build: add the SIBO SDK

This commit is contained in:
2026-07-06 18:01:36 +01:00
parent d76326729c
commit 64e484448c
757 changed files with 97167 additions and 0 deletions
+180
View File
@@ -0,0 +1,180 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* BCD.CPP - BCD number class implementation. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#include <clib.h>
#include <bcd.hpp>
#pragma module(init_prio=>22)
bcd::bcd(int x) {
int_to_dec((unsigned long) abs(x));
if(x < 0)
bcd_array[9]|=0x80;
}
bcd::bcd(unsigned x) {
int_to_dec((unsigned long) x);
}
bcd::bcd(long x) {
int_to_dec((unsigned long) labs(x));
if(x < 0)
bcd_array[9]|=0x80;
}
bcd::bcd(unsigned long x) {
int_to_dec(x);
}
bcd bcd::operator-() {
bcd_array[9]^=0x80;
return *this;
}
ostream& operator<<(ostream& os, bcd& b) {
os << real(b);
return os;
}
istream& operator>>(istream& is, bcd& b) {
long double n;
is >> n;
b.real_to_dec(n);
return is;
}
void bcd::bcd_copy_to(unsigned char *source) {
int n=0;
while(n < 10) {
bcd_array[n] = source[n];
++n;
}
}
void bcd::bcd_copy_from(unsigned char *dest) {
int n=0;
while(n < 10) {
dest[n] = bcd_array[n];
++n;
}
}
void bcd::int_to_dec(unsigned long x) {
char s[32];
int l, n, c, p;
unsigned char cv;
if(!x)
exp=ExpZero;
else
exp=110 + (int)log10((double) (x));
ultoa(x, s, 10);
l=strlen(s);
p=0;
while(p < 10) {
bcd_array[p++]=0;
}
p=8;
n=0;
while(n < l) {
c=s[n++];
cv=(c-0x30)<<4;
if(n == l) {
bcd_array[p]=cv;
break;
}
c=s[n++];
cv|=(c-0x30);
bcd_array[p--]=cv;
}
}
#pragma save
#pragma call(reg_param=>(ax))
extern "C" long double _cvt_bcd(unsigned char/* <_SS>*/ *);
#pragma restore
long double bcd::dec_to_real() {
long double n;
unsigned char bcd_temp[10];
bcd_copy_from(bcd_temp);
n=_cvt_bcd(bcd_temp);
n*= pow10((double)(exp-127));
return n;
}
void bcd::real_to_dec(long double x, int decimals) {
long double zero = 0;
long double norm;
int k,clear,n;
unsigned char bcd_temp[10];
if ( x < zero ) {
x = -x;
bcd_temp[9] = 0x80;
}
else
bcd_temp[9] = 0;
if ( x == zero )
k = -10000;
else {
k = 1 + (int) floorl( log10l(x) + 0.001 );
}
while (1) {
norm = x;
if ( k != -10000 )
norm *= _pow_int(10,18-k);
_bcd( norm, (char near *)bcd_temp );
if ( k == -10000 ) {
k = 1;
break;
}
if ( ( bcd_temp[8] >> 4 ) != 0 )
break;
k -= 1;
}
exp = 109 + k;
if((k < 0) && (decimals != _BcdMaxDecimals)) {
clear = abs(k) + decimals;
n = 0;
while(clear) {
bcd_temp[n] &= ~0x0F;
if(--clear == 0)
break;
bcd_temp[n] &= ~0xF0;
--clear;
++n;
}
}
bcd_copy_to(bcd_temp);
}

+220
View File
@@ -0,0 +1,220 @@
/* Release 3.00 */
/*-------------------------------------------------------------------------*
* *
* cdata.c - C library data *
* *
* COPYRIGHT (C) 1989 Jensen and Partners. All Rights Reserved *
* Written by Simon Knight. *
* *
* COPYRIGHT (C) 1991 Psion PLC. All Rights Reserved *
* Modified by NSM. *
* *
*--------------------------------------------------------------------------*/
#define _USE_TIME
#include <clib.h>
char _cvt_buf[64]; /* real number conversion buffer */
int daylight=0; /* daylight saving flag */
time_t timezone=0; /* timezone variable */
struct lconv _lconv={".", "", "", "", "", "", "", "", "", "",
CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX };
jmp_buf _EOFhandler; /* EOF error jump environment */
int _open_init;
int _s_args; /* argument count */
int _vp_ret; /* character count */
int _vs_count; /* character count */
int (*_vs_fill)(FILE *st); /* filler function pointer */
int (*_vp_flush)(FILE *st); /* output function pointer */
/*-------------------------------------------------------------------------*
* error message output - data declarations *
*--------------------------------------------------------------------------*/
#ifdef OLDERRORS
char *sys_errlist[]=
{"Unknown Error",
"Error Zero",
"Invalid Function Code",
"File Not Found",
"Path Not Found",
"Too Many Open Files",
"Access Denied",
"Invalid Handle",
"Memory Blocks Destroyed",
"Not Enough Core",
"Invalid Memory Block Address",
"Invalid Environment",
"Invalid Format",
"Invalid Access Code",
"Invalid Data",
"",
"Invalid Drive",
"Attempt To Remove CurDir",
"Not Same Device",
"No More Files",
"Invalid Argument",
"Not Directory",
"Is Directory",
"Corrupted EXE File",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"Cross-Device Link",
"Math Argument Invalid",
"Result Too Large",
"File Locking Deadlock",
"Unknown Error"
};
int sys_nerr=38; /* number of system error strings */
#endif
char _sys_errbuf[128]; /* error message buffer */
/*-------------------------------------------------------------------------*
* Character type array. *
*--------------------------------------------------------------------------*/
char _ctype[257] = {
0,/* -1 EOF */
_IS_CTL,/* 0 NUL */
_IS_CTL,/* 1 SOH */
_IS_CTL,/* 2 STX */
_IS_CTL,/* 3 ETX */
_IS_CTL,/* 4 EOT */
_IS_CTL,/* 5 ENQ */
_IS_CTL,/* 6 ACK */
_IS_CTL,/* 7 BEL */
_IS_CTL,/* 8 BS */
_IS_CTL|_IS_SP,/* 9 HT */
_IS_CTL|_IS_SP,/* A LF */
_IS_CTL|_IS_SP,/* B VT */
_IS_CTL|_IS_SP,/* C FF */
_IS_CTL|_IS_SP,/* D CR */
_IS_CTL,/* E SO */
_IS_CTL,/* F SI */
_IS_CTL,/* 10 DLE */
_IS_CTL,/* 11 DC1 */
_IS_CTL,/* 12 DC2 */
_IS_CTL,/* 13 DC3 */
_IS_CTL,/* 14 DC4 */
_IS_CTL,/* 15 NAK */
_IS_CTL,/* 16 SYN */
_IS_CTL,/* 17 ETB */
_IS_CTL,/* 18 CAN */
_IS_CTL,/* 19 EM */
_IS_CTL,/* 1A SUB */
_IS_CTL,/* 1B ESC */
_IS_CTL,/* 1C FS */
_IS_CTL,/* 1D GS */
_IS_CTL,/* 1E RS */
_IS_CTL,/* 1F UF */
_IS_SP,/* 20 '\ ' */
_IS_PUN,/* 21 ! */
_IS_PUN,/* 22 " */
_IS_PUN,/* 23 # */
_IS_PUN,/* 24 $ */
_IS_PUN,/* 25 % */
_IS_PUN,/* 26 & */
_IS_PUN,/* 27 ' */
_IS_PUN,/* 28 ( */
_IS_PUN,/* 29 ) */
_IS_PUN,/* 2A * */
_IS_PUN,/* 2B + */
_IS_PUN,/* 2C ,*/
_IS_PUN,/* 2D - */
_IS_PUN,/* 2E . */
_IS_PUN,/* 2F / */
_IS_DIG,/* 30 0 */
_IS_DIG,/* 31 1 */
_IS_DIG,/* 32 2 */
_IS_DIG,/* 33 3 */
_IS_DIG,/* 34 4 */
_IS_DIG,/* 35 5 */
_IS_DIG,/* 36 6 */
_IS_DIG,/* 37 7 */
_IS_DIG,/* 38 8 */
_IS_DIG,/* 39 9 */
_IS_PUN,/* 3A : */
_IS_PUN,/* 3B ; */
_IS_PUN,/* 3C < */
_IS_PUN,/* 3D = */
_IS_PUN,/* 3E > */
_IS_PUN,/* 3F ? */
_IS_PUN,/* 40 @ */
_IS_UPP|_IS_HEX,/* 41 A */
_IS_UPP|_IS_HEX,/* 42 B */
_IS_UPP|_IS_HEX,/* 43 C */
_IS_UPP|_IS_HEX,/* 44 D */
_IS_UPP|_IS_HEX,/* 45 E */
_IS_UPP|_IS_HEX,/* 46 F */
_IS_UPP,/* 47 G */
_IS_UPP,/* 48 H */
_IS_UPP,/* 49 I */
_IS_UPP,/* 4A J */
_IS_UPP,/* 4B K */
_IS_UPP,/* 4C L */
_IS_UPP,/* 4D M */
_IS_UPP,/* 4E N */
_IS_UPP,/* 4F O */
_IS_UPP,/* 50 P */
_IS_UPP,/* 51 Q */
_IS_UPP,/* 52 R */
_IS_UPP,/* 53 S */
_IS_UPP,/* 54 T */
_IS_UPP,/* 55 U */
_IS_UPP,/* 56 V */
_IS_UPP,/* 57 W */
_IS_UPP,/* 58 X */
_IS_UPP,/* 59 Y */
_IS_UPP,/* 5A Z */
_IS_PUN,/* 5B [ */
_IS_PUN,/* 5C \ */
_IS_PUN,/* 5D ] */
_IS_PUN,/* 5E ^ */
_IS_PUN,/* 5F _ */
_IS_PUN,/* 60 ` */
_IS_LOW|_IS_HEX,/* 61 a */
_IS_LOW|_IS_HEX,/* 62 b */
_IS_LOW|_IS_HEX,/* 63 c */
_IS_LOW|_IS_HEX,/* 64 d */
_IS_LOW|_IS_HEX,/* 65 e */
_IS_LOW|_IS_HEX,/* 66 f */
_IS_LOW,/* 67 g */
_IS_LOW,/* 68 h */
_IS_LOW,/* 69 i */
_IS_LOW,/* 6A j */
_IS_LOW,/* 6B k */
_IS_LOW,/* 6C l */
_IS_LOW,/* 6D m */
_IS_LOW,/* 6E n */
_IS_LOW,/* 6F o */
_IS_LOW,/* 70 p */
_IS_LOW,/* 71 q */
_IS_LOW,/* 72 r */
_IS_LOW,/* 73 s */
_IS_LOW,/* 74 t */
_IS_LOW,/* 75 u */
_IS_LOW,/* 76 v */
_IS_LOW,/* 77 w */
_IS_LOW,/* 78 x */
_IS_LOW,/* 79 y */
_IS_LOW,/* 7A z */
_IS_PUN,/* 7B { */
_IS_PUN,/* 7C | */
_IS_PUN,/* 7D } */
_IS_PUN,/* 7E ~ */
_IS_CTL,/* 7F DEL */
0};
+306
View File
@@ -0,0 +1,306 @@
(* Release 3.00 *)
(* c_io1 - common low level I/O *)
(* Copyright (C) 1989 Jensen and Partners. All Rights Reserved*)
(* Written by Simon Knight.*)
(* Copyright (C) 1991 Psion PLC. All Rights Reserved*)
(* Modified by NSM.*)
include "corelib.inc"
include "epocdefs.inc"
module cio1
(***************************************************************************)
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn __filbuf
select _TEXT
(*
int fgetc(FILE *st)
*)
public _fgetc :
push bx
push cx
push dx
push si
mov bx, ax
mov cx, [bx][_flag]
dec word [bx][_cnt]
js callfunc
mov si, [bx][_ptr]
inc word [bx][_ptr]
mov al, [si]
sub ah, ah
done:
test cx, _F_BIN
jnz noTrans
cmp al, CTLZ
je fgEOF
cmp al, 0DH
jne noTrans
mov ax, bx
call _fgetc
noTrans:
pop si
pop dx
pop cx
pop bx
ret 0
callfunc:
push bx
mov ax, bx
call __filbuf
pop bx
jmp done
fgEOF:
or word [bx][_flag], _F_EOF
mov ax, -1
jmp noTrans
(* _fgetc ENDP *)
(******************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn __flsbuf
extrn __flusher
select _TEXT
(*
int fputc(int ch, FILE *st)
*)
public _fputc :
push cx
push dx
push si
test word [bx][_flag], _F_BIN
jnz fpOK
cmp al, -1
je fpError
cmp al, CTLZ
je fpEOF
cmp al, 0AH
jne fpOK
push bx
mov ax, 0DH
call _fputc
pop bx
mov ax, 0AH
fpOK:
dec word [bx][_cnt]
js callfunc
mov si, [bx][_ptr]
inc word [bx][_ptr]
mov [si], al
cmp al, 0AH
jne done
test word [bx][_flag], _F_LBUF
jz done
mov ax, bx
call __flusher
done:
pop si
pop dx
pop cx
ret 0
callfunc:
call __flsbuf
jmp done
fpError:
mov ax, -1
jmp done
fpEOF:
or word [bx][_flag], _F_CTZ
jmp fpOK
(* _fputc ENDP *)
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
select _DATA
extrn __ungotchar
select _TEXT
public _ungetch :
(*
int ungetch(int c)
Returns character to console input stream. Returns EOF if __ungotchar
is occupied.
*)
cmp word [__ungotchar], -1
jne occupied
cmp ax, -1
je occupied
mov [__ungotchar], ax
jmp ungetchDone
occupied:
mov ax, EOF
ungetchDone:
ret 0
(* _ungetch ENDP *)
(***************************************************************************)
section
segment _TEXT(CODE,28H)
extrn __ioerr
public _chmod :
(*
int chmod(char *path, int attribute)
Returns -1 on error and sets _errno.
*)
push bx
push cx
push di
mov cx, bx
mov bx, ax
mov di, 1
cmp cx, S_IREAD
je chRdonly
mov cx, FileAttWrite
jmp chGotmode
chRdonly:
sub cx, cx
chGotmode:
sub al, al
mov ah, NmFilStatusSet
int FilManager
jnc chSuccess
call __ioerr (* set errno *)
mov ax, -1
jmp chDone
chSuccess:
sub ax, ax
chDone:
pop di
pop cx
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
extrn __ioerr
public __chmod :
(*
int _chmod(char *path, int mode, int attribute)
mode 0 - returns file attribute.
mode 1 - sets file attribute to attribute.
Returns -1 on error. Low level DOS function.
*)
push bx
push cx
push di
sub sp, FileEnt
test bx, bx
mov bx, ax
jz getAtt
mov di, FileAttWrite | FileAttHidden | FileAttSystem
and cx, di
xor cl, FileAttWrite
sub al, al
mov ah, NmFilStatusSet
int FilManager
jnc chSuccess
chFailed:
call __ioerr (* set errno *)
mov ax, -1
jmp chDone
getAtt:
mov cx, sp
sub al, al
mov ah, NmFilStatusGet
int FilManager
jc chFailed
mov bx, sp
mov ax, [bx][FileAtt]
and ax, FileAttWrite | FileAttHidden | FileAttSystem
xor al, FileAttWrite
chSuccess:
sub ax, ax
chDone:
add sp, FileEnt
pop di
pop cx
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
extrn __ioerr
public _access :
(*
int access(char *path, int mode)
Returns 0 if mode available.
Returns -1 on error.
*)
exist = 0
write = 2
read = 4
rdwr = 6
push bx
push cx
push dx
sub sp, FileEnt
mov cx, sp
mov dx, bx
mov bx, ax
sub al, al
mov ah, NmFilStatusGet
int FilManager
jnc accSuccess
call __ioerr (* set errno *)
accNo:
mov ax, -1
jmp accDone
accSuccess:
test dx, dx
je accYes
test dx, write
jz accYes
mov bx, sp
test byte [bx][FileAtt], FileAttWrite
jz accNo
accYes:
sub ax, ax
accDone:
add sp, FileEnt
pop dx
pop cx
pop bx
ret 0
end
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+239
View File
@@ -0,0 +1,239 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* COMPLEX.C - complex number class implementation. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#include <clib.h>
#include <complex.hpp>
#pragma module(init_prio=>22)
double norm(const complex& c) {
double r, i;
r=real(c);
i=imag(c);
return r*r + i*i;
}
double arg(const complex& c) {
return atan2(imag(c), real(c));
}
complex operator*(const complex& c1, const complex& c2) {
double ires, rres;
double r1, r2, i1, i2;
r1=real(c1);
i1=imag(c1);
r2=real(c2);
i2=imag(c2);
rres = r1*r2 - i1*i2;
ires = r1*i2 + r2*i1;
return complex(rres, ires);
}
complex operator/(const complex& c1, const complex& c2) {
double ires, rres;
double r1, r2, i1, i2;
r1=real(c1);
i1=imag(c1);
r2=real(c2);
i2=imag(c2);
rres=(i1*i2+r1*r2)/(r2*r2+i2*i2);
ires=(r2*i1-r1*i2)/(r2*r2+i2*i2);
return complex(rres, ires);
}
const complex& complex::operator*=(const complex& c2) {
double ires, rres;
double r2, i2;
r2=real(c2);
i2=imag(c2);
rres = re*r2 - im*i2;
ires = re*i2 + r2*im;
re=rres;
im=ires;
return *this;
}
const complex& complex::operator/=(const complex& c2) {
double ires, rres;
double r2, i2;
r2=real(c2);
i2=imag(c2);
ires=(im*r2 - i2*re)/(i2*i2 + r2*r2);
rres=(im-r2*ires)/i2;
re=rres;
im=ires;
return *this;
}
double abs(const complex& c) {
double i, r;
i=imag(c);
r=real(c);
return sqrt(r*r + i*i);
}
complex acos(const complex& c) {
complex r;
r=sqrt(1 - c*c);
r=complex(-imag(r), real(r) );
r=log(c + r);
return complex(imag(r), -real(r));
}
complex asin(const complex& c) {
complex r;
r=sqrt(1 - c*c);
r=log(complex(-imag(r), real(r)) + r);
return complex(imag(r), -real(r));
}
complex atan(const complex& c) {
complex r, t;
t=complex(-imag(c), real(c));
r=log((1.0+t)/(1.0-t))/2.0;
return complex(imag(r), -real(r));
}
complex cos(const complex& c) {
complex t;
t=complex(-imag(c), real(c));
return (exp(t) + exp(-t))/2.0;
}
complex cosh(const complex& c) {
return (exp(c) + exp(-c))/2.0;
}
complex exp(const complex& c) {
double ex;
ex=exp(real(c));
return complex(ex*cos(imag(c)), ex*sin(imag(c)));
}
complex log(const complex& c) {
complex t;
t=arg(c);
t=complex(-imag(t), real(t));
return log(abs(c)) + t;
}
complex log10(const complex& c) {
complex t;
t=arg(c);
t=complex(-imag(t), real(t));
return (log(abs(c)) + t)/log(10.0);
}
complex pow(const complex& base, double expo) {
return exp(expo*log(base));
}
complex pow(double base, const complex& expo) {
return exp(expo*log(base));
}
complex pow(const complex& base, const complex& expo) {
return exp(expo*log(base));
}
complex sin(const complex& c) {
complex t;
complex twoi(0.0, 2.0);
t=complex(-imag(c), real(c));
return complex((exp(t) - exp(-t))/twoi);
}
complex sinh(const complex& c) {
return (exp(c) - exp(-c))/2.0;
}
complex sqrt(const complex& c) {
complex t;
t=sin(arg(c)/2.0);
t=complex(-imag(t), real(t));
return sqrt(abs(c))*(cos(arg(c)/2.0) + t);
}
complex tan(const complex& c) {
return sin(c)/cos(c);
}
complex tanh(const complex& c) {
return sinh(c)/cosh(c);
}
ostream& operator<<(ostream& st, const complex& c) {
st<< '(' << real(c) << ',' << imag(c) << ')';
return st;
}
istream& operator>>(istream& st, complex& c) {
double r=0.0, i=0.0;
if(st.peek() == '(')
st.get();
st >> r;
if(st.peek() == ',')
st.get();
st >> i;
if(st.peek() == ')')
st.get();
c=complex(r, i);
return st;
}

+104
View File
@@ -0,0 +1,104 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* CONIOSTR.CPP - console I/O stream class implementations. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#define _USE_CONIO
#include <clib.h>
#include <coniostr.hpp>
#pragma module(init_prio=>22)
extern "C" void _init_con(void) {
conout.setf(ios::unitbuf);
}
static conbuf inbuf;
static conbuf outbuf;
istream conin(&inbuf);
ostream conout(&outbuf);
int conbuf::underflow() {
#define CGETS_MAX_NR 255 /* new line */
int nr, c;
char *buf;
nr=ebuf()-eback();
if(nr == 1) {
c=getche();
if(c == EOF) {
return EOF;
}
*eback()=c;
}
else {
if (nr > CGETS_MAX_NR) /* new line */
nr = CGETS_MAX_NR; /* new line */
buf=new char[nr+3];
buf[0]=nr;
cgets(buf);
nr=buf[1];
memcpy(eback(), buf+2, nr); /* corrected line */
delete buf;
}
setg(eback(), eback(), eback()+nr);
return *gptr();
#undef CGETS_MAX_NR /* new line */
}
int conbuf::pbackfail(int c) {
return ungetch(c);
}
extern "C" unsigned _flush_init_magic;
int conbuf::overflow(int c) {
char *pt;
int nw;
flush_magic=_flush_init_magic;
if(unbuffered()) {
if((c == EOF) || (putch(c) == EOF)) {
return EOF;
}
}
else {
pt=pbase();
nw=pptr()-pt;
while(nw--) {
if(putch(*pt) == EOF) {
return EOF;
}
++pt;
}
}
setp(pbase(), epptr());
if((c != EOF) && (!unbuffered()))
sputc(c);
return c;
}
int conbuf::sync() {
overflow();
setp(base(), ebuf());
setg(base(), ebuf(), ebuf());
return 0;
}
+47
View File
@@ -0,0 +1,47 @@
(* Release 3.00 *)
(* c_files.a - file control memory *)
(* Copyright (C) 1989 Jensen and Partners. All Rights Reserved*)
(* Written by Simon Knight.*)
(* Copyright (C) 1991 Psion PLC. All Rights Reserved*)
(* Modified by NSM.*)
include "corelib.inc"
OPEN_MAX = 20
module files
section
segment _DATA(DATA, 28H)
select _DATA
public __open_max: dw OPEN_MAX
section
segment _BSS(BSS, 28H)
public __iob: org OPEN_MAX * _iobSize
public __openfd: org OPEN_MAX*2
public __openmp: org OPEN_MAX*2
public __openfl: org OPEN_MAX*2
section
segment _BSS(BSS, 28H)
select _BSS
public __tmpfiles: org OPEN_MAX * DataPtrSize
section
segment _BSS(BSS, 28H)
select _BSS
public __tmpfptrs: org OPEN_MAX * DataPtrSize
end
+257
View File
@@ -0,0 +1,257 @@
(* Release 3.00 *)
(* c_coreinit - common initialisation between PLIB and CLIB *)
(* Copyright (C) 1991 Psion PLC. All Rights Reserved*)
(* Written by NSM.*)
include "corelib.inc"
include "epocdefs.inc"
module coreinit
(***************************************************************************)
section
segment _MAGIC(MAGIC,68H)
segment _DATA(DATA,68H)
segment _CONST(DATA,48H)
segment _BSS(BSS,68H)
segment BSS_END(BSS,68H)
group DGROUP(_MAGIC,_DATA,_CONST,_BSS,BSS_END)
select _DATA
public _winHandle : dw 0
public __conName : db 'CON:*',0
(***************************************************************************)
section
segment _DATA(DATA,68H)
public __DefScreenRect : dw -1,0,0,0
(***************************************************************************)
section
segment _DATA(DATA,68H)
public __DefScreenMode : dw 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
public __FatalErrorPos :
push bx
mov bx, sp
mov ax, ss:[bx][2]
pop bx
ret 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
public __FatalError :
mov al, 80
int ProcPanic
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn _winHandle
extrn _DatCommandPtr
extrn __DefScreenRect
extrn __DefScreenMode
extrn __conName
select _TEXT
extrn __FatalErrorPos
extrn __FatalError
xMode = -2
xParse = xMode-FullParseEnt
xBuf = xParse-MaxPathSize
public _p_xwind :
push bp
mov bp, sp
add sp, xBuf
push ax
push bx
push cx
push dx
push di
push si
;
mov bx, [_DatCommandPtr]
test bx, bx
je noCommandLine
sub cx, cx
lea di, [bp][xBuf]
lea si, [bp][xParse]
sub al, al
mov ah, NmFilParse
int FilManager
jc noCommandLine
lea di, [bp][xBuf]
mov si, __conName
int StringCopy
add di, 5
lea si, [bp][xBuf][FileSystemNameSize]
mov ax, [bp][xParse][FullParseDevice]
add al, ah
sub ah, ah
add si, ax
mov cl, [bp][xParse][FullParseName]
sub ch, ch
cld
rep ; movsb
sub al, al
stosb
jmp openCon
noCommandLine:
lea di, [bp][xBuf]
mov si, __conName
int StringCopy
mov byte [di][4], 0
openCon:
lea bx, [bp][xBuf]
mov cx, -1
mov ah, NmIoOpen
int DevManager
jnc openOk
;
call __FatalErrorPos
mov bx, FatalOpenConsole
jmp __FatalError
;
openOk: mov [_winHandle], ax
;
mov si, ds:[Datawserv_channel]
or si, si
jz old_window_server
mov al, [si][wserv_spec_info_version]
and al, 0FH
cmp al, 2 (* WS_VERSION_4 *)
jb old_window_server
;
sub sp, 32 (* SIZE W_SUPPORT_INFO *)
mov si, sp
mov ax, 0FF06H (* WOR_X_SUPPROT_INFO *)
int WservOpcodes
mov ax, [__DefScreenMode]
mov bx, [si]
add sp, 32 (* SIZE W_SUPPORT_INFO *)
;
test bx, 2 (* W_SUPPORT_CTBY_S3 *)
jz no_ctby_mode
test ax, 1 (* Use compatibility mode if set *)
jnz no_ctby_mode
push ax
push bx
mov word [bp][xMode], 20 (* P_SCR_COMPATIBILITY *)
lea cx, [bp][xMode]
xor ax, ax (* No compatibilty mode *)
push ax
mov dx, sp
mov bx, [_winHandle]
mov al, IoFuncSet
mov ah, NmIoWithWait
int IoManager
pop ax
pop bx
pop ax
;
no_ctby_mode:
test bx, 1 (* W_SUPPORT_CTBY_GREY *)
jz no_grey
test ax, 2 (* Use grey if set *)
jz no_grey
;
mov word [bp][xMode], 21 (* P_SCR_GREY *)
lea cx, [bp][xMode]
mov ax, TRUE
push ax
mov dx, sp
mov bx, [_winHandle]
mov al, IoFuncSet
mov ah, NmIoWithWait
int IoManager
pop ax
no_grey:
;
old_window_server:
mov di, __DefScreenRect
cmp word [di][RectTl][PointX], -1
jne rectGood
sub ax, ax
mov [di][RectTl][PointX], ax
mov [di][RectTl][PointY], ax
mov ah, NmGenLcdType
int GenManager
mov bx, 60
mov cx, 15
cmp al, Lcd240X80
jne try160X80
mov bx, 40
mov cx, 9
jmp setBr
try160X80:
cmp al, Lcd160X80
jne setBr
mov bx, 26
mov cx, 9
setBr:
mov [di][RectBr][PointX], bx
mov [di][RectBr][PointY], cx
rectGood:
mov word [bp][xMode], 5 (* P_SCR_WSET *)
lea cx, [bp][xMode]
mov dx, di
mov bx, [_winHandle]
mov al, IoFuncSet
mov ah, NmIoWithWait
int IoManager
;
mov word [bp][xMode], 3 (* P_SCR_POSA *)
lea cx, [bp][xMode]
xor ax, ax
push ax
push ax
mov dx, sp
mov al, IoFuncSet
mov ah, NmIoWithWait
int IoManager
;
lea di, [bp][xParse]
mov word [di], 1
mov dx, di
mov word [bp][xMode], 9 (* P_SCR_CURSOR *)
mov al, IoFuncSet
mov ah, NmIoWithWait
int IoManager
;
pop si
pop di
pop dx
pop cx
pop bx
pop ax
mov sp, bp
pop bp
ret 0
;
(****************************************************************************)
section
segment _TEXT(CODE,28H)
public _ClassTable :
public _ExtCatTable :
dw 0
end
File diff suppressed because it is too large Load Diff
+673
View File
@@ -0,0 +1,673 @@
(* Release 3.00 *)
(* CoreMain - process startup and exit, args, environment. *)
(* Copyright (C) 1989 Jensen and Partners. All Rights Reserved*)
(* Written by Simon Knight.*)
(* Copyright (C) 1991 Psion PLC. All Rights Reserved*)
(* Written by NSM.*)
include "corelib.inc"
include "epocdefs.inc"
module CoreMain
(****************************************************************************)
segment _MAGIC(DATA,28H)
segment _INIT(DATA,28H)
segment _CONST(DATA,28H)
segment _DATA(DATA,28H)
segment _BSS(BSS,28H)
segment _BSS_END(BSS,28H)
group DGROUP(_MAGIC,_INIT,_CONST,_DATA,_BSS,_BSS_END)
select _BSS
public __argbuf : org 128 (* command line buffer *)
public __osmajor : org 2
public __osminor : org 2
public __exit_stk : org 32*CodePtrSize (* at/onexit function stack *)
public __exit_io : org CodePtrSize
public __exit_tmp : org CodePtrSize
public __exit_proc : org CodePtrSize
public __real_in : org CodePtrSize
public __real_out : org CodePtrSize
public __sigsetup : org 2
public __exitbreak : org CodePtrSize
public __exitsig : org CodePtrSize
public @InitCount : org 2
public @InitEnd : org 2
public @InitDone : org 2
public @ExitCode : org 2
public @StackContextSP : org 2
public @StackContextBP : org 2
select _DATA
extrn __Term2
extrn __init_start
extrn __bss_start
public __exit_ptr : dw __exit_stk + (32*CodePtrSize)
public __exit_top : dw __exit_stk + (32*CodePtrSize)
public standard@haltChain : dw __Term2
public @InitPointer : dw __init_start
public @InitPriority : db PRMAX
public __arg_init : db 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
extrn __exit
select _DATA
extrn __exit
extrn __exit_io
extrn __exit_tmp
extrn __exit_proc
extrn __init_start
extrn __const_start
extrn @RecursiveExit
extrn @InitPointer
extrn @InitCount
extrn @InitPriority
extrn @InitEnd
extrn @InitDone
extrn @ExitCode
extrn @StackContextSP
extrn @StackContextBP
extrn $Stage2
select _TEXT
public _exit :
mov [@ExitCode], ax
cmp byte [@RecursiveExit], 0
je notAgain
call __exit
notAgain:
not byte [@RecursiveExit]
mov sp, [@StackContextSP]
mov bp, [@StackContextBP]
jmp near $TerminateProcess
public __InitLoop :
push di
push si
mov bx, [@InitPointer]
jmp traverseLoop
nextLoop:
add bx, InitSize
chainLoop:
traverseLoop:
cmp bx, [@InitEnd]
jae endOfArray
mov al, [@InitPriority]
cmp al, [bx][Priority]
jne nextLoop
lea ax, [bx][InitSize]
mov [@InitPointer], ax
dec word [@InitCount]
call [bx][ProcVar]
mov bx, [@InitPointer]
cmp word [@InitDone], 0
je traverseLoop
initLoopRet:
pop si
pop di
ret 0
endOfArray:
cmp word [@InitCount], 0
je stageComplete
endOfList:
dec byte [@InitPriority]
js stageComplete
mov bx, __init_start
jmp chainLoop
stageComplete:
inc word [@InitDone]
mov [@StackContextBP], bp
mov [@StackContextSP], sp
call $Stage2
mov [@ExitCode], ax
$TerminateProcess:
public __Term2 :
extrn __exit_ptr
extrn __exit_top
extrn standard@haltChain
(* reset halt chain to allow it to be re-used in termination code *)
mov bx, here
xchg bx, [standard@haltChain]
call bx
here:
mov bp, [@StackContextBP]
mov sp, [@StackContextSP]
mov si, [__exit_ptr]
mov di, [__exit_top]
exitLoop:
cmp si, di
je loopDone
call [si]
add si, 2
jmp exitLoop
loopDone:
jmp initLoopRet
public __cleanup :
mov cx, [__exit_io]
jcxz noCall1
call cx
noCall1:
mov cx, [__exit_tmp]
jcxz noCall2
call cx
noCall2:
mov cx, [__exit_proc]
jcxz noCall3
call cx
noCall3:
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
segment _BSS(BSS,28H)
__env_buffer : org 256
select _TEXT
public _getenv :
push di
push si
mov si, __env_buffer
mov di, ax
mov ah, NmGenEnvStringGet
int GenManager
mov ax, si
jnc getenvExit
sub ax, ax
getenvExit:
pop si
pop di
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
extrn _strlen
extrn _strcpy
extrn _strchr
public _putenv :
push bx
push di
push si
sub sp, (256+18)
cld
mov bx, ax
call _strlen
mov di, ax
test ax, ax
je putenvFailed
cmp ax, (256+18)
jae putenvFailed
mov ax, sp
call _strcpy
mov bl, '='
sub bh, bh
call _strchr
mov bx, ax
mov ah, NmGenEnvStringDelete
test bx, bx
je putenvDelete
mov si, bx
mov byte [si], 0
inc si
cmp byte [si], 0
je putenvDelete
mov ah, NmGenEnvStringSet
putenvDelete:
mov di, sp
int GenManager
jc putenvFailed
sub ax, ax
putenvExit:
add sp, (256+18)
pop si
pop di
pop bx
ret 0
putenvFailed:
mov ax, -1
jmp putenvExit
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn @InitCount
extrn @InitEnd
extrn @InitDone
extrn __init_start
extrn __const_start
select _TEXT
public __InitSetup :
mov ax, __const_start
sub ax, __init_start
mov bl, InitSize
div bl
sub ah, ah
mov [@InitCount], ax
mul bl
add ax, __init_start
mov [@InitEnd], ax
and word [@InitDone], 0
ret 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
extrn __argv
extrn __argc
select _TEXT
extrn _main
public __init2 :
mov ax, [__argc]
mov bx, __argv
jmp near _main
(****************************************************************************)
section
segment _INIT(DATA,28H)
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
segment _BSS(BSS, 28H)
extrn __setargv
extrn __InitLoop
select _TEXT
do_initargc : (* defined later on ! *)
select _INIT
initargc : dw MAGIC
db PR1
dw do_initargc
select _BSS
public __argv : org 32*DataPtrSize
public __argin : org DataPtrSize
public __argout : org DataPtrSize
public __argapp : org 2
select _DATA
public __argc : dw initargc
select _TEXT
call __setargv
jmp __InitLoop
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
extrn __exit
select _DATA
extrn __osmajor
extrn __osminor
select _TEXT
public __osversion :
(*
void __osversion(void)
checks Epoc/Os version into __osver
*)
mov ah, NmGenVersion
int GenManager
push ax
shr ax, 1
shr ax, 1
shr ax, 1
shr ax, 1
mov [__osmajor], ah
mov [__osminor], al
pop ax
and ah, 0FH
mov al, 0AH
mul ah
add [__osminor], ax
ret 0
(**************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
select _DATA
extrn __argv
extrn __argbuf
extrn __argc
extrn __argin
extrn __argout
extrn __argapp
extrn __arg_init
extrn _DatCommandPtr
select _TEXT
extrn _strlen
public __setargv :
push di
push si
cld
cmp byte [__arg_init], 0
jne initDone
not byte [__arg_init]
mov word [__argc], 0
mov di, [_DatCommandPtr]
test di, di
je initDone
mov bx, __argv
call saveArg
mov ax, di
call _strlen
add di, ax
inc di
mov si, di
lodsb
cbw
add ax, si
mov dx, ax
mov di, __argbuf
convLoop:
cmp si, dx
jae initDone
lodsb
test al, al
je initDone
cmp al, ' '
je convLoop
cmp al, '<'
je gotInRedir
cmp al, '>'
je gotOutRedir
cmp al, '"'
je gotString
dec si
mov al, ' '
gotString:
mov cl, al
call saveArg
locateLoop:
cmp si, dx
jae gotLocate
lodsb
test al, al
je gotLocate
cmp al, cl
je gotLocate
stosb
jmp locateLoop
gotLocate:
sub al, al
stosb
jmp convLoop
initDone:
pop si
pop di
ret 0
gotInRedir:
push bx
mov bx, __argin
jmp goLocate
gotOutRedir:
cmp byte [si], '>'
jne notAppend
lodsb
mov word [__argapp], ModeAppend
notAppend:
push bx
mov bx, __argout
goLocate:
cmp si, dx
jae noFileName
lodsb
test al, al
je noFileName
cmp al, ' '
je goLocate
dec si
mov [bx], di
mov cl, ' '
pop bx
jmp locateLoop
noFileName:
pop bx
jmp initDone
saveArg:
cmp word [__argc], 32
jae noRoomForMore
mov [bx], di
inc bx
inc bx
inc word [__argc]
noRoomForMore:
ret 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
select _DATA
extrn __sigsetup
extrn __exitbreak
extrn __exitsig
select _TEXT
extrn __FloatFinish
public __exit :
(*
void __exit(int code)
terminates process.
*)
mov di, ax
mov cx, [__exitbreak]
jcxz noBreak
call cx
noBreak:
mov cx, [__exitsig]
jcxz noSig
call cx
noSig:
call __FloatFinish
mov ah, NmProcId
int ProcManager
mov bx, ax
mov ax, di
mov ah, NmProcKill
int ProcManager
(****************************************************************************)
section
segment _DATA(DATA, 28H)
segment _TEXT(CODE,28H)
extrn __exit_proc
extrn __exitbreak
extrn __exitsig
extrn __FloatFinish
public __term_process :
mov cx, [__exit_proc]
jcxz noCall4
call cx
noCall4:
mov cx, [__exitbreak]
jcxz noBreak
call cx
noBreak:
mov cx, [__exitsig]
jcxz noSig
call cx
noSig:
jmp near __FloatFinish
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
select _DATA
message : db 0AH,'Floating Point Not Loaded',0AH,0
select _TEXT
extrn _puts
public __real_pdef :
public __real_sdef :
mov ax, message
jmp _puts
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _MAGIC(DATA,28H)
segment _INIT(DATA,28H)
segment _CONST(DATA,28H)
segment _DATA(DATA,28H)
segment _BSS(BSS,28H)
segment _BSS_END(BSS,28H)
group DGROUP(_MAGIC,_INIT,_CONST,_DATA,_BSS,_BSS_END)
extrn __EpocInit
extrn __exit
extrn __cleanup
extrn __osversion
extrn __FloatInit
extrn __InitSetup
extrn __InitLoop
extrn __init2
extrn @ExitCode
select _TEXT (* Process initialisation starts here *)
public __startup :
call __EpocInit
call __FloatInit (* initialise floating point if present *)
call __osversion (* get Epoc/Os version first *)
call __InitSetup
call __InitLoop
call __cleanup
mov ax, [@ExitCode]
jmp near __exit
public $Stage2 :
call __init2
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn __real_in
extrn __real_out
extrn __rreal_in
extrn __rreal_out
select _TEXT
extrn __initsig
public __fp_1 :
mov word [__real_in], __rreal_in (* initialise 'C' fp output *)
mov word [__real_out], __rreal_out
jmp near __initsig
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn __real_in
extrn __real_out
extrn __real_pdef
extrn __real_sdef
select _TEXT
public __fp_0 :
mov word [__real_in], __real_sdef
mov word [__real_out], __real_pdef
ret 0
end
File diff suppressed because it is too large Load Diff
+202
View File
@@ -0,0 +1,202 @@
(************************************************************************)
(* *)
(* Release 3.00 *)
(* *)
(* CoreMem - Common memory management module. *)
(* *)
(* Copyright (C) 1989, 1990 Jensen and Partners. All Rights Reserved *)
(* Written by Simon Knight. *)
(* *)
(* Copyright (C) 1991 Psion PLC. All Rights Reserved *)
(* Modified by NSM. *)
(* *)
(************************************************************************)
include "corelib.inc"
include "epocdefs.inc"
module CoreMem
(***************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn _errno
select _TEXT
public __ncalloc :
public _calloc :
push cx
push dx
mul bx
or dx, dx
je __nmallocEntry
__nmallocError : (* arrive here to return NULL *)
mov word [_errno], ENOMEM
sub ax, ax
pop dx
pop cx
ret 0
public __nmalloc :
public _malloc :
push cx
push dx
or dl, 1
__nmallocEntry:
or ax, ax
je __nmallocError (* return NULL if size = 0 *)
mov cx, ax
mov ah, NmHeapAllocateCell
int HeapManager
jc __nmallocError
test dl, dl
jne __noZeroFill (* was malloc, so no zero fill *)
push di
mov di, ax
mov dx, ax
sub ax, ax
cld
shr cx, 1
rep; stosw
pop di
mov ax, dx
__noZeroFill:
pop dx
pop cx
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
select _TEXT
public _coreleft :
public __memavl :
public _nearcoreleft :
push bx
mov ah, NmHeapFreeMemory
int HeapManager
pop bx
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
select _TEXT
public __nfree :
public _free :
push ax
push bx
mov bx, ax
mov ah, NmHeapFreeCell
int HeapManager
pop bx
pop ax
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
select _TEXT
public __msize :
public __nmsize :
push bx
mov bx, ax
mov ah, NmHeapCellSize
int HeapManager
pop bx
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
extrn __nheapchk
select _TEXT
public __heapchk :
jmp near __nheapchk
(***************************************************************************)
section
segment _TEXT(CODE,28H)
extrn __nheapset
select _TEXT
public __heapset :
jmp near __nheapset
(***************************************************************************)
section
segment _TEXT(CODE,28H)
extrn __nheapwalk
select _TEXT
public __heapwalk :
jmp near __nheapwalk
(***************************************************************************)
section
segment _TEXT(CODE,28H)
extrn _errno
extrn __nfree
select _TEXT
public __nrealloc :
public _realloc :
test bx, bx
jne _notFree
push bx
mov bx, ax
call __nfree
pop bx
sub ax, ax
ret 0
_notFree:
push bx
push cx
mov cx, bx
mov bx, ax
mov ah, NmHeapReAllocateCell
int HeapManager
jnc reAllocExit
mov word [_errno], ENOMEM
sub ax, ax
reAllocExit:
pop cx
pop bx
ret 0
end
File diff suppressed because it is too large Load Diff
+525
View File
@@ -0,0 +1,525 @@
(* Release 3.00 *)
(* c_signal - signal module *)
(* Copyright (C) 1989 Jensen and Partners. All Rights Reserved*)
(* Written by Simon Knight.*)
(* Copyright (C) 1991 Psion PLC. All Rights Reserved*)
(* Modified by NSM.*)
include "corelib.inc"
include "epocdefs.inc"
module csignal
(***************************************************************************)
segment _BSS(BSS, 28H)
public CoreSig@CnsHandler : org CodePtrSize
segment _BSS(BSS, 28H)
public __sigTable : org 46
segment _BSS(BSS, 28H)
public @RecursiveExit : org 2
segment _BSS(BSS, 28H)
public _errno : org 2
(***************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
extrn _errno
select _TEXT
public __seterrno :
mov [_errno], ax
ret 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
extrn _errno
select _TEXT
public __errno__ :
mov ax, _errno
ret 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
extrn _errno
extrn __doserrno
validError:
db 0, -1, -2, -5, -6, -7, -9
db -10,-15,-16,-18,-32,-33,-36
db -37,-39,-40,-41,-42,-66, 1
select _TEXT
public __ioerr :
cbw
mov [__doserrno], ax
push bx
cmp ax, -128
jl invalid
cmp ax, 0
jg invalid
mov bx, validError
locateLoop:
cmp [bx], al
je errorOk
inc bx
cmp byte [bx], 1
jne locateLoop
invalid:
mov ax, EFAULT
errorOk:
pop bx
mov [_errno], ax
ret 0
dw __doserrno
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA, 28H)
select _TEXT (* must be in TEXT *)
extrn __FloatJmpSave
extrn __FloatJmpRestore
extrn _DatClassHandle
extrn _DatClassPtr
extrn _DatEnterFramePtr
extrn _DatOsFramePtr
public _setjmp :
public __setjmp :
(*
int setjmp(jmp_buf task_state)
Saves current task state and returns 0.
*)
push bp
mov bp, sp
push di
mov di, ax
call __FloatJmpSave
pushf
pop ax
stosw
mov ax, [bp][2]
stosw
lea ax, [bp][4]
stosw
mov ax, [bp]
stosw
mov ax, si
stosw
mov ax, [bp][-2]
stosw
mov ax, dx
stosw
mov ax, cx
stosw
mov ax, bx
stosw
mov ax,[_DatClassHandle]
stosw
mov ax,[_DatClassPtr]
stosw
mov ax,[_DatEnterFramePtr]
stosw
mov ax,[_DatOsFramePtr]
stosw
sub ax, ax
pop di
pop bp
ret 0
(* _setjmp ENDP *)
public _longjmp :
(*
void longjmp ( task_state, val);
Restores task state and jumps to landing_zone.
Returns val. (If val == 0, val++)
*)
mov si, ax
cmp bx, 1 (* generates carry if BX = 0 *)
adc bx, 0 (* (val) BX = (BX) ? BX : 1; *)
call __FloatJmpRestore
mov di, [si][_j_di]
mov dx, [si][_j_dx]
mov cx, [si][_j_cx]
mov ax, [si][_j_classHandle]
mov [_DatClassHandle], ax
mov ax, [si][_j_classPtr]
mov [_DatClassPtr], ax
mov ax, [si][_j_enterFrame]
mov [_DatEnterFramePtr], ax
cli
mov sp, [si][_j_sp]
mov bp, [si][_j_bp]
mov ax, [si][_j_osFrame]
mov [_DatOsFramePtr], ax
push [si][_j_flag]
popf
push [si][_j_ip]
mov ax, bx
mov bx, [si][_j_bx]
mov si, [si][_j_si]
ret 0
(* _longjmp ENDP *)
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
select _DATA
HeadMsg : db 'Process Terminated', 0
select _TEXT
public __sysmsg :
mov bx, HeadMsg
mov cx, ax
sub dx, dx
mov di, dx
mov si, dx
mov ah, NmGenNotify
int GenManager
ret 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _INIT(DATA,28H)
segment _DATA(DATA,28H)
extrn __initsig
extrn __InitLoop
select _TEXT
do_initsig : (* defined later on ! *)
select _INIT
initsig : dw MAGIC
db PR3
dw do_initsig
select _DATA
public __NSIG : dw 22, initsig
select _TEXT
call __initsig
jmp __InitLoop
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
segment _BSS(BSS,28H)
extrn __FatalError
extrn __FatalErrorPos
extrn __table_raise
select _BSS
extrn __sigTable
SIGINT = 2
SIGILL = 8
SIGFPE = 16
SIGSEGV = 22
SIGTERM = 30
SIGUSR1 = 32
SIGUSR2 = 34
SIGUSR3 = 40
SIGABRT = 44
select _DATA
DefMsg : db 'By Signal', 0
FpeMsg : db 'By Floating Point Exception', 0
Usr1Msg : db 'By User 1 Signal', 0
Usr2Msg : db 'By User 2 Signal', 0
Usr3Msg : db 'By User 3 Signal', 0
AbrtMsg : db 'By Abort', 0
extrn __sigsetup
extrn __exitsig
extrn __sysmsg
extrn __FloatMathExcepDos
extrn __NSIG
extrn __SH_sword
extrn __exc_addr
select _TEXT
SIG_ERR = -1
SIG_DFL = 0
SIG_IGN = 1
__do_exitsig :
ret 0
public __initsig :
(* set up handler table *)
cmp word [__sigsetup], 0
jnz near noInit
not word [__sigsetup]
mov bx, __sigTable
mov word [__exitsig], __do_exitsig
mov ax, SIG_DFL
mov [bx][SIGABRT], ax (* SIGABRT *)
mov [bx][SIGILL], ax (* SIGILL *)
mov [bx][SIGSEGV], ax (* SIGSEGV *)
mov [bx][SIGINT], ax (* SIGINT *)
mov [bx][SIGFPE], ax (* SIGFPE *)
mov [bx][SIGTERM], ax (* SIGTERM *)
mov [bx][SIGUSR1], ax (* SIGUSR1 *)
mov [bx][SIGUSR2], ax (* SIGUSR2 *)
mov [bx][SIGUSR3], ax (* SIGUSR3 *)
noInit:
ret 0
public __sigIgnore :
(* A signal is ignored by doing nothing. *)
ret 0
public __sigDefault :
(* Default action when a signal occurs is to exit the program. *)
push ax
cmp ax, 8
je typeFPE
cmp ax, 16
je typeUsr1
cmp ax, 17
je typeUsr2
cmp ax, 20
je typeUsr3
cmp ax, 22
je typeABRT
typeDEFAULT:
mov ax, DefMsg
jmp sendMessage
typeFPE:
mov ax, FpeMsg
jmp sendMessage
typeUsr1:
mov ax, Usr1Msg
jmp sendMessage
typeUsr2:
mov ax, Usr2Msg
jmp sendMessage
typeUsr3:
mov ax, Usr3Msg
jmp sendMessage
typeABRT:
mov ax, AbrtMsg
sendMessage:
call __sysmsg
call __FatalErrorPos
pop cx
mov bx, FatalSignal
cmp cx, 8
jne notFP
mov ax, [__exc_addr]
notFP:
jmp __FatalError
public __sigFp :
call __FloatMathExcepDos
push ax
push bx
push cx
push dx
push di
push si
mov bx, SIGFPE
mov ax, [__SH_sword]
mov cx, 8
transLoop:
shr ax, 1
jc foundBit
loop transLoop
foundBit:
mov ax, 89H
sub ax, cx
call __table_raise
pop si
pop di
pop dx
pop cx
pop bx
pop ax
ret 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
segment _BSS(BSS,28H)
extrn __NSIG
extrn __sigTable
extrn __sigIgnore
extrn __sigDefault
extrn __seterrno
select _TEXT
public _signal :
(*
void ( *signal(int sig, void ( * func)()))();
sets signal handler to func.
Returns old function pointer.
*)
EINVAL = 19
push bx
push cx
mov cx, bx
mov bx, ax
or bx, bx
je sigErr
cmp bx, [__NSIG]
ja sigErr
shl bx, 1 (* calculate table index *)
add bx, __sigTable
mov ax, [bx]
mov [bx], cx (* store new function pointer *)
sigDone:
pop cx
pop bx
ret 0
sigErr:
mov ax, EINVAL
call __seterrno
mov ax, -1
jmp sigDone
public _raise :
(*
int raise(sig);
raises signal.
*)
push bx
push cx
mov cx, bx
mov bx, ax
or bx, bx
je raiseErr
cmp bx, [__NSIG]
ja raiseErr
shl bx, 1 (* calculate table index *)
mov ax, cx
call __table_raise
sub ax, ax
raiseDone:
pop cx
pop bx
ret 0
raiseErr: (* return -1 *)
mov ax, -1
jmp raiseDone
SIG_DFL = 0
SIG_IGN = 1
SIGINT = 2
SIGILL = 8
SIGFPE = 16
SIGSEGV = 22
SIGTERM = 30
SIGUSR1 = 32
SIGUSR2 = 34
SIGUSR3 = 40
SIGABRT = 44
public __table_raise : (* bx = sig num offset, ax = arg *)
push bx
push cx
push dx
mov dx, ax
mov ax, bx
shr ax, 1
mov cx, [bx][__sigTable]
cmp bx, SIGTERM
je doDFL
cmp bx, SIGABRT
je doDFL
cmp bx, SIGILL
je doDFL
cmp bx, SIGSEGV
je doDFL
cmp bx, SIGINT
je doDFL
cmp bx, SIGFPE
je doDFL
cmp bx, SIGUSR1
je doDFL
cmp bx, SIGUSR2
je doDFL
cmp bx, SIGUSR3
jne dontSet
doDFL:
mov word [bx][__sigTable], SIG_DFL
dontSet:
cmp cx, 1
jbe defRaise
mov bx, dx
call cx
trDone:
pop dx
pop cx
pop bx
ret 0
defRaise:
jcxz callDefault
call __sigIgnore
jmp trDone
callDefault:
call __sigDefault
jmp trDone
end
+159
View File
@@ -0,0 +1,159 @@
(* Release 3.10 *)
(*-------------------------------------------------------------------------*
* *
* CPPLOW.A - C++ assembler implementations *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*)
include "corelib.inc"
module cpplow
(******************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
segment _INIT(DATA,28H)
extrn __init_standard
select _TEXT
do_initstandard : (* defined later on ! *)
select _INIT
initio : dw MAGIC
db PRL
dw do_initstandard
select _DATA
public __assign_init_magic : dw 0, initio
select _TEXT
call __init_standard
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
segment _INIT(DATA,28H)
extrn __init_con
select _TEXT
do_initcon : (* defined later on ! *)
select _INIT
initcon : dw MAGIC
db PRL
dw do_initcon
select _DATA
public __flush_init_magic : dw 0, initcon
select _TEXT
call __init_con
ret 0
(***************************************************************************)
section
segment _DATA(DATA,28H)
segment _TEXT(CODE,28H)
(*
void _call_ctors(void *(*ctor)(void *), char *obj_ptr, int vbnum, int n, int siz);
void _call_dtors(void (*dtor)(void *), char *obj_ptr, int vbnum, int n, int siz);
*)
sframe = 4
tor = sframe
objptr = 2+sframe
vbnum = 4+sframe
n = 6+sframe
siz = 8+sframe
public __call_ctors :
push bp
mov bp, sp
push di
push si
sub di, di
ctorsCommon:
mov cx, [bp][n]
jcxz ctDone
ctLoop:
push cx
or di, di
jz noDec
mov cx, [bp][siz]
sub [bp][objptr], cx
noDec:
mov si, 3
mov ax, [bp][objptr]
mov bx, di
mov cx, [bp][vbnum]
mov dx, di
sub cx, si
jle ctCallConst
ctPushLoop:
push dx
loop ctPushLoop
ctCallConst:
mov cx, di
call word [bp][tor]
or di, di
jnz noInc
mov cx, [bp][siz]
add [bp][objptr], cx
noInc:
pop cx
loop ctLoop
ctDone:
pop si
pop di
pop bp
ret 0
public __call_dtors :
push bp
mov bp, sp
push di
push si
mov di, 1
jmp ctorsCommon
(***************************************************************************)
section
segment _TEXT(CODE,28H)
extrn __bcd
public __cvt_bcd :
xchg ax, bx
fbld st(0), ss:[bx]
fstp st(1), st(0)
xchg ax, bx
ret 0
public __real_to_dec :
push bp
mov bp, sp
mov bx, ax
fld st(0), st(0)
fistp qword [bx], st(0)
pop bp
ret 0
end
File diff suppressed because it is too large Load Diff
+437
View File
@@ -0,0 +1,437 @@
/* Release 3.00 */
/*-------------------------------------------------------------------------*
* *
* csys.c - common system functions. *
* *
* COPYRIGHT (C) 1989 Jensen and Partners. All Rights Reserved *
* Written by Simon Knight. *
* *
* COPYRIGHT (C) 1991 Psion PLC. All Rights Reserved *
* Modified by NSM. *
* *
*--------------------------------------------------------------------------*/
#define _USE_CONIO
#define _USE_TIME
#include <clib.h>
/*-------------------------------------------------------------------------*
* exit functions - terminate process after closing open files. *
*--------------------------------------------------------------------------*/
void _exit1(void)
{
int n;
_flushall();
n=0;
while(n < _open_max)
{
if(_openfd[n])
close(n);
n++;
}
return;
}
void _exit2(void)
{
int n;
char *tmp;
n=0;
while (n < _open_max)
{
if ((tmp=_tmpfiles[n])!=NULL)
{
if(_openfd[n])
close(n);
unlink(tmp);
}
n++;
}
return;
}
/*-------------------------------------------------------------------------*
* abort - print message and raise ABORT signal. *
*--------------------------------------------------------------------------*/
void abort(void)
{
fputs("Abnormal Program Termination\n", stderr);
raise(SIGABRT);
return;
}
/*-------------------------------------------------------------------------*
* atexit - put function pointer on stack to be called by exit. *
*--------------------------------------------------------------------------*/
int atexit(void (* func)(void))
{
int ret;
if(_exit_ptr != _exit_stk) /* return if stack full */
{
*(--_exit_ptr)=func; /* push func */
ret=0;
}
else
ret=-1;
return(ret);
}
/*-------------------------------------------------------------------------*
* onexit - put function pointer on stack to be called by exit. *
*--------------------------------------------------------------------------*/
void (* onexit(void (* func)(void)))()
{
void (* ret)(void);
if(_exit_ptr != _exit_stk) /* return if stack full */
{
*(--_exit_ptr)=func; /* push func */
ret=func;
}
else
ret=NULL;
return(ret);
}
/*-------------------------------------------------------------------------*
* system - execute command.com. *
*--------------------------------------------------------------------------*/
int system(const char *command)
{
char *compath;
compath=getenv("COMSPEC"); /* use COMSPEC to find command.com */
if(compath == NULL)
compath="ROM::SYS$SHLL";
if(command == NULL)
{
if(!_exists(compath)) /* does file exist ? */
{
errno=ENOENT;
return(0);
}
return(1);
}
flushall(); /* flush open streams */
return(spawnl(P_WAIT,compath,"",command,NULL));
}
/*-------------------------------------------------------------------------*
* exec?? - execute child process. *
*--------------------------------------------------------------------------*/
#pragma warn(wpnu => off)
int execl(const char *path, char *arg0, ...)
{
va_list argptr;
va_start(argptr, path);
return(_execc(path, (char **) argptr, _E_EXEC));
}
int execlp(const char *path, char *arg0, ...)
{
va_list argptr;
va_start(argptr, path);
return(_execc(path, (char **) argptr, _E_EXEC|_E_SEARCH));
}
int execv(const char *path, char *argv[])
{
return(_execc(path, argv, _E_EXEC));
}
int execvp(const char *path, char *argv[])
{
return(_execc(path, argv, _E_EXEC|_E_SEARCH));
}
/*-------------------------------------------------------------------------*
* spawn?? - spawn child process. *
*--------------------------------------------------------------------------*/
int spawnl(int mode, const char *path, char *arg0, ...)
{
va_list argptr;
va_start(argptr, path);
return(_execc(path, (char **) argptr, mode));
}
int spawnlp(int mode, const char *path, char *arg0, ...)
{
va_list argptr;
va_start(argptr, path);
return(_execc(path, (char **) argptr, mode|_E_SEARCH));
}
int spawnv(int mode, const char *path, char *argv[])
{
return(_execc(path, argv, mode));
}
#pragma warn(wpnu => on)
int spawnvp(int mode, const char *path, char *argv[])
{
return(_execc(path, argv, mode|_E_SEARCH));
}
/*-------------------------------------------------------------------------*
* searchenv - find file using environment string *
*--------------------------------------------------------------------------*/
void _searchenv(const char *name, const char *env, char *path)
{
char *envpath;
int n, p, c;
int length;
if((envpath=getenv(env)) == NULL)
{
path[0]=0;
return;
}
length=strlen(name)+1;
getcwd(path, 0x80); /* try current directory */
n=strlen(path);
path[n++]='\\';
memcpy(&path[n], name, length);
if(_exists(path))
{
return; /* found it already */
}
n=0;
p=0;
do /* search each path */
{
while((c=envpath[n++]) && (c != ';'))
{
path[p++]= (char) c;
}
if(path[p-1] != '\\')
path[p++]='\\';
memcpy(&path[p], name, length);
if(_exists(path))
{
return; /* found it */
}
p=0;
} while (envpath[n-1]);
path[0]=0; /* couldn't find file */
return;
}
void sleep(unsigned seconds)
{
_sleepTenths(seconds*10l);
}
static void call_test1(void)
{
calloc(0, 0);
free(NULL);
malloc(0);
realloc(NULL, 0);
_ncalloc(0, 0);
_nfree(NULL);
_nmalloc(0);
_nrealloc(NULL, 0);
_msize(NULL);
_memmax();
_memavl();
_heapchk();
_heapset(0);
_heapwalk(NULL);
coreleft();
_freect(0);
_nheapchk();
_nheapset(0);
_nheapwalk(NULL);
_nmsize(NULL);
nearcoreleft();
}
static void call_test3(void)
{
cgets(NULL);
cputs(NULL);
getch();
getche();
kbhit();
putch(0);
ungetch(0);
}
static void call_test4(void)
{
chdir(NULL);
getcurdir(0, NULL);
getcwd(NULL, 0);
_getdrive();
mkdir(NULL);
rmdir(NULL);
getdisk();
searchpath(NULL);
setdisk(0);
}
static void call_test6(void)
{
access(NULL, 0);
chmod(NULL, 0);
chsize(0, 0L);
}
static void call_test7(void)
{
abs(0);
acos(0.0);
asin(0.0);
atan(0.0);
atan2(0.0, 0.0);
atof(NULL);
ceil(0.0);
cos(0.0);
cosh(0.0);
exp(0.0);
fabs(0.0);
floor(0.0);
fmod(0.0, 0.0);
frexp(0.0, NULL);
labs(0L);
ldexp(0.0, 0);
log(0.0);
log10(0.0);
modf(0.0, NULL);
poly(0.0, 0, NULL);
pow(0.0, 0.0);
sin(0.0);
sinh(0.0);
sqrt(0.0);
strtod(NULL, NULL);
tan(0.0);
tanh(0.0);
matherr(NULL);
hypot(0.0, 0.0);
pow10(0);
_fpreset();
}
static void call_test8(void)
{
void *ptr=NULL;
memccpy(ptr, ptr, 0, 0);
memchr(ptr, 0, 0);
memcmp(ptr, ptr, 0);
memcpy(ptr, ptr, 0);
memicmp(ptr, ptr, 0);
memmove(ptr, ptr, 0);
memset(ptr, 0, 0);
movmem(ptr, ptr, 0);
setmem(ptr, 0, 0);
memwmove(ptr, ptr, 0);
memwset(ptr, 0, 0);
memwcpy(ptr, ptr, 0);
}
static void call_test9(void)
{
signal(0, NULL);
raise(0);
}
static void call_test10(void)
{
fgetc(NULL);
fputc(0, NULL);
rename(NULL, NULL);
unlink(NULL);
}
static void call_test11(void)
{
delay(0);
getenv(NULL);
mblen(NULL, 0);
mbtowc(NULL, NULL, 0);
wctomb(NULL, 0);
mbstowcs(NULL, NULL, 0);
wcstombs(NULL, NULL, 0);
ecvt(0.0, 0, NULL, NULL);
_exit(0);
fcvt(0.0, 0, NULL, NULL);
gcvt(0.0, 0, NULL);
itoa(0, NULL, 0);
_lrotl(0L, 0);
_lrotr(0L, 0);
ltoa(0L, NULL, 0);
_searchenv(NULL, NULL, NULL);
_rotl(0, 0);
_rotr(0, 0);
swab(NULL, NULL, 0);
ultoa(0L, NULL, 0);
}
static void call_test12(void)
{
void *ptr=NULL;
strcat(ptr, ptr);
strcmp(ptr, ptr);
strcpy(ptr, ptr);
strlen(ptr);
strset(ptr, 0);
stpcpy(ptr, ptr);
strchr(ptr, 0);
strcoll(ptr, ptr);
strxfrm(ptr, ptr, 0);
strcspn(ptr, ptr);
strdup(ptr);
strerror(0);
stricmp(ptr, ptr);
strlwr(ptr);
strncat(ptr, ptr, 0);
strncmp(ptr, ptr, 0);
strncpy(ptr, ptr, 0);
strnicmp(ptr, ptr, 0);
strnset(ptr, 0, 0);
strpbrk(ptr, ptr);
strrchr(ptr, 0);
strrev(ptr);
strspn(ptr, ptr);
strstr(ptr, ptr);
strtok(ptr, ptr);
strupr(ptr);
}
static void call_test13(void)
{
settime(NULL);
gettime(NULL);
setdate(NULL);
getdate(NULL);
utime(NULL, NULL);
get_utime(0);
_filetime(0, NULL);
}

+751
View File
@@ -0,0 +1,751 @@
(* *)
(* Release 3.00 *)
(* *)
(* Epoc/Os - Interface routines *)
(* *)
(* Copyright (C) 1991 Psion PLC. All Rights Reserved *)
(* Written by NSM. *)
(* *)
(************************************************************************)
include "corelib.inc"
include "epocdefs.inc"
module Epoc
(***************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
__ServerName: db "SYS$FSRV.*",0
__FileDevName: db "FIL",0
segment _BSS(BSS,28H)
public __FServerPid : org 2 (* File server process id *)
public __FilDeviceHandle : org 2 (* File device driver handle *)
select _TEXT
public __EpocInit :
sub al, al
mov ah, NmFilConnect
int FilManager
sub bx, bx
sub sp, MaxNameESize + 2
mov si, sp
mov di, __ServerName
mov ah, NmProcFind
int ProcManager
mov [__FServerPid], ax
sub bx, bx
mov dx, LDDSignature
mov di, __FileDevName
mov si, sp
mov ah, NmDevFind
int DevManager
mov [__FilDeviceHandle], ax
add sp, MaxNameESize + 2
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
public __allocInfo :
push ax
push bx
push di
push si
mov si, ax (* Arg 1 *)
mov ah, NmProcId
int ProcManager
mov di, ax
int GenDataSegment
and di, PidMask
mov ax, es:[di][ProcMemBasePtr]
test ax, ax
je infoExit
mov [bx], ax
add ax, MemEnt
mov [si], ax
infoExit:
pushf
cli
mov bx, ss
mov es, bx
popf
pop si
pop di
pop bx
pop ax
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
select _TEXT
public __heapTop :
push bx
mov ah, NmProcId
int ProcManager
mov bx, ax
and bx, PidMask
int GenDataSegment
mov bx, es:[bx][ProcDataSeg]
pushf
cli
mov ax, es:[bx][SegEnt][SegBase]
sub ax, es:[bx][SegBase]
mov bx, ss
mov es, bx
popf
shl ax, 1
shl ax, 1
shl ax, 1
shl ax, 1
pop bx
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
public _getpid :
mov ah, NmProcId
int ProcManager
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
public __getDateAndTime :
pop ax
sub sp, DateEnt
mov si, sp
sub sp, DyScEnt
mov di, sp
push ax
push bx
mov ah, NmTimGetSystemTime
int TimManager
push cx
push dx
mov cx, ax
mov dx, bx
mov ah, NmTimSystemTimeToDaySeconds
int TimManager
pop dx
pop cx
xchg di, si
mov ah, NmTimDaySecondsToDate
int TimManager
pop bx
ret 0
(***************************************************************************)
section
segment _TEXT(CODE,28H)
public __setDateAndTime :
lea si, [di][-DyScEnt]
xchg si, di
mov ah, NmTimDateToDaySeconds
int TimManager
xchg si, di
mov ah, NmTimDaySecondsToSystemTime
int TimManager
push bx
push cx
push dx
mov cx, ax
mov dx, bx
mov ah, NmTimSetSystemTime
int TimManager
pop dx
pop cx
pop bx
ret 0
(****************************************************************************)
section
segment _TEXT(CODE,28H)
(* WORDREGS Structure *)
_ax = 0
_bx = 2
_cx = 4
_dx = 6
_si = 8
_di = 10
_cflag = 12
_flags = 14
extrn __ioerr
public _int86x :
public _int86 :
(*
int int86(int intnum, union REGS *inregs, union REGS *outregs)
loads 086 registers and executes interrupt. AX value is returned. If the
carry flag is set cflag is !=0 and _doserrno is set to the error code.
*)
push di
push si
mov si, bx
mov di, cx
int GenIntByNumber
mov [di][_flags], ax
mov word [di][_cflag], 0
jnc noCarry
inc word [di][_cflag]
mov ax, [di][_ax]
call __ioerr
noCarry:
mov ax, [di][_ax]
pop si
pop di
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public _intr :
(* REGPACK Structure *)
r_ax = 0
r_bx = 2
r_cx = 4
r_dx = 6
r_bp = 8
r_si = 10
r_di = 12
r_ds = 14
r_es = 16
r_flags = 18
push ax
push bx
push di
push si
mov si, bx
mov di, bx
mov bx, [si][r_si]
xchg bx, [si][r_bp]
xchg bx, [si][r_di]
mov [si][r_di], bx
int GenIntByNumber
mov [di][r_flags], ax
mov ax, [di][r_di]
xchg ax, [di][r_bp]
xchg ax, [di][r_si]
mov [di][r_di], bx
pop si
pop di
pop bx
pop ax
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __iopen :
push dx
push di
mov di, ax
sub dx, dx
mov ah, NmIoOpen
int DevManager
jc openFailed
mov [di], ax
sub al, al
openFailed:
cbw
pop di
pop dx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __iow2 :
public __iow3 :
public __iow4 :
xchg ax, bx
mov ah, NmIoWithWait
int IoManager
jnc iowOk
cbw
iowOk:
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __parse :
push di
push si
mov si, dx
mov di, cx
mov cx, bx
mov bx, ax
sub al, al
mov ah, NmFilParse
int FilManager
jc parseFailed
sub al, al
parseFailed:
cbw
pop si
pop di
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
DaySeconds = -DyScEnt
DateF = -(DyScEnt+DateEnt)
locals = (DyScEnt+DateEnt)
public __convTimeToDos :
push di
push si
push dx
push cx
push bp
mov bp, sp
sub sp, locals
mov cx, bx
mov dx, ax
mov ax, cx
cmp dh, 0A6H
sbb ax, 012CEH
jnc timeOk
mov cx, 012CEH
mov dx, 0A600H
timeOk:
lea di, [bp][DaySeconds]
mov ah, NmTimSystemTimeToDaySeconds
int TimManager
mov si, di
lea di, [bp][DateF]
mov ah, NmTimDaySecondsToDate
int TimManager
xor ah, ah
mov al, [di][DateHour]
mov cx, 6
shl ax, cl
or al, [di][DateMinute]
dec cx
shl ax, cl
mov bl, [di][DateSecond]
shr bl, 1
or al, bl
xor dh, dh
mov dl, [di][DateYear]
sub dl, 80
mov cx, 4
shl dx, cl
or dl, [di][DateMonth]
inc dx
inc cx
shl dx, cl
or dl, [di][DateDay]
inc dx
add sp, locals
pop bp
pop cx
mov di, cx
mov [di], dx
pop dx
mov di, dx
mov [di], ax
pop si
pop di
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn __FServerPid
extrn __FilDeviceHandle
select _TEXT
public __FsChanToName :
push ax
push bx
push cx
push di
push si
push bx
push si
mov di, sp
mov si, ax
mov ax, [__FilDeviceHandle]
cmp [si][ChanLibHandle], ax
je isAFileHandle
pop si
pop di
and byte [di], 0
jmp chanExit
isAFileHandle:
mov si, [si][FilHandle]
add si, FsyFileName
mov bx, [__FServerPid]
mov cx, 2
int ProcCopyFromById
pop si
pop di
mov cx, MaxPathSize
int ProcCopyFromById
chanExit:
pop si
pop di
pop cx
pop bx
pop ax
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
extrn __FServerPid
extrn __FilDeviceHandle
select _TEXT
public __FsChanToMode :
push bx
push cx
push di
push si
mov di, sp
mov si, ax
mov ax, [__FilDeviceHandle]
cmp [si][ChanLibHandle], ax
mov ax, -1
jne modeExit
push ax
mov di, sp
mov si, [si][FilHandle]
add si, FsyFileMode
mov bx, [__FServerPid]
mov cx, 2
int ProcCopyFromById
pop ax
modeExit:
pop si
pop di
pop cx
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __systemTimeToDaySeconds :
push ax
push cx
push dx
push di
mov di, cx
mov dx, ax
mov cx, bx
mov ah, NmTimSystemTimeToDaySeconds
int TimManager
pop di
pop dx
pop cx
pop ax
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __daySecondsToSystemTime :
push bx
push si
mov si, ax
mov ah, NmTimDaySecondsToSystemTime
int TimManager
mov dx, ax
mov ax, bx
pop si
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __daySecondsToDate :
push ax
push di
push si
mov si, ax
mov di, bx
mov ah, NmTimDaySecondsToDate
int TimManager
pop si
pop di
pop ax
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __dateToDaySeconds :
push di
push si
mov si, ax
mov di, bx
mov ah, NmTimDateToDaySeconds
int TimManager
mov ax, 0
jnc convOk
dec ax
convOk:
pop si
pop di
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __date :
push bx
mov ah, NmTimGetSystemTime
int TimManager
mov dx, ax
mov ax, bx
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __fileInfo :
push bx
push cx
mov cx, bx
mov bx, ax
sub al, al
mov ah, NmFilStatusGet
int FilManager
jc gotFailed
sub al, al
gotFailed:
cbw
pop cx
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __fileSetModTime :
push bx
push cx
push di
mov di, cx
mov cx, bx
mov bx, ax
sub al, al
mov ah, NmFilSetFileDate
int FilManager
jc setFailed
sub al, al
setFailed:
cbw
pop di
pop cx
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __getPath :
push ax
push bx
mov bx, ax
sub al, al
mov ah, NmFilPathGet
int FilManager
pop bx
pop ax
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __setPath :
push ax
push bx
mov bx, ax
sub al, al
mov ah, NmFilPathSet
int FilManager
jc setFailed
sub al, al
setFailed:
cbw
pop bx
pop ax
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __sleepTenths :
push ax
push cx
push dx
mov dx, ax
mov cx, bx
mov ah, NmTimSleepForTenths
int TimManager
pop dx
pop cx
pop ax
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public ___execc :
push bx
push cx
push di
push ax
mov di, sp
mov cx, bx
mov bx, ax
sub al, al
mov ah, NmFilExecute
int FilManager
jnc gotHandle
cbw
mov [di], ax
gotHandle:
pop ax
pop di
pop cx
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __logon :
push bx
push di
mov di, bx
mov bx, ax
mov ah, NmIoSignalKillAsynchronous
int IoManager
jc logonFailed
sub al, al
logonFailed:
cbw
pop di
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __waitStat :
push ax
push di
mov di, ax
mov ah, NmIoWaitForStatus
int IoManager
pop di
pop ax
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __resume :
push bx
mov bx, ax
mov ah, NmProcResume
int ProcManager
jc resFailed
sub al, al
resFailed:
cbw
pop bx
ret 0
(******************************************************************************)
section
segment _TEXT(CODE,28H)
public __getErrorText :
mov ah, NmGenGetErrorText
int GenManager
mov ax, bx
ret 0
end
+744
View File
@@ -0,0 +1,744 @@
/* Release 3.00 */
/*-------------------------------------------------------------------------*
* *
* Epoc1.c - Epoc/Os interface routines *
* *
* COPYRIGHT (C) 1991 Psion PLC. All Rights Reserved *
* Written by NSM. *
* *
*--------------------------------------------------------------------------*/
#define _USE_CONIO
#define _USE_TIME
#include <clib.h>
#define SZMBLK sizeof(_MBLOCK) /* size of free cell header */
#define SZHD sizeof(unsigned int) /* size of allocated cell header */
extern char DatHeapLocked;
int _nheapwalk(struct _nheapinfo *pE)
/*
Walks through every cell in the heap (whether allocated
or free) from low to high address. Also checks the heap
for consistency and returns an error if something is wrong.
*/
{
int ret;
_MBLOCK *p1,*p2;
ret=_HEAPOK;
DatHeapLocked++;
if (pE->_pentry==NULL)
{
if (_allocInfo(&p1,&p2)==0)
{
ret=_HEAPEMPTY;
goto walkExit;
}
goto advanceFreePtr;
}
else
{
if (pE->_useflag) /* Was allocated */
{
p1=(_MBLOCK *)(((char *)pE->_pentry)-SZHD);
p2=pE->_secret;
}
else /* Was free */
{
p2=(_MBLOCK *)(((char *)pE->_pentry)-SZMBLK);
p1=pE->_secret;
}
if (p1<p2) /* Allocated cell is before free cell */
p1=(_MBLOCK *)(((char *)p1)+p1->mlen);
else /* Free cell is before allocated cell */
{
advanceFreePtr:
p2=p2->mnext; /* Points to first free cell */
if (p2!=NULL &&
((((int)p2)&1) || (p2>_heapTop()-1) ||
(p2->mnext && p2->mnext<p2+1)))
{
ret=_HEAPBADPTR;
goto returnFree;
}
}
}
if (p2 && p1<p2)
{
if ((((int)p1)&1) || p1->mlen<SZMBLK || (p1->mlen&1) ||
p1->mlen>((char *)p2-(char *)p1))
{
badNode:
ret=_HEAPBADNODE;
}
pE->_pentry=(int *)(((char *)p1)+SZHD);
pE->_size=p1->mlen-SZHD;
pE->_secret=p2;
pE->_useflag=1;
}
else if (p2)
{
p1=(_MBLOCK *)(((char *)p2)+p2->mlen); /* next allocated cell */
returnFree:
pE->_pentry=(int *)(((char *)p2)+SZMBLK);
pE->_size=p2->mlen-SZMBLK;
pE->_secret=p1;
pE->_useflag=0;
}
else if (_heapTop()!=p1)
goto badNode;
else
ret=_HEAPEND;
walkExit:
DatHeapLocked--;
return(ret);
}
static int heapDoIt(int flag,int fill)
/*
Actually does _nheapchk() and _nheapset().
*/
{
int ret;
struct _nheapinfo hi;
hi._pentry=NULL;
while ((ret=_nheapwalk(&hi))==_HEAPOK)
{
if (flag && hi._useflag==0)
memset(hi._pentry,(char)fill,hi._size);
}
if (ret==_HEAPEND)
ret=_HEAPOK;
return(ret);
}
int _nheapchk(void)
/*
Check the entire heap for consistency.
*/
{
return(heapDoIt(0,0));
}
int _nheapset(int fill)
/*
Check the entire heap for consistency and fill all
free cells with fill as we go along.
*/
{
return(heapDoIt(1,fill));
}
size_t _memmax(void)
/*
Returns the size of the biggest free cell.
*/
{
size_t ret,i;
_MBLOCK *p1,*p2;
ret=0;
DatHeapLocked++;
if (_allocInfo(&p1,&p2)==0)
goto memExit;
while ((p2=p2->mnext)!=NULL) /* Scan free cells */
{
i=p2->mlen-sizeof(unsigned int);
if (i>ret)
ret=i;
}
i=(unsigned int)0xfe00-(unsigned int)_heapTop()-sizeof(unsigned int);
if (i>ret)
ret=i;
memExit:
DatHeapLocked--;
return(ret);
}
static unsigned int memCalc(unsigned int num,unsigned int den)
/*
Works out how many times den will fit into num, where num is
the size of a free block in the heap.
*/
{
unsigned int ret;
num-=sizeof(unsigned int);
ret=num/den;
if (ret && (num%den)<SZMBLK)
ret--;
return(ret);
}
unsigned int _freect(size_t _size)
/*
Returns the number of times _size can be allocated from
the heap.
*/
{
unsigned int ret;
_MBLOCK *p1,*p2;
ret=0;
if (_size&1)
_size+=1;
if (_size<SZMBLK)
_size+=2;
DatHeapLocked++;
if (_allocInfo(&p1,&p2)==0)
goto freeExit;
while ((p2=p2->mnext)!=NULL) /* Scan free cells */
ret+=memCalc(p2->mlen,_size);
ret+=memCalc((unsigned int)0xfe00-(unsigned int)_heapTop(),_size);
freeExit:
DatHeapLocked--;
return(ret);
}
char *_d_cgets(char *s)
/*
Read a string of characters directly from the console.
*/
{
int i,c,maxLen,ql;
char *p,*q;
static char _b1[] = {'\b',' ','\b'};
static char _b2[] = {'\b','\b',' ',' ','\b','\b'};
static char _cr[] = {'\r'};
maxLen=(s[0]&0xff);
p=(&s[2]);
i=0;
while ((c=getch())!='\r')
{
if (c=='\b')
{
if (i)
{
i--;
if (p[i]<' ')
{
q=(&_b2[0]);
ql=sizeof(_b2);
}
else
{
q=(&_b1[0]);
ql=sizeof(_b1);
}
_iow4(winHandle,P_FWRITE,q,&ql);
}
}
else if (i<maxLen)
{
if (c<' ')
{
putch('^');
putch(c+'@');
}
else
putch(c);
p[i++]=c;
}
else
putch(0x7);
}
ql=1;
_iow4(winHandle,P_FWRITE,&_cr,&ql);
s[1]=i;
p[i]=0;
return((char *)p);
}
char _pname[P_FNAMESIZE];
P_FPARSE _pinfo;
int _isloc(const char *path)
/*
Returns true if path is on the local file system.
*/
{
if (_parse(path,"",&_pname[0],&_pinfo)<0)
return(0);
return(memcmp("LOC",&_pname[0],3)==0 ? 1 : 0);
}
#define MAXD 4
typedef struct
{
int magic;
char *handle;
} _DCTL;
typedef struct
{
char *handle;
int ctl;
int magic;
int attrib;
int first;
} _DRES;
_STATIC _DCTL _dctl[MAXD];
_STATIC int _dNext;
int findfirst(const char *path,struct ffblk *b,int attrib)
/*
Find the first matching directory entry.
*/
{
int ret;
char *h;
_DRES *r;
if (!_isloc(path))
{
errno=EINVAL;
return(-1);
}
if ((h=_dctl[_dNext].handle)!=NULL)
{
_iow2(h,P_FCLOSE);
_dctl[_dNext].handle=NULL;
}
_dctl[_dNext].magic++;
if ((ret=_iopen(&h,(char *)path,P_FDIR))<0)
{
failed:
_ioerr(ret);
return(-1);
}
r=(_DRES *)&b->ff_reserved[0];
r->handle=h;
r->ctl=_dNext;
r->magic=_dctl[_dNext].magic;
r->attrib=(attrib&0xff);
r->first=ENOENT;
_dctl[_dNext++].handle=h;
if (_dNext>=MAXD)
_dNext=0;
return(findnext(b));
}
int findnext(struct ffblk *b)
/*
Find the next directory entry.
*/
{
int a;
_DRES *r;
P_INFO f;
r=(_DRES *)&b->ff_reserved[0];
if (_dctl[r->ctl].magic!=r->magic)
{
failed:
errno=(r->first ? ENOENT : ENMFILE);
return(-1);
}
do
{
if ((a=_iow4(r->handle,P_FREAD,&b->ff_name[0],&f))<0)
{
_iow2(r->handle,P_FCLOSE);
_dctl[r->ctl].handle=0;
_dctl[r->ctl].magic++;
_ioerr(a);
return(-1);
}
a=f.status&(FA_HIDDEN|FA_SYSTEM|FA_LABEL|FA_DIREC);
} while (a && (a&r->attrib)==0);
b->ff_attrib=(f.status&0xff)^1;
b->ff_fsize=f.size;
_convTimeToDos(f.modst,&b->ff_fdate,&b->ff_ftime);
return(0);
}
int utime(char *path,struct utm *ftime)
/*
Set the modification time of a file.
*/
{
INT ret;
P_DATE dt;
P_DAYSEC ds;
time_t t;
if (ftime)
{
dt.year=ftime->u_year+80;
dt.month=ftime->u_mon-1;
dt.day=ftime->u_day-1;
dt.hour=ftime->u_hour;
dt.minute=ftime->u_min;
dt.second=ftime->u_sec;
_dateToDaySeconds(&dt,&ds);
t=_daySecondsToSystemTime(&ds);
}
else
t=_date();
if ((ret=_fileSetModTime(path,t))<0)
{
_ioerr(ret);
return(-1);
}
return(0);
}
int _filetime(int handle,struct utm *ftime)
/*
Get the modified time of the file open on handle.
*/
{
int ret;
char name[P_FNAMESIZE];
P_DAYSEC ds;
P_DATE dt;
P_INFO pI;
_FsChanToName(getRealHandle(handle),&name[0]);
if (name[0])
{
if ((ret=_fileInfo(&name[0],&pI))<0)
{
_ioerr(ret);
return(-1);
}
_systemTimeToDaySeconds((time_t)pI.modst,&ds);
_daySecondsToDate(&ds,&dt);
if (dt.year<80)
goto baseDate;
}
else
{
baseDate:
memset(&dt,0,sizeof(dt));
dt.year=80;
}
ftime->u_year=dt.year-80;
ftime->u_mon=dt.month+1;
ftime->u_day=dt.day+1;
ftime->u_hour=dt.hour;
ftime->u_min=dt.minute;
ftime->u_sec=dt.second;
return(0);
}
int _filedrive(int handle)
/*
Return the drive letter if on LOC:: file system.
*/
{
char name[P_FNAMESIZE];
_FsChanToName(getRealHandle(handle),&name[0]);
if (name[0] && memcmp("LOC",&_pname[0],3)==0)
return(name[5]-'A');
return(0);
}
int _execc(const char *path, char **argv, int mode)
/*
Generalised exec call.
*/
{
int pid;
WORD stat;
char *p,*pe,*s,name[P_FNAMESIZE],command[0x80];
if (mode&_E_SEARCH)
{
mode&=(~_E_SEARCH);
if (_parse(path,".img",&_pname[0],&_pinfo)<0)
{
errno=EINVAL;
return(-1);
}
_searchenv(&_pname[_pinfo.system+_pinfo.device+_pinfo.path],"PATH",&name[0]);
if (name[0]==0)
{
errno=ENOENT;
return(-1);
}
}
else
strcpy(&name[0],path);
argv++;
p=(&command[0]);
pe=p+0x7f;
while (*argv)
{
*p++=' ';
s=(*argv++);
while (p<pe && *s)
*p++=(*s++);
if (p>=pe)
{
errno=E2BIG;
return(-1);
}
}
*p++=0;
command[0]=p-(&command[1]);
if ((pid=__execc(&name[0],&command[0]))<0)
{
_ioerr(pid);
return(-1);
}
if (mode&_E_EXEC || mode==P_OVERLAY)
{
_resume(pid);
exit(0);
}
if (mode==P_NOWAIT)
{
_resume(pid);
return(pid);
}
_logon(pid,&stat);
_resume(pid);
_waitStat(&stat);
return(stat);
}
int getdisk(void)
/*
Get the current disk.
*/
{
_getPath(&_pname[0]);
if (!_isloc(&_pname[0]))
return(0);
return(_pname[5]-'A');
}
int setdisk(int drive)
/*
Set the current disk.
*/
{
void *h;
_getPath(&_pname[0]);
if (!_isloc(&_pname[0]))
return(0);
_pname[5]='A'+drive;
_setPath(&_pname[0]);
_iopen(&h,"LOC::",P_FDEVICE);
drive=0;
while (_iow3(h,P_FREAD,&_pname[0])>=0)
drive++;
_iow2(h,P_FCLOSE);
return(drive);
}
int getftime(int handle,struct ftime *f)
/*
Get the file time from and open file.
*/
{
int ret;
struct utm ftime;
if ((ret=_filetime(handle, &ftime))<0)
return(ret);
f->ft_tsec = (unsigned) (ftime.u_sec>>1);
f->ft_min = (unsigned) ftime.u_min;
f->ft_hour= (unsigned) ftime.u_hour;
f->ft_day= (unsigned) ftime.u_day;
f->ft_month= (unsigned) ftime.u_mon;
f->ft_year=ftime.u_year+1980;
return(0);
}
long _lseek(void *handle, long offset, int where)
/*
Seek on a file by handle.
*/
{
int ret,mode;
long endPos,newPos;
switch (where)
{
case SEEK_CUR:
mode=P_FCUR;
goto doSeek;
case SEEK_END:
mode=P_FEND;
doSeek:
newPos=0l;
_iow4(handle,P_FSEEK,&mode,&newPos);
newPos+=offset;
break;
case SEEK_SET:
newPos=offset;
}
if (newPos<0)
newPos=0;
endPos=newPos;
mode=P_FABS;
if ((ret=_iow4(handle,P_FSEEK,&mode,&newPos))<0)
goto failed;
if (newPos!=endPos)
{
newPos=endPos;
if (_FsChanToMode(handle)&P_FUPDATE)
{
if ((ret=_iow3(handle,P_FSETEOF,&newPos))<0)
goto failed;
if ((ret=_iow4(handle,P_FSEEK,&mode,&newPos))<0)
{
failed:
_ioerr(ret);
return(-1);
}
}
}
return(newPos);
}
void gotoxy(int x, int y)
/*
Position the consol channel.
*/
{
UWORD mode;
P_POINT p;
p.x=x-1;
p.y=y-1;
mode=P_SCR_POSA;
_iow4(winHandle,P_FSET,&mode,&p);
}
int wherex(void)
/*
Return the X cursor position.
*/
{
P_RECTP rp;
_iow3(winHandle,P_FSENSE,&rp);
return(rp.p.x+1);
}
int wherey(void)
/*
Return the Y cursor position.
*/
{
P_RECTP rp;
_iow3(winHandle,P_FSENSE,&rp);
return(rp.p.y+1);
}
void clrscr(void)
/*
Clear the screen.
*/
{
UWORD mode;
P_RECTP rp;
_iow3(winHandle,P_FSENSE,&rp);
mode=P_SCR_CLR;
_iow4(winHandle,P_FSET,&mode,&rp.r);
gotoxy(1,1);
}
void cursoron(void)
/*
Switch the cursor on.
*/
{
UWORD mode,flag;
flag=TRUE;
mode=P_SCR_CURSOR;
_iow4(winHandle,P_FSET,&mode,&flag);
}
void cursoroff(void)
/*
Switch the cursor off.
*/
{
UWORD mode,flag;
flag=FALSE;
mode=P_SCR_CURSOR;
_iow4(winHandle,P_FSET,&mode,&flag);
}
void setwrap(int flag)
/*
Switch the wrap mode.
*/
{
UWORD mode;
flag=(flag ? 1 : 0);
mode=P_SCR_WLOCK;
_iow4(winHandle,P_FSET,&mode,&flag);
}
static void xLine(int flag)
/*
Insert or delete the line containg the cursor.
*/
{
UWORD mode;
P_RECTP rp;
_iow3(winHandle,P_FSENSE,&rp);
rp.r.tl.x=0;
rp.r.tl.y=rp.p.y;
rp.p.x=0;
rp.p.y=flag;
mode=P_SCR_SCROLL;
_iow4(winHandle,P_FSET,&mode,&rp);
}
void insline(void)
/*
Insert a line.
*/
{
xLine(1);
}
void delline(void)
/*
Delete a line.
*/
{
xLine(-1);
}
void clreol(void)
/*
Clear to the end of line.
*/
{
UWORD mode;
P_RECTP rp;
_iow3(winHandle,P_FSENSE,&rp);
rp.r.tl=rp.p;
rp.r.br.y=rp.p.y+1;
mode=P_SCR_CLR;
_iow4(winHandle,P_FSET,&mode,&rp.r);
}
+468
View File
@@ -0,0 +1,468 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* FSTREAM.CPP - 2.1 file stream class implementations. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#include <clib.h>
#include <fstream.hpp>
#pragma module(init_prio=>22)
_STATIC int get_mode(int h);
//**************************************************************************
// fstream implementation
//**************************************************************************
const int filebuf::openprot = S_IREAD|S_IWRITE;
filebuf::filebuf() {
xfd=EOF;
opened=0;
mode=0;
last_seek=0;
in_start=NULL;
setp(base(), ebuf());
setg(base(), ebuf(), ebuf());
}
filebuf::filebuf(int h) {
xfd=h;
if(h != -1) {
opened=1;
mode=get_mode(h);
}
else
opened=0;
last_seek=0;
in_start=NULL;
setp(base(), ebuf());
setg(base(), ebuf(), ebuf());
}
filebuf::filebuf(int h, char *s, int sz) : streambuf(s, sz) {
xfd=h;
if(h != -1) {
opened=1;
mode=get_mode(h);
}
else
opened=0;
last_seek=0;
in_start=NULL;
if(unbuffered()) {
setb(lahead, &lahead[1], 0);
setp(base(), base());
unbuffered(1);
}
else
setp(base(), ebuf());
setg(base(), ebuf(), ebuf());
}
filebuf::~filebuf() {
if(xfd != EOF)
close();
}
filebuf* filebuf::open(const char *path, int fmode, int permission)
{
unsigned om;
if(opened)
close();
if(fmode&ios::binary)
om=O_BINARY;
else
om=O_TEXT;
if((fmode&(ios::in|ios::out)) == (ios::in|ios::out))
om|=O_RDWR;
else if(fmode&ios::in)
om|=O_RDONLY;
else if(fmode&ios::out)
om|=O_WRONLY;
if(om&(O_WRONLY|O_RDWR))
{
if(fmode&ios::app)
om|=O_APPEND;
if(fmode&ios::trunc)
om|=O_TRUNC;
if(!(fmode&ios::nocreate))
om|=O_CREAT;
}
if((fmode&ios::noreplace) && (_exists(path)))
xfd=EOF;
else
xfd=::open(path, om, permission); // translate fmode
if(xfd != EOF)
{
opened=1;
mode =fmode;
if(fmode&(ios::ate|ios::app))
last_seek=lseek(xfd, 0L, SEEK_END);
else
last_seek=0;
return this;
}
else
{
opened=0;
return NULL;
}
}
filebuf* filebuf::close() {
if(opened) {
sync();
::close(xfd);
}
return this;
}
filebuf* filebuf::attach(int h) {
if(opened)
return 0;
xfd=h;
if(h != EOF) {
opened=1;
mode=get_mode(h);
}
else
opened=0;
return this;
}
_STATIC int get_mode(int h) {
int mode;
if(h >= _open_max)
return (ios::in|ios::out);
if(_openfd[h]&O_BINARY)
mode=ios::binary;
else
mode=0;
if(_openfd[h]&O_RDWR)
mode |= ios::in|ios::out;
else if(_openfd[h]&O_WRONLY)
mode |= ios::out;
else
mode |= ios::in;
if(_openfd[h]&O_APPEND)
mode |= ios::app;
return mode;
}
_STATIC int translate(char *buf, int num, int h) {
int ip, op, c;
ip=0;
op=0;
while(ip < num) {
c=buf[ip];
if(c != 0xD) {
buf[op++]=c;
}
++ip;
}
if((buf[ip-1] == 0xD) && (num > 1))
::lseek(h, -1L, SEEK_CUR);
return op;
}
_STATIC int real_off(char *buf, int num) {
int p, n;
p=0;
n=0;
if(num > 0) {
while(p < num) {
if(buf[p++] == 0xA)
n+=2;
else
++n;
}
return n;
}
while(p >= num) {
if(buf[--p] == 0xA)
n+=2;
else
++n;
}
return -n;
}
int filebuf::last_op() {
int ret;
if(pptr() > pbase())
ret= ios::out;
else if(in_start)
ret= ios::in;
else
ret = 0;
return ret;
}
int filebuf::overflow(int c) {
int nw;
if(unbuffered()) {
if((c == EOF) || (::write(xfd, &c, sizeof(char)) == -1))
return EOF;
nw=1;
}
else {
nw=pptr()-pbase();
if(nw) {
if(::write(xfd, pbase(), nw) == -1)
return EOF;
}
}
last_seek+=nw;
setp(pbase(), epptr());
if((c != EOF) && (!unbuffered()))
sputc(c);
return c;
}
int filebuf::underflow() {
int nr;
if(unbuffered())
in_start=eback();
else
in_start=eback()+4;
nr=ebuf()-in_start;
last_seek=tell(xfd);
if((nr=::_read(xfd, in_start, nr)) <= 0)
return EOF;
if(!(mode&ios::binary))
nr=translate(in_start, nr, xfd);
setg(eback(), in_start, in_start+nr);
return (unsigned char) *gptr();
}
int filebuf::sync() {
streampos pos;
int lo;
if(!opened)
return EOF;
lo=last_op();
if(lo == ios::out)
overflow();
else if(lo == ios::in) {
if(mode&ios::binary)
pos = gptr()-in_start + last_seek;
else
pos = real_off(in_start, gptr()-in_start) + last_seek;
last_seek = ::lseek(xfd, pos, SEEK_SET);
}
else
return 0;
setp(pbase(), epptr());
setg(base(), ebuf(), ebuf());
in_start=NULL;
return 0;
}
streampos filebuf::seekoff(streamoff off, ios::seek_dir d, int ) {
streampos p;
ios::seek_dir dir;
int lo;
if(opened) {
if((!unbuffered()) && (d == ios::cur)) {
lo=last_op();
if(lo == ios::out) {
if(mode&ios::binary)
p = pptr()-pbase();
else
p = real_off(pbase(), pptr()-pbase());
}
else if(lo == ios::in) {
if(mode&ios::binary)
p = gptr()-in_start;
else
p = real_off(eback(), gptr()-in_start);
}
else
p=0;
p += last_seek + off;
dir=ios::beg;
}
else {
p=off;
dir=d;
}
sync();
last_seek = ::lseek(xfd, p, dir);
setp(pbase(), epptr());
setg(base(), ebuf(), ebuf());
return last_seek;
}
return (streampos) -1;
}
streambuf* filebuf::setbuf(char *s, int sz) {
if(opened || (base() && (!unbuffered())))
return NULL;
setb(s, s+sz, 0);
if(s) {
setp(s, s+sz);
setg(s, s+sz, s+sz);
}
else {
setp(NULL, NULL);
setg(NULL, NULL, NULL);
}
return this;
}
//**************************************************************************//**************************************************************************
// fstreambase implementation
//**************************************************************************
fstreambase::fstreambase() {
}
fstreambase::fstreambase(int h) : buf(h) {
}
fstreambase::fstreambase(int h, char *s, int sz) : buf(h, s, sz) {
}
fstreambase::fstreambase(const char *path, int mode, int permission) {
buf.open(path, mode, permission);
if(!buf.is_open())
setstate(failbit);
}
fstreambase::~fstreambase() {
}
void fstreambase::open(const char *path, int mode, int permission) {
buf.open(path, mode, permission);
if(!buf.is_open())
state|=failbit;
}
void fstreambase::attach(int h) {
if(buf.attach(h) == NULL)
state|=failbit;
}
void fstreambase::close() {
buf.close();
}
void fstreambase::setbuf(char *b, int sz) {
buf.setbuf(b, sz);
}
//**************************************************************************//**************************************************************************
// ifstream implementation
//**************************************************************************
ifstream::ifstream() : istream(rdbuf()) {
}
ifstream::ifstream(const char* path, int mode, int prot) : istream(rdbuf()) {
if(rdbuf()->open(path, mode, prot) == NULL)
setstate(badbit);
}
ifstream::ifstream(int h) : istream(rdbuf()),
fstreambase(h) {
}
ifstream::ifstream(int h, char* b, int sz) : istream(rdbuf()),
fstreambase(h, b, sz) {
}
ifstream::~ifstream() {
}
ofstream::ofstream() : ostream(rdbuf()) {
}
ofstream::ofstream(const char* path, int mode, int prot) : ostream(rdbuf()) {
if(rdbuf()->open(path, mode, prot) == NULL)
setstate(badbit);
}
ofstream::ofstream(int h) : ostream(rdbuf()),
fstreambase(h) {
}
ofstream::ofstream(int h, char* b, int sz) : ostream(rdbuf()),
fstreambase(h, b, sz) {
}
ofstream::~ofstream() {
}
fstream::fstream() : iostream(rdbuf()) {
}
fstream::fstream(const char* path, int mode, int prot) : iostream(rdbuf()) {
if(rdbuf()->open(path, mode, prot) == NULL)
setstate(badbit);
}
fstream::fstream(int h) : iostream(rdbuf()),
fstreambase(h) {
}
fstream::fstream(int h, char* b, int sz) : iostream(rdbuf()),
fstreambase(h, b, sz) {
}
fstream::~fstream() {
}

+9
View File
@@ -0,0 +1,9 @@
(* 8K Epoc C header for use with CLIB *)
(* Release 1.00F NSM *)
(* Copyright (C) Psion PLC 1991 *)
StackSize = 2000H
include "iclib.inc"
+103
View File
@@ -0,0 +1,103 @@
(* Epoc C header for use with CLIB include file *)
(* Release 1.00F NSM *)
(* Copyright (C) Psion PLC 1991 *)
include "epocdefs.inc"
module iclib
section
segment _TEXT(CODE,68H)
segment STACK(STACK,74H)
public __stack_start:
segment _MAGIC(MAGIC,68H)
public _DatWordDead: dw 0
public _DatHandNext: dw 0
public _DatHandPrev: dw 0
public _DatCountrySeg: dw 0
public _DatClassHandle: dw 0
public _DatClassPtr: dw 0
public _DatEClassHandle: dw 0
public _DatEClassPtr: dw 0
public _DatEnterFramePtr: dw 0
public _w_ws: dw 0
public _w_am: dw 0
public _wClientData: dw 0
public _wserv_channel: dw 0
public _T: dw 0
public _r: dw 0
public _DatOsFramePtr: dw 0
public _DatATFlag: db 0
public _DatHeapLocked: db 0
public _DatProcessNamePtr: dw 0
public _DatCommandPtr: dw 0
public _DatTest: dw 0
public _DatApp1: dw 0
public _DatApp2: dw 0
public _DatApp3: dw 0
public _DatApp4: dw 0
public _DatApp5: dw 0
public _DatApp6: dw 0
public _DatApp7: dw 0
public _DatDialogPtr: dw 0
public _DatGate: dw 0
public _DatLocked: dw 0
public _DatStatusNamePtr: dw 0
public _DatUsedPathNamePtr: dw 0
org StackSize-40H
segment _INIT(DATA,48H)
public __init_start:
segment _CONST(DATA,48H)
public __const_start:
dw 0
segment _DATA(DATA,68H)
public __data_start:
segment _BSS(BSS,68H)
public __bss_start:
segment _BSS_END(BSS,68H)
public __bss_end:
group DGROUP(_MAGIC,_INIT,_CONST,_DATA,_BSS,_BSS_END)
select _TEXT
extrn __startup
extrn _exit
extrn _ExtCatTable
extrn _ClassTable
public __begin :
call __startup
ret far 0
dw __bss_start
dw _ExtCatTable
dw _ClassTable
dw _DatWordDead
dw __bss_end
public _p_leave:
int LibLeave
int LibSendExit
dw __init_start
dw __const_start
public _p_exit:
mov ax, bx
jmp _exit
public _p_abort:
mov ax, FailedToStartErr
jmp _exit
end *
+8
View File
@@ -0,0 +1,8 @@
(* 2K stack Epoc C header for use with CLIB *)
(* Release 1.00F NSM *)
(* Copyright (C) Psion PLC 1991 *)
StackSize = 800H
include "iclib.inc"
+8
View File
@@ -0,0 +1,8 @@
(* 4K stack Epoc C header for use with CLIB *)
(* Release 1.00F NSM *)
(* Copyright (C) Psion PLC 1991 *)
StackSize = 1000H
include "iclib.inc"
+9
View File
@@ -0,0 +1,9 @@
copy iclib*.obj ..\lib
copy iplib*.obj ..\lib
copy icat.obj ..\lib
copy r_emul.obj ..\lib
copy nofloat.obj ..\lib
copy rlib.lib ..\lib
copy clib.lib ..\lib
copy sys$8087.ldd ..\lib
+332
View File
@@ -0,0 +1,332 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* IOINLINE.CPP - 2.0 stream class small inline implementations. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#undef _SMALL_INLINE
#include <clib.h>
#include <iostream.hpp>
streambuf* ios::rdbuf() {
return _bp;
}
ostream* ios::tie() {
return x_tie;
}
char ios::fill() {
return x_fill;
}
int ios::precision() {
return x_precision;
}
int ios::rdstate() {
return state;
}
int ios::eof() {
return (state&eofbit);
}
int ios::fail() {
return (state&(failbit|badbit|hardfail));
}
int ios::bad() {
return (state&(badbit|hardfail));
}
int ios::good() {
return (state == 0);
}
long ios::flags() {
return x_flags;
}
int ios::width() {
return x_width;
}
int ios::width(int _w) {
int _temp = x_width;
x_width = _w;
return _temp;
}
char ios::fill(char _w) {
char _temp = x_fill;
x_fill = _w;
return _temp;
}
int ios::precision(int _w) {
int _temp = x_precision;
x_precision = _w;
return _temp;
}
ios::operator void* () {
return (fail()|eof()) ? 0 : this;
}
ios::operator! () {
return (fail()|eof());
}
char * streambuf::base() {
return _base;
}
char * streambuf::pbase() {
return _pbase;
}
char * streambuf::pptr() {
return _pptr;
}
char * streambuf::epptr() {
return _epptr;
}
char * streambuf::gptr() {
return _gptr;
}
char * streambuf::egptr() {
return _egptr;
}
char * streambuf::eback() {
return _eback;
}
char * streambuf::ebuf() {
return _ebuf;
}
int streambuf::unbuffered() {
return _unbuf;
}
int streambuf::blen() {
return (int) (_ebuf - _base);
}
void streambuf::pbump(int _n) {
_pptr += _n;
}
void streambuf::gbump(int _n) {
_gptr += _n;
}
void streambuf::unbuffered(int _ub) {
_unbuf = (_ub != 0);
}
int streambuf::in_avail() {
return (_egptr > _gptr) ? (int)(_egptr - _gptr): 0;
}
int streambuf::out_waiting() {
return _pptr ? (int)(_pptr - _pbase): 0;
}
int streambuf::allocate() {
return((_base || _unbuf) ? 0 : doallocate());
}
int streambuf::sgetc() {
return ((_gptr >= _egptr) ? underflow() : (unsigned char) *_gptr);
}
int streambuf::snextc() {
return ((++_gptr >= _egptr) ? do_snextc() : (unsigned char) *_gptr);
}
int streambuf::sbumpc() {
return ((_gptr >= _egptr) && (underflow() == EOF) ? EOF : (unsigned char) *_gptr++);
}
void streambuf::stossc() {
if (_gptr >= _egptr)
underflow();
else
++_gptr;
}
int streambuf::sputbackc(char _c) {
return (_gptr > _eback) ? *--_gptr = _c : pbackfail(_c) ;
}
int streambuf::sputc(int _c) {
return (_pptr >= _epptr) ? overflow(_c) : (*_pptr++=_c);
}
int istream::gcount() {
return _gcount;
}
int istream::ipfx(int _need) {
if( _need ? (ispecial&~skipping) : ispecial)
return do_ipfx(_need);
return 1;
}
int istream::ipfx0() {
return ispecial ? do_ipfx(0) : 1;
}
int istream::ipfx1() {
return (ispecial&~skipping) ? do_ipfx(1) : 1;
}
istream& istream::operator>>(unsigned char& _c) {
if(ipfx0()) {
if(_bp->in_avail())
_c = _bp->sbumpc();
else
_c = do_get();
}
return *this;
}
istream& istream::operator>>(signed char& _c) {
if(ipfx0()) {
if(_bp->in_avail())
_c = _bp->sbumpc();
else
_c = do_get();
}
return *this;
}
istream& istream::operator>>(char& _c) {
if(ipfx0()) {
if(_bp->in_avail())
_c = _bp->sbumpc();
else
_c = do_get();
}
return *this;
}
istream& istream::operator>>(unsigned char* _s) {
return *this>>(signed char *) _s;
}
istream& istream::operator>>(char* _s) {
return *this>>(signed char *) _s;
}
istream& istream::get(unsigned char* _s, int _l, char _t) {
return get((signed char *)_s, _l, _t);
}
istream& istream::get(char* _s, int _l, char _t) {
return get((signed char *)_s, _l, _t);
}
istream& istream::read(unsigned char* _s, int _l) {
return read((signed char *)_s, _l);
}
istream& istream::read(char* _s, int _l) {
return read((signed char *)_s, _l);
}
istream& istream::getline(unsigned char* _s, int _l, char _t) {
return getline((signed char *)_s, _l, _t);
}
istream& istream::getline(char* _s, int _l, char _t) {
return getline((signed char *)_s, _l, _t);
}
int istream::sync() {
return _bp->sync();
}
istream& istream::operator>> (istream& (*_f)(istream&)) {
return (*_f)(*this);
}
int istream::peek() {
return ipfx1() ? _bp->sgetc() : EOF;
}
int ostream::opfx() {
return ospecial ? do_opfx() : 1;
}
void ostream::osfx() {
if((x_flags&(stdio|unitbuf)) || (ospecial)) do_osfx();
}
ostream& ostream::operator<<(unsigned char _c) {
return *this <<(signed char ) _c;
}
ostream& ostream::operator<<(char _c) {
return *this <<(signed char ) _c;
}
ostream& ostream::operator<<(short _i) {
return *this<<(long)_i;
}
ostream& ostream::operator<<(unsigned short _i) {
return *this<<(unsigned long)_i;
}
ostream& ostream::operator<<(int _i) {
return *this<<(long)_i;
}
ostream& ostream::operator<<(unsigned int _i) {
return *this<<(unsigned long)_i;
}
ostream& ostream::operator<<(float _f) {
return *this<<(long double)_f;
}
ostream& ostream::operator<<(double _f) {
return *this<<(long double)_f;
}
ostream& ostream::operator<<(ostream& (*_f)(ostream&)) {
return (*_f)(*this);
}
ostream& ostream::write(const signed char *_s, int _n) {
return write((const char *)_s, _n);
}
ostream& ostream::write(const unsigned char *_s, int _n) {
return write((const char *)_s, _n);
}
ostream& ostream::put(char _c) {
if(_bp->sputc(_c) == EOF)
setstate(badbit);
return *this;
}
ostream& ostream::operator<<(const signed char *_s) {
return *this<<(const char *) _s;
}
ostream& ostream::operator<<(const unsigned char *_s) {
return *this<<(const char *) _s;
}

File diff suppressed because it is too large Load Diff
+9
View File
@@ -0,0 +1,9 @@
(* 4K Epoc C header for use with PLIB *)
(* Release 1.00F NSM *)
(* Copyright (C) Psion PLC 1991 *)
StackSize = 1000H
include "iplib.inc"
+233
View File
@@ -0,0 +1,233 @@
(* Epoc C header for use with PLIB include file *)
(* Release 1.10F NSM *)
(* Copyright (C) Psion PLC 1991-93 *)
include "epocdefs.inc"
Priority = 2
ProcVar = 3
InitSize = 5
PRMAX = 32
module iplib
section
segment _TEXT(CODE,68H)
segment STACK(STACK,74H)
public __stack_start:
segment _MAGIC(MAGIC,68H)
public _DatWordDead: dw 0
public _DatHandNext: dw 0
public _DatHandPrev: dw 0
public _DatCountrySeg: dw 0
public _DatClassHandle: dw 0
public _DatClassPtr: dw 0
public _DatEClassHandle: dw 0
public _DatEClassPtr: dw 0
public _DatEnterFramePtr: dw 0
public _w_ws: dw 0
public _w_am: dw 0
public _wClientData: dw 0
public _wserv_channel: dw 0
public _T: dw 0
public _r: dw 0
public _DatOsFramePtr: dw 0
public _DatATFlag: db 0
public _DatHeapLocked: db 0
public _DatProcessNamePtr: dw 0
public _DatCommandPtr: dw 0
public _DatTest: dw 0
public _DatApp1: dw 0
public _DatApp2: dw 0
public _DatApp3: dw 0
public _DatApp4: dw 0
public _DatApp5: dw 0
public _DatApp6: dw 0
public _DatApp7: dw 0
public _DatDialogPtr: dw 0
public _DatGate: dw 0
public _DatLocked: dw 0
public _DatStatusNamePtr: dw 0
public _DatUsedPathNamePtr: dw 0
org StackSize-40H
segment _INIT(DATA,48H)
public __init_begin:
dw 0
public __init_start:
segment _CONST(DATA,48H)
public __const_start:
dw 0
segment _DATA(DATA,68H)
public __data_start:
public CoreSig@CnsHandler : dw 0
segment _BSS(BSS,68H)
public __bss_start:
public __SH_sword:
org 2
segment BSS_END(BSS,68H)
public __bss_end:
select _DATA
extrn @InitPointer
extrn @InitPriority
select _BSS
extrn @InitCount
extrn @InitEnd
extrn @InitDone
extrn @ExitCode
extrn @StackContextSP
extrn @StackContextBP
group DGROUP(_MAGIC,_INIT,_CONST,_DATA,_BSS,BSS_END)
select _TEXT
public __init0:
extrn _main
extrn __FloatInit
extrn __FloatFinish
extrn __FloatMathExcepDos
extrn __FatalErrorPos
extrn __FatalError
extrn _ClassTable
extrn _ExtCatTable
extrn __InitSetup
extrn __InitLoop
call __begin
ret far 0
dw __bss_start
dw _ExtCatTable
dw _ClassTable
dw _DatWordDead
dw __bss_end
public _p_leave:
int LibLeave
int LibSendExit
dw __init_start
dw __const_start
public __begin:
sub al, al
mov ah, NmFilConnect
int FilManager
jc _p_abort
call __FloatInit
call __InitSetup
call __InitLoop
doExit:
call __FloatFinish
mov ah, NmProcId
int ProcManager
mov bx, ax
mov ax, [@ExitCode]
mov ah, NmProcKill
int ProcManager
public _p_abort:
mov al, FailedToStartErr
mov [@ExitCode], ax
jmp doExit
public __fp_0:
ret 0
public __fp_1:
ret 0
public __sigFp:
jmp __FloatMathExcepDos
public __math_excep:
call __FatalErrorPos
mov bx, FatalMathException
jmp __FatalError
public __InitSetup :
mov ax, __const_start
sub ax, __init_start
mov bl, InitSize
div bl
sub ah, ah
mov [@InitCount], ax
mul bl
add ax, __init_start
mov [@InitEnd], ax
and word [@InitDone], 0
ret 0
public __InitLoop :
push di
push si
mov bx, [@InitPointer]
jmp traverseLoop
nextLoop:
add bx, InitSize
chainLoop:
traverseLoop:
cmp bx, [@InitEnd]
jae endOfArray
mov al, [@InitPriority]
cmp al, [bx][Priority]
jne nextLoop
lea ax, [bx][InitSize]
mov [@InitPointer], ax
dec word [@InitCount]
call [bx][ProcVar]
mov bx, [@InitPointer]
cmp word [@InitDone], 0
je traverseLoop
initLoopRet:
pop si
pop di
ret 0
endOfArray:
cmp word [@InitCount], 0
je stageComplete
endOfList:
dec byte [@InitPriority]
js stageComplete
mov bx, __init_start
jmp chainLoop
stageComplete:
inc word [@InitDone]
mov [@StackContextBP], bp
mov [@StackContextSP], sp
call _main
mov [@ExitCode], ax
jmp initLoopRet
public _p_exit:
mov sp, [@StackContextSP]
mov bp, [@StackContextBP]
mov [@ExitCode], bx
jmp initLoopRet
select _DATA
public @InitPointer : dw __init_start
public @InitPriority : db PRMAX
select _BSS
public @InitCount : org 2
public @InitEnd : org 2
public @InitDone : org 2
public @ExitCode : org 2
public @StackContextSP : org 2
public @StackContextBP : org 2
end *
+9
View File
@@ -0,0 +1,9 @@
(* 2K Epoc C header for use with PLIB *)
(* Release 1.00F NSM *)
(* Copyright (C) Psion PLC 1991 *)
StackSize = 800H
include "iplib.inc"
+9
View File
@@ -0,0 +1,9 @@
(* 8K Epoc C header for use with PLIB *)
(* Release 1.00F NSM *)
(* Copyright (C) Psion PLC 1991 *)
StackSize = 2000H
include "iplib.inc"
+90
View File
@@ -0,0 +1,90 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* NEW.CPP - new implementations. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#include <clib.h>
#include <p_std.h>
#pragma module(init_prio=>22)
_STATIC void (*new_handler)(void);
#pragma save, call(reg_return=>(ax,bx))
void* operator new(unsigned size) {
void *b;
b=p_alloc(size);
if((b == NULL) && (new_handler) && (size))
new_handler();
return b;
}
#pragma restore
void* operator new(unsigned, void *place) {
return place;
}
void operator delete(void *p) {
p_free(p);
}
void (* set_new_handler(void(*nh)()))() {
void (* ret)();
ret=new_handler;
new_handler=nh;
return ret;
}
extern "C" void * _vec_new( char * obj_ptr, unsigned n, unsigned siz, ctor_t ctor, unsigned vbnum) {
unsigned *h;
if (! obj_ptr) {
h=(unsigned *)p_alloc(n * siz + sizeof(unsigned));
if(h == NULL) {
if(new_handler)
new_handler();
return NULL;
}
*h=n;
obj_ptr= (char *)(h + 1);
}
if (ctor)
_call_ctors(ctor, (char *) obj_ptr, vbnum, n, siz);
return obj_ptr;
}
extern "C" void _vec_delete( char * obj_ptr, unsigned siz, dtor_t dtor, unsigned _free, unsigned vbnum, unsigned static_num)
{
unsigned n;
unsigned *tmp;
if (obj_ptr)
{
tmp = (unsigned *)obj_ptr-1;
if(dtor)
{
if(_free)
n=*tmp;
else
n=static_num;
obj_ptr+=n*siz;
_call_dtors(dtor,obj_ptr,vbnum,n,siz);
}
if(_free)
p_free(tmp);
}
}
+33
View File
@@ -0,0 +1,33 @@
(* Release 3.00 *)
module nofloat
public FIDRQQ (* wait, esc*) = 0
public FIARQQ (* wait, ds:*) = 0
public FICRQQ (* wait, cs:*) = 0
public FIERQQ (* wait, es:*) = 0
public FISRQQ (* wait, ss:*) = 0
public FIWRQQ (* nop, wait*) = 0
public FJARQQ (* Esc nn -> ds:nn*) = 0
public FJCRQQ (* Esc nn -> cs:nn*) = 0
public FJSRQQ (* Esc nn -> es:nn*) = 0
public FJERQQ (* ???????????????*) = 0
public FIXRQQ = 0 (* brings this module in - known to linker *)
segment _TEXT(CODE,28H)
extrn __fp_0
public __FloatInit :
jmp __fp_0
public __FloatFinish:
public __FloatInitInstance:
public __FloatJmpSave :
public __FloatJmpRestore :
public __FloatMathExcepDos :
ret 0
end
+923
View File
@@ -0,0 +1,923 @@
/* Release 3.00 */
/*-------------------------------------------------------------------------*
* *
* printf.c - formatted output module *
* *
* COPYRIGHT (C) 1989 Jensen and Partners. All Rights Reserved *
* Written by Simon Knight. *
* *
* COPYRIGHT (C) 1991 Psion PLC. All Rights Reserved *
* Modified by NSM. *
* *
*--------------------------------------------------------------------------*/
#define _USE_CONIO
#include <clib.h>
#define _VPUTC(c) _vputc(c)
_STATIC int _insert_str(char *s, char c, int num);
_STATIC int _con_flush(FILE *st);
_STATIC int _buf_flush(FILE *st);
enum modifier { none, /* modifier prefixes */
shortmod, /* short integer */
longmod, /* long integer */
ldmod }; /* LONGDOUBLE - syntax only */
_STATIC void _vprinter(const char *format, va_list _v_argptr)
{
int n, p, c;
int np;
int pad;
int radix;
int pretemp;
int width, precision;
enum modifier mod; /* modifier type */
int genflag;
long target;
char *in_str;
char _fmt_buf[64], *plist;
n=0;
_vp_ret=0;
while((c=format[n++]) !=0) /* main loop to scan format string */
{
switch(c)
{
case '%':
goto arg_eval; /* scan format spec */
arg_eval_ret:
#pragma warn(wubd => off)
n+=p;
#pragma warn(wubd => on)
break;
default: /* output character */
_VPUTC(c);
break;
}
}
return;
arg_eval:
/* evaluate and output argument */
plist=(char *) &format[n];
p=0; /* set local format subscript */
_upperHex='a'; /* default PF_HEX digit case */
genflag=0; /* all flags to default */
/***************************************************************************
* This paragraph reads any flags from the format string. The optimal *
* path is for no flags. Multiple flags are permitted. *
***************************************************************************/
c=plist[p++];
if(c == '%')
{
_VPUTC(c);
goto arg_eval_ret;
}
while(c != 0)
{
switch(c)
{
case '-':
genflag|=PF_LEFT;
goto cont;
case '+':
genflag|=PF_SIGN;
goto cont;
case '\ ':
genflag|=PF_SPACE;
goto cont;
case '#':
genflag|=PF_HASH;
goto cont;
case '0':
genflag|=PF_ZFLAG;
goto cont;
default:
goto noflag;
}
cont:
c=plist[p++];
}
noflag:
if((genflag&PF_ZFLAG) && (genflag&PF_LEFT))
genflag&=(~PF_ZFLAG);
if((genflag&PF_SIGN) && (genflag&PF_SPACE))
genflag&=(~PF_SPACE);
/***************************************************************************
* The next paragraph evaluates any width parameter if present. There is *
* no limit on field width apart from integer range. *
***************************************************************************/
width=0;
while (isdigit(c))
{
width *= 10;
width += c- 0x30;
c=plist[p++];
}
if(c == '*') /* _width is argument */
{
width = va_arg(_v_argptr, int);
if(width < 0)
{
width*= -1;
genflag|=PF_LEFT;
genflag&=(~PF_ZFLAG);
}
c=plist[p++];
}
/***************************************************************************
* The next paragraph evaluates any precision parameter if present. *
* Default precisions are set by the data type functions. PF_NOPOINT *
* if precision implicitly set to 0. Maximum precison is 32 digits. *
***************************************************************************/
precision=0;
pretemp=0;
if(c == '.')
{
while(isdigit(c=plist[p++]))
{
pretemp *= 10;
pretemp += c - 0x30;
}
if(c == '*') /* precision is argument */
{
pretemp = va_arg(_v_argptr, int);
c=plist[p++];
}
if(pretemp >= 0)
{
if(pretemp == 0) /* precision explicitly zero */
genflag|=PF_NOPOINT;
else
{
precision=pretemp; /* precision non zero */
if(precision > 32)
precision = 32;
}
genflag|=PF_PSET;
}
}
/***************************************************************************
* The next paragraph evaluates any type modifiers present. The optimal *
* path is for no modifiers *
***************************************************************************/
switch(c)
{
case 0 : /* incomplete spec - return for */
case '\ ': /* literal output */
_VPUTC('%');
p=0;
goto arg_eval_ret;
case 'h':
mod=shortmod; /* short integer */
goto modcont;
case 'l':
mod=longmod; /* long integer */
goto modcont;
case 'L':
mod=ldmod; /* LONGDOUBLE ( no semantics) */
goto modcont;
default:
mod=none;
break;
modcont:
c=plist[p++];
break;
}
/***************************************************************************
* The next paragraph is the main switch for data types. Arguments are *
* fetched and evaluated by the appropriate conversion function with the *
* result in a buffer. The address of this buffer is passed to the *
* appropriate output section - _int_out, _real_out or _str_out. *
***************************************************************************/
switch(c)
{
case 'i': /* integer types */
case 'd':
genflag|=PF_IS_SIGNED;
radix=10;
switch(mod)
{
case longmod:
target=va_arg(_v_argptr, long);
break;
case shortmod:
target= (long) va_arg(_v_argptr, short);
break;
default:
target= (long) va_arg(_v_argptr, int);
break;
}
goto int_out;
case 'u': /* unsigned */
radix=10;
goto get_uns;
case 'o': /* octal */
genflag|=PF_OCT;
radix=8;
goto get_uns;
do_nptr:
case 'X': /* PF_HEX */
genflag|=PF_UPPER;
_upperHex= 'A';
case 'x':
genflag|=PF_HEX;
radix=16;
get_uns:
switch(mod)
{
case longmod:
target=va_arg(_v_argptr, long);
break;
case shortmod:
target= (long) (unsigned) va_arg(_v_argptr, short);
break;
default:
target= (long) (unsigned) va_arg(_v_argptr, int);
break;
}
goto int_out;
int_ret:
break;
case 'E': /* reals */
genflag|=PF_UPPER; /* exponent form */
case 'e':
genflag|=PF_EXP;
case 'f':
goto do_real;
case 'G':
genflag|=PF_UPPER;
case 'g':
genflag|=PF_GTYPE;
do_real:
if(mod == ldmod)
genflag |= PF_LDMOD;
if((precision == 0) && ((genflag&PF_NOPOINT)==0))
precision=6;
_v_argptr=_real_out(_v_argptr, genflag, width, precision);
break;
case 'c': /* character */
if(!(genflag&PF_LEFT))
{
while(width > 1)
{
_VPUTC(' ');
--width;
}
}
_VPUTC(va_arg(_v_argptr, int));
while(width > 1)
{
_VPUTC(' ');
--width;
}
goto arg_eval_ret;
case 's':
genflag&= ~PF_ZFLAG;
precision=pretemp;
in_str= (char *)(va_arg(_v_argptr, char *));
if(in_str)
_str_out(in_str, genflag, width, precision);
break;
case 'n':
switch(mod)
{
case longmod:
*(va_arg(_v_argptr, long *)) = _vp_ret;
break;
default :
*(va_arg(_v_argptr, int *)) = _vp_ret;
break;
}
goto arg_eval_ret;
case 'p': /* pointer */
precision=4;
mod=none;
goto do_nptr;
default: /* invalid type - return for literal output */
_VPUTC('%');
p=0;
goto arg_eval_ret;
}
goto arg_eval_ret;
/***************************************************************************
* This paragraph handles precision and format for the integer value *
* now in the form of an ASCIIZ string. *
***************************************************************************/
int_out:
np=50;
if(genflag&PF_IS_SIGNED)
ltoa(target, &_fmt_buf[50], radix);
else
ultoa(target, &_fmt_buf[50], radix);
if(precision == 0) /* set default precision */
{
if((target == 0) && (genflag&PF_NOPOINT)) {
np=0;
if((genflag&PF_SPACE) && ((genflag&PF_IS_SIGNED)))
_fmt_buf[np++]='\ ';
_fmt_buf[np]='\0';
_justify(_fmt_buf, genflag, width); /* and ouput */
goto int_ret;
}
precision = 1;
}
if((genflag&PF_ZFLAG) && (!(genflag&PF_PSET)))
{
precision=width;
width=0;
if(((target < 0) || (genflag&PF_SIGN)) && (precision > 0))
--precision;
}
genflag&= ~PF_ZFLAG;
if((target < 0) && (genflag&PF_IS_SIGNED))
np++;
pad = precision - strlen(&_fmt_buf[np]); /* pad with '0' to precision */
while(pad > 0)
{
_fmt_buf[--np]='0';
pad--;
}
if(genflag&(PF_HEX|PF_OCT)) /* PF_HEX and octal prefix */
{
if((genflag&PF_HASH) && (target))
{
if(genflag&PF_HEX)
{
if(genflag&PF_UPPER)
_fmt_buf[--np]='X';
else
_fmt_buf[--np]='x';
}
_fmt_buf[--np]= '0';
}
}
if(genflag&PF_IS_SIGNED)
{ /* set +/- */
if(target >= 0)
{
if(genflag&PF_SIGN) /* leading + required */
_fmt_buf[--np]= '+';
else if(genflag&PF_SPACE) /* leading PF_SPACE required */
_fmt_buf[--np]= ' ';
}
else
_fmt_buf[--np]='-'; /* copy existing PF_SIGN */
}
_justify(&_fmt_buf[np], genflag, width); /* and ouput */
goto int_ret;
} /* end of vprinter */
/***************************************************************************
* This next paragraph handles precision and format for the real value *
* now in the form of an ASCCIZ string. *
***************************************************************************/
va_list _rreal_out(va_list _v_argptr, int flag, int wid, int prec)
{
char _fmt_buf[64];
LONGDOUBLE ld;
if(flag&PF_LDMOD)
ld=va_arg(_v_argptr, LONGDOUBLE);
else
ld=(LONGDOUBLE) va_arg(_v_argptr, double);
_f_fmt(_fmt_buf, ld, flag, prec);
_justify(_fmt_buf, flag, wid);
return(_v_argptr);
}
_STATIC int _insert_str(char *s, char c, int num)
{ /* insert characters into string */
movmem(s, s+num, strlen(s)+1);
setmem(s, num, c);
return(num);
}
/***************************************************************************
* This next function handles far pointer arguments. *
***************************************************************************/
char *_fptoa(unsigned long ptr, char *s)
{
int pad;
unsigned off;
_upperHex='A';
ultoa(ptr>>16, s, 16);
s[4]=0;
pad=4-strlen(s);
if(pad > 0)
_insert_str(s, '0', pad);
s[4]=':';
off=(unsigned) ptr;
ultoa((unsigned long) off, &s[5], 16);
pad=4-strlen(&s[5]);
s[9]=0;
if(pad > 0)
_insert_str(&s[5], '0', pad);
_upperHex='a';
return(s);
}
char *_f_fmt(char *_fmt_buf, LONGDOUBLE num, int flag, int prec)
{
int np, nq;
char extemp[18], out_str[64];
int dec, csign;
int fd;
int r, t;
int round, noround, tzeros;
np=0;
nq=0;
_cvt( num, 18, &dec, &csign, out_str);
if(abs(dec) > 30) /* default to exponential form */
flag|=PF_EXP;
if(csign) /* set PF_SIGN */
_fmt_buf[np++]='-';
else if(flag&PF_SIGN)
_fmt_buf[np++]= '+'; /* leading + */
else if(flag&PF_SPACE)
_fmt_buf[np++]= ' '; /* leading space */
if(flag&PF_HASH)
flag&=~PF_NOPOINT; /* force decimal point */
fd=np;
/***************************************************************************
* This paragraph evaluates whether the exponential form is required and *
* copies the first digit of the mantissa and inserts the decimal point *
* If the exponent form is not being used, the position of the decimal *
* point is calulated and 0s are inserted if necessary. *
***************************************************************************/
if( ((flag&PF_GTYPE) && ((dec > (prec)) || (dec < -4))) || (flag&PF_EXP))
{
flag|=PF_EXP; /* get first digit and decimal point */
_fmt_buf[np++]=out_str[nq++];
if(flag&PF_GTYPE)
--prec;
if(!(flag&PF_NOPOINT))
_fmt_buf[np++]=DEC_POINT;
}
else
{
flag&=~PF_EXP;
if(dec <= 0) /* if negative exponent pad */
{
_fmt_buf[np++]='0';
if(!(flag&PF_NOPOINT))
{
r=dec;
_fmt_buf[np++]=DEC_POINT;
while(r++ < 0)
{
if(--prec < 0) {
nq=-1; /* dont round */
break;
}
_fmt_buf[np++]='0';
}
}
else
nq=-1;
}
else /* positive exponent */
{
r=dec;
while(r-- > 0)
{
t=out_str[nq++];
if(nq > 17)
t='0';
_fmt_buf[np++]= (char) t;
if(flag&PF_GTYPE)
{
if(prec-- == 0)
break;
}
}
if(!(flag&PF_NOPOINT))
_fmt_buf[np++]=DEC_POINT;
}
}
/***************************************************************************
* This paragraph copies the digits to the right of the decimal point *
* to the limit of precison, padding with 0s if necessary. *
***************************************************************************/
noround=FALSE;
tzeros=FALSE;
if(!(flag&PF_NOPOINT)) /* copy digits to precision */
{
tzeros=TRUE;
while(prec > 0)
{
if(nq > 17)
{
noround=TRUE;
break;
}
_fmt_buf[np++]=out_str[nq++];
prec--;
}
if (prec > 0)
{ /* pad to precision if necessary */
noround=TRUE;
if((!(flag&PF_GTYPE)) || (flag&PF_HASH))
{
while(prec-- > 0)
{
_fmt_buf[np++]='0';
}
}
}
}
_fmt_buf[np]=0;
/***************************************************************************
* This paragraph rounds the copied number if any digits remain unused. *
***************************************************************************/
if(nq != -1) {
round=out_str[nq];
if((!noround) && (isdigit(round))) /* round if any digits remain */
{
r=np-1;
if(round >= '5')
{
while(r >= fd-1)
{
if(_fmt_buf[r] == DEC_POINT) /* skip decimal point */
r--;
if(++_fmt_buf[r] > '9')
_fmt_buf[r--]='0';
else
break; /* no carry */
if(r < fd)
{
if(flag&PF_EXP) /* handle high order carry */
{
_fmt_buf[r+1]='1';
++dec;
}
else
{
_insert_str(&_fmt_buf[fd], '1', 1);
np++;
}
break;
}
}
}
}
}
if((tzeros) && (flag&(PF_GTYPE|PF_CPP)) && (!(flag&PF_HASH)))
{
while(_fmt_buf[--np] == '0')
{
_fmt_buf[np]=0;
}
++np;
}
/***************************************************************************
* If required, this paragraph converts the exponent to ASCII string and *
* copies it to the target buffer. *
***************************************************************************/
if((_fmt_buf[np-1] == DEC_POINT) && (!(flag&PF_HASH)))
--np;
if((flag&PF_EXP) && ((dec != 1) || (!(flag&PF_GTYPE))))
{
if(flag&PF_UPPER)
_fmt_buf[np++]='E';
else
_fmt_buf[np++]='e';
if(--dec < 0)
{
_fmt_buf[np++]='-';
dec=abs(dec);
}
else
_fmt_buf[np++]='+';
itoa(dec, extemp, 10);
t=strlen(extemp);
r=2-t;
if(r < 0 )
r=0;
while(r--)
{ /* insert leading 0s */
_fmt_buf[np++]='0';
}
r=0;
while(r < t)
{
_fmt_buf[np++]=extemp[r++];
}
}
/***************************************************************************
* This paragraph terminates the string and calls the function which *
* justifies the number within its field width and outputs it. *
***************************************************************************/
_fmt_buf[np]=0;
return(_fmt_buf);
}
void _vp_setbuf(FILE *st, char *buffer)
{
st->_base=buffer;
st->_ptr=buffer;
st->_size=PF_TEMP_BUF;
st->_cnt=PF_TEMP_BUF;
st->_flag|=_F_UBUF;
st->_flag&=(~_F_RST);
return;
}
void _vp_freebuf(FILE *st)
{
st->_size=0;
st->_cnt=0;
st->_flag&=(~_F_UBUF);
return;
}
/*-------------------------------------------------------------------------*
* printf.c - formatted output to stdout *
* This function provides formatted output to stdout for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int printf(const char *format, ...)
{
va_list _v_argptr;
int temp_buf, ret;
temp_buf=0;
if(stdout->_size == 0)
{
char buffer[PF_TEMP_BUF];
stdout->_flag|=_F_RST;
_vp_setbuf(stdout, buffer);
temp_buf=1;
}
_vp_flush=_flusher; /* set output flusher */
_stream=stdout;
va_start(_v_argptr, format); /* initialise argument pointer */
_vprinter(format, _v_argptr); /* do it */
if(temp_buf)
{
_flusher(stdout);
stdout->_flag|=_F_RST;
_vp_freebuf(stdout);
}
else if(stdout->_flag&_F_DEV)
_flusher(stdout);
ret=_vp_ret;
return(ret); /* return number of characters output */
}
/*-------------------------------------------------------------------------*
* cprintf.c - formatted output to console *
* This function provides formatted output to console for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int _con_flush(FILE *st)
{
int n, num;
char *buf;
n=0;
buf=st->_base;
num=st->_cnt;
if(num < 0)
num=0;
num=st->_size-num;
while(num-- > 0)
{
putch(buf[n++]);
}
st->_cnt=st->_size;
st->_ptr=st->_base;
return(0);
}
int cprintf(const char *format, ...)
{
va_list _v_argptr;
FILE cst;
char cbuf[PF_VBSIZE];
int ret;
_vp_flush=_con_flush; /* set output function */
cst._cnt=PF_VBSIZE;
cst._size=PF_VBSIZE;
cst._base=cbuf;
cst._ptr=cbuf;
_stream=&cst;
va_start(_v_argptr, format); /* initialise argument pointer */
_vprinter(format, _v_argptr); /* do it */
_con_flush(&cst);
ret=_vp_ret;
return(ret); /* return number of characters output */
}
/*-------------------------------------------------------------------------*
* sprintf.c - formatted output to buffer *
* This function provides formatted output to a character buffer for a *
* variable number of arguments. *
*--------------------------------------------------------------------------*/
int _buf_flush(FILE *st)
{
st->_cnt=st->_size;
st->_ptr=st->_base;
return(0);
}
int sprintf(char *s, const char *format, ...)
{
va_list _v_argptr;
FILE sst;
int ret;
_vp_flush=_buf_flush; /* set output function */
sst._base=s;
sst._ptr=s;
sst._cnt=INT_MAX-1;
sst._size=INT_MAX-1;
sst._flag=_F_BIN;
_stream=&sst;
va_start(_v_argptr, format); /* initialise argument pointer */
_vprinter(format, _v_argptr); /* do it */
*sst._ptr=0;
ret=_vp_ret;
return(ret); /* return number of characters output */
}
/*-------------------------------------------------------------------------*
* fprintf.c - formatted output to stream *
* This function provides formatted output to stream for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int fprintf(FILE *st, const char *format, ...)
{
va_list _v_argptr;
int temp_buf, ret;
temp_buf=0;
if((st->_flag&_F_IN) || (!(st->_flag&_F_WRIT)))
return(-1);
if(st->_size == 0)
{
char buffer[PF_TEMP_BUF];
st->_flag|=_F_RST;
_vp_setbuf(st, buffer);
temp_buf=1;
}
_vp_flush=_flusher; /* set output function */
_stream=st; /* initialise file pointer */
va_start(_v_argptr, format); /* initialise argument pointer */
_vprinter(format, _v_argptr); /* do it */
if(temp_buf)
{
_flusher(st);
st->_flag|=_F_RST;
_vp_freebuf(st);
}
else if(st->_flag&_F_DEV)
_flusher(st);
ret=_vp_ret;
return(ret); /* return number of characters output */
}
/*-------------------------------------------------------------------------*
* vprintf.c - formatted output to stdout *
* This function provides formatted output to stdout for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int vprintf(const char *format, va_list param)
{
va_list _v_argptr;
int temp_buf, ret;
temp_buf=0;
if(stdout->_size == 0)
{
char buffer[PF_TEMP_BUF];
stdout->_flag|=_F_RST;
_vp_setbuf(stdout, buffer);
temp_buf=1;
}
_vp_flush=_flusher; /* set output function */
_v_argptr= param; /* initialise argument pointer */
_stream=stdout;
_vprinter(format, _v_argptr); /* do it */
if(temp_buf)
{
_flusher(stdout);
stdout->_flag|=_F_RST;
_vp_freebuf(stdout);
}
else if(stdout->_flag&_F_DEV)
_flusher(stdout);
ret=_vp_ret;
return(ret); /* return number of characters output */
}
/*-------------------------------------------------------------------------*
* vsprintf.c - formatted output to buffer *
* This function provides formatted output to a character buffer for a *
* variable number of arguments. *
*--------------------------------------------------------------------------*/
int vsprintf(char *s, const char *format, va_list param)
{
va_list _v_argptr;
FILE sst;
int ret;
_vp_flush=_buf_flush; /* set output function */
sst._base=s;
sst._ptr=s;
sst._cnt=INT_MAX-1;
sst._size=INT_MAX-1;
sst._flag=_F_BIN;
_stream=&sst;
_v_argptr= param; /* initialise argument pointer */
_vprinter(format, _v_argptr); /* do it */
*sst._ptr=0; /* terminator for output string */
ret=_vp_ret;
return(ret); /* return number of characters output */
}
/*-------------------------------------------------------------------------*
* vfprintf.c - formatted output to stream *
* This function provides formatted output to stream for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int vfprintf(FILE *st, const char *format, va_list param)
{
va_list _v_argptr;
int temp_buf, ret;
temp_buf=0;
if((st->_flag&_F_IN) || (!(st->_flag&_F_WRIT)))
return(-1);
if(st->_size == 0)
{
char buffer[PF_TEMP_BUF];
st->_flag|=_F_RST;
_vp_setbuf(st, buffer);
temp_buf=1;
}
_vp_flush=_flusher; /* set output function */
_stream=st; /* set file pointer */
_v_argptr=param; /* initialise argument pointer */
_vprinter(format, _v_argptr); /* do it */
if(temp_buf)
{
char buffer[PF_TEMP_BUF];
_flusher(st);
st->_flag|=_F_RST;
_vp_setbuf(st, buffer);
}
else if(st->_flag&_F_DEV)
_flusher(st);
ret=_vp_ret;
return(ret); /* return number of characters output */
}
+136
View File
@@ -0,0 +1,136 @@
(* Release 3.00 *)
module r_emul
include "corelib.inc"
include "epocdefs.inc"
public FIDRQQ = 05C32H
public FIWRQQ = 0A23DH
public FIERQQ = 01632H
public FIARQQ = 0FE32H
public FISRQQ = 00632H
public FICRQQ = 00E32H
public FJERQQ = 00000H
public FJARQQ = 04000H
public FJSRQQ = 08000H
public FJCRQQ = 0C000H
public FIXRQQ = 0
segment _TEXT(CODE,28H)
segment _DATA(DATA,28H)
__emName: db 'SYS$8087.LDD',0
__lddName: db 'EM$:',0
__lddNameX: db 'EM$',0
extrn __SH_sword
extrn _DatCommandPtr
segment _DATA(DATA,28H)
__FChan: dw 0
select _TEXT
extrn __fp_1
extrn __sigFp
extrn __math_excep
extrn __FatalErrorPos
extrn __FatalError
xEnv = -256
xBuf = xEnv-MaxPathSize
public __FloatInit:
push bp
mov bp, sp
add sp, xBuf
;
sub dx, dx
mov cx, [_DatCommandPtr]
jcxz noCommandLine
tryAgain:
mov bx, __emName
lea di, [bp][xBuf]
sub si, si
sub al, al
mov ah, NmFilParse
int FilManager
jc noCommandLine
mov bx, di
xor al, al
mov ah, NmDevLoadLDD
int DevManager
jnc loadedLdd
cmp al, ExistsErr
je loadedLdd
test dx, dx
jne openFailed
noCommandLine:
inc dx
lea si, [bp][xEnv]
mov di, __lddNameX
mov ah, NmGenEnvStringGet
int GenManager
jc openFailed
mov cx, si
jmp tryAgain
loadedLdd:
mov dx, __sigFp
mov cx, -1
mov bx, __lddName
mov ah, NmIoOpen
int DevManager
jc openFailed
mov [__FChan], ax
;
mov sp, bp
pop bp
jmp __fp_1
;
openFailed:
call __FatalErrorPos
mov bx, 0FFFFH
jmp __FatalError
public __FloatFinish:
mov bx, [__FChan]
test bx, bx
je skipClose
mov ah, NmIoClose
int IoManager
mov bx, __lddNameX
mov dx, LDDSignature
mov ah, NmDevDelete
int DevManager
skipClose:
ret 0
public __FloatMathExcepDos :
fstsw [__SH_sword]
fclex
jmp near __math_excep
public __FloatJmpSave :
fld st(0), st(1)
fstp tbyte [di][_j_st1], st(0)
fld st(0), st(2)
fstp tbyte [di][_j_st2], st(0)
ret 0
public __FloatJmpRestore :
fld tbyte st(0), [si][_j_st1]
fstp st(2), st(0)
fld tbyte st(0), [si][_j_st2]
fstp st(3), st(0)
ret 0
end
+899
View File
@@ -0,0 +1,899 @@
/* Release 3.00 */
/*-------------------------------------------------------------------------*
* *
* r_scanf.c - MSDOS formatted input module *
* *
* COPYRIGHT (C) 1989 Jensen and Partners. All Rights Reserved *
* Written by Simon Knight. *
* *
* COPYRIGHT (C) 1991 Psion PLC. All Rights Reserved *
* Modified by NSM. *
* *
*--------------------------------------------------------------------------*/
#define _USE_CONIO
#include <clib.h>
_STATIC void _vscanner(const char *param_list, va_list _v_argptr);
_STATIC va_list _get_int(int pmod, int smod, unsigned flag, int width, va_list _v_argptr);
_STATIC va_list _get_char(int pmod, unsigned flag, int width, int setwidth, va_list _v_argptr);
_STATIC va_list _get_str(int pmod, unsigned flag, int width, va_list _v_argptr);
_STATIC va_list _get_str_delim(char *s, int pmod, unsigned flag, int width, va_list _v_argptr);
_STATIC va_list _get_pointer(int pmod, unsigned flag, va_list _v_argptr);
_STATIC int _skip_space(void);
_STATIC int _scan_input(int scan_state);
_STATIC int _isterm(char *s, char tc);
_STATIC int _buf_fil(FILE *st);
_STATIC int _con_fil(FILE *st);
int _vgetc(void);
int _vungetc(int c);
enum modifier { none, /* modifier prefixes */
shortmod, /* short integer */
longmod, /* long integer */
ldmod }; /* LONGDOUBLE */
#define _VGETC() _vgetc()
#define _VUNGETC(c) _vungetc(c)
#define _SKIP_SPACE() _skip_space()
#define _SCAN_INPUT(scan_state) _scan_input(scan_state)
/****************************************************************************
* this function scans the format string. *
****************************************************************************/
_STATIC void _vscanner(const char *plist, va_list _v_argptr)
{
int n;
int c, i;
int p, f;
int pmod, smod;
int width, setwidth;
unsigned flag;
char *tlist;
n=0;
_s_args=0;
_vs_count=0; /* zero counts */
while((c=plist[n++]) != 0) /* scan format string */
{
if(_v_argptr == NULL)
break;
if(isspace(c)) /* skip white space characters */
{ /* between input data */
while(isspace(i=_VGETC())); /* force end of file */
if(i > 0)
{
_VUNGETC(i);
continue;
}
else
return;
}
if(c == '%') /* evaluate format spec */
{
tlist=(char *) &plist[n];
goto _fmt_eval;
_fmt_eval_ret:
#pragma warn(wubd => off)
if(p)
{
n+=p;
#pragma warn(wubd => on)
continue;
}
else /* format spec error */
{ /* get next character and */
if((c=plist[n++]) == 0) /* check against input */
break;
}
}
if(c != (i =_VGETC())) /* if input char doesn't match - */
{
_VUNGETC(c);
break; /* terminate */
}
}
_vs_count++;
return;
/****************************************************************************
* This routine evaluates the format spec. *
****************************************************************************/
_fmt_eval:
p=0;
flag=0;
f=tlist[0];
if(f == '*')
{
flag|=SF_SUPRESS; /* suppress asignment */
p++;
}
/***************************************************************************
* The next paragraph evaluates any width parameter if present. There is *
* no limit on field width apart from integer range. *
***************************************************************************/
width=0;
f=tlist[p++];
while (isdigit(f))
{
width *= 10;
width += f- 0x30;
f=tlist[p++];
}
if(!width)
{
setwidth=0; /* width explicitly 0 */
width=SHRT_MAX;
}
else
setwidth=width;
/***************************************************************************
* This paragraph evaluates any pointer modifiers present. The optimal *
* path is for no modifiers *
***************************************************************************/
pmod=none;
/***************************************************************************
* This paragraph evaluates any size modifiers present. The optimal *
* path is for no modifiers *
***************************************************************************/
switch(f)
{
case 0 : /* incomplete spec - return */
case '\ ':
p=0;
goto _fmt_eval_ret;
case 'h':
smod=shortmod; /* short integer */
f=tlist[p++];
break;
case 'L':
smod=ldmod; /* LONGDOUBLE */
f=tlist[p++];
break;
case 'l':
smod=longmod; /* long integer */
f=tlist[p++];
break;
default:
smod=none;
break;
}
/***************************************************************************
* This paragraph is the main type switch. The argument pointer is taken *
* from the argument list and input and conversion functions called, where*
* if not disabled, an assignment is made. *
***************************************************************************/
switch(f)
{
case 'i':
flag|=SF_WILD;
goto _do_int;
break;
case 'd':
goto _do_int;
break;
case 'o':
flag|=SF_OCT;
goto _do_int;
break;
case 'X':
case 'x':
flag|=SF_HEX;
goto _do_int;
break;
case 'U':
flag|=SF_UPPER;
case 'u':
flag|=SF_NSIGNED;
_do_int:
_v_argptr=_get_int(pmod, smod, flag, width, _v_argptr);
break;
case 'E': /* real types */
case 'e':
case 'f':
case 'G':
case 'g':
_v_argptr=_real_in(pmod, smod, flag, width, _v_argptr);
break;
case 'c': /* character */
_v_argptr=_get_char(pmod, flag, width, setwidth, _v_argptr);
break;
case 's': /* string */
_v_argptr=_get_str(pmod, flag, width, _v_argptr);
break;
case '[': /* deliminated string */
_v_argptr=_get_str_delim(&tlist[p], pmod, flag, width, _v_argptr);
while((tlist[p++] != ']') && (p-1));
break;
case 'n': /* character count */
if(smod == longmod)
*(va_arg(_v_argptr, long *)) = _vs_count;
else
*(va_arg(_v_argptr, int *)) = _vs_count;
break;
case 'p': /* pointer */
flag|=(SF_HEX);
pmod=none;
goto _do_int;
default:
p=0;
goto _fmt_eval_ret;
}
goto _fmt_eval_ret; /* return */
}
_STATIC int _skip_space()
{
int i;
while(isspace(i=_VGETC())); /* skip white space in stream */
if(i >= 0)
{
_VUNGETC(i);
return(0);
}
else if(_s_args == 0)
longjmp(_EOFhandler, 1);
return(-1);
}
_STATIC int _scan_input(int scan_state)
{
int c;
c=_VGETC();
if(c != -1)
return(c);
if((_s_args == 0) && (scan_state == 0))
longjmp(_EOFhandler, 1);
return(-1);
}
/****************************************************************************
* This function scans the input stream and converts to an integer. *
****************************************************************************/
_STATIC va_list _get_int(int pmod, int smod, unsigned flag, int width, va_list _v_argptr)
{
unsigned long temp;
int c, good_scan;
int negative;
void *iptr;
temp=0;
good_scan=0;
negative=FALSE;
if(_SKIP_SPACE() == -1)
return(_v_argptr);
c=_SCAN_INPUT(good_scan);
if((c == '+') && (width))
{
if((c=_SCAN_INPUT(good_scan)) == -1)
return(_v_argptr);
--width;
}
else if((c == '-') && (width))
{ /* number is negative */
negative=TRUE;
if((c=_SCAN_INPUT(good_scan)) == -1)
return(_v_argptr);
--width;
}
if(flag&SF_WILD)
{ /* get dec oct or hex */
if((c =='0') && (width))
{
flag|=SF_OCT;
--width;
good_scan=1;
c=_SCAN_INPUT(good_scan);
c=tolower(c);
if(c == 'x')
{
flag|=SF_HEX;
if((c=_SCAN_INPUT(good_scan)) == -1)
return(_v_argptr);
--width;
}
}
}
if(flag&SF_HEX) /* convert hex */
{
if((c =='0') && (width))
{
--width;
good_scan=1;
c=_SCAN_INPUT(good_scan);
c=tolower(c);
if(c == 'x')
{
if((c=_SCAN_INPUT(good_scan)) == -1)
return(_v_argptr);
--width;
}
}
while((isxdigit(c=tolower(c))) && (width >0))
{
good_scan=1;
temp*=16;
if(!isdigit(c))
c-=87;
else
c-='0';
temp+=c;
c=_SCAN_INPUT(good_scan);
--width;
}
}
else if(flag&SF_OCT) /* convert octal */
{
while((c >= '0') && (c <= '7') && (width>0))
{
good_scan=1;
temp*=8;
temp+=c-'0';
c=_SCAN_INPUT(good_scan);
--width;
}
}
else /* convert decimal */
{
while((isdigit(c)) && (width>0))
{
good_scan=1;
temp*=10;
temp+=c-'0';
c=_SCAN_INPUT(good_scan);
--width;
}
}
_VUNGETC(c);
if((!(flag&SF_NSIGNED)) && (negative)) /* ignore '-' if unsigned */
temp*= -1;
if(!good_scan)
return(NULL);
if(!(flag&SF_SUPRESS)) /* assign field unless suppressed */
{
if(flag&SF_UPPER)
smod=longmod;
iptr = (va_arg(_v_argptr, void *));
switch(smod)
{
case shortmod:
*((short *) iptr) = (short) temp;
break;
case longmod:
*((long *) iptr) = (long) temp;
break;
default:
*((int *) iptr) = (int) temp;
break;
}
_s_args++; /* inc argument counter */
}
return(_v_argptr);
}
/****************************************************************************
* This function scans the input stream and converts to real. *
****************************************************************************/
#pragma warn(wall => off)
va_list _rreal_in(int pmod, int smod, unsigned flag, int width, va_list _v_argptr)
{
int n, q, c, good_scan;
LONGDOUBLE volatile dtemp;
char _fmt_buf[64]; /* buffer for formatted number */
void *dptr;
n=0;
good_scan=0;
if(_SKIP_SPACE() == -1)
return(_v_argptr);
c=_SCAN_INPUT(good_scan);
while(1)
{
if((c == '+') || (c == '-')) /* leading sign */
{
_fmt_buf[n++]= (char) c;
if((c=_SCAN_INPUT(good_scan)) == -1)
return(_v_argptr);
--width;
} /* width check always after _VGETC */
for(q=0; q<2; q++)
{
while((isdigit(c)) && (width)) /* get digits */
{
good_scan=1;
_fmt_buf[n++]= (char) c;
c=_SCAN_INPUT(good_scan);
--width;
}
if((c == DEC_POINT) && (q == 0) && (width)) /* decimal point */
{
_fmt_buf[n++]= (char) c;
if((c=_SCAN_INPUT(good_scan)) == -1)
break;
--width;
}
else if(q == 0)
break;
} /* go back for more digits if first iteration */
if(!width)
break; /* exponent */
if((c == 'E') || (c == 'e') || (c == 'D') || (c == 'd'))
{
_fmt_buf[n++]= (char) c;
c=_SCAN_INPUT(good_scan);
--width;
}
else
break;
if(!width) /* exponent leading sign */
break;
if((c == '+') || (c == '-'))
{
_fmt_buf[n++]= (char) c;
c=_SCAN_INPUT(good_scan);
--width;
} /* exponent digits */
while((isdigit(c)) && (width))
{
_fmt_buf[n++]= (char) c;
c=_SCAN_INPUT(good_scan);
--width;
}
break;
}
_fmt_buf[n]=0; /* terminate string */
_VUNGETC(c);
if(!good_scan)
return(NULL);
if(!(flag&SF_SUPRESS))
{
dtemp=atofl(_fmt_buf); /* convert and assign if not suppressed */
dptr = (va_arg(_v_argptr, void *));
switch(smod)
{
case ldmod :
*((LONGDOUBLE *) dptr) = dtemp;
break;
case longmod :
*((double *) dptr) = (double) dtemp;
break;
default :
*((float *) dptr) = (float) dtemp;
break;
}
_s_args++;
}
return(_v_argptr);
}
/****************************************************************************
* This function scans the input stream for the next width characters even *
* if white space. *
****************************************************************************/
_STATIC va_list _get_char(int pmod, unsigned flag, int width, int setwidth, va_list _v_argptr)
{
int c, n, good_scan;
char *array;
n=0;
good_scan=0;
if(!setwidth) /* width = 1 if not set */
width=1;
if(!(flag&SF_SUPRESS)) /* if not suppressed get char pointer */
{
array=va_arg(_v_argptr, char *);
}
while(width)
{ /* scan input */
if((c=_SCAN_INPUT(good_scan)) == -1)
break;
--width;
good_scan=1;
if(!(flag&SF_SUPRESS)) /* assign if not suppressed */
{
array[n++]=(char) c; /* terminate string if not suppressed */
}
}
if(good_scan)
++_s_args;
else
return(NULL);
return(_v_argptr);
}
/****************************************************************************
* This function scans the input stream for the next width characters *
* until it finds a white space character. *
****************************************************************************/
_STATIC va_list _get_str(int pmod, unsigned flag, int width, va_list _v_argptr)
{
int c, n, good_scan;
char *array;
n=0;
good_scan=0;
if(_SKIP_SPACE() == -1)
return(_v_argptr);
c=_SCAN_INPUT(good_scan);
if(!(flag&SF_SUPRESS)) /* get char pointer if not suppressed */
{
array=va_arg(_v_argptr, char *);
}
while (width)
{
if(isspace(c)) /* terminate if white-space or EOF */
break;
good_scan=1;
if(!(flag&SF_SUPRESS)) /* assign if not suppressed */
{
array[n++]=(char) c;
}
if((c=_SCAN_INPUT(good_scan)) == -1)
break;
--width;
}
_VUNGETC(c);
if(!(flag&SF_SUPRESS)) /* terminate string if not suppressed */
{
array[n]='\0'; /* terminate string if not suppressed */
}
if(good_scan)
++_s_args;
else
return(NULL);
return(_v_argptr);
}
/****************************************************************************
* This function scans the input stream for the next width characters *
* until it finds a white space character. *
****************************************************************************/
_STATIC va_list _get_str_delim(char *s, int pmod, unsigned flag , int width, va_list _v_argptr)
{
int c, n, good_scan;
char *array;
n=0;
good_scan=0;
if((c=_SCAN_INPUT(good_scan)) == -1)
return(_v_argptr);
if(!(flag&SF_SUPRESS)) /* get char pointer unless suppressed */
{
array=va_arg(_v_argptr, char *);
}
while(width)
{
if(_isterm(s, (char)c)) /* terminate if a deliminating character */
break;
good_scan=1;
if(!(flag&SF_SUPRESS)) /* asign if not suppressed */
{
array[n++]=(char) c;
}
if((c=_SCAN_INPUT(good_scan)) == -1)
break;
width--;
}
_VUNGETC(c);
if(!(flag&SF_SUPRESS))
{
array[n]='\0'; /* terminate string if not suppressed */
}
if(good_scan)
++_s_args;
else
return(NULL);
return(_v_argptr);
}
/****************************************************************************
* This function scans the format string for deliminating characters. *
* It returns TRUE if the character is a deliminator. *
****************************************************************************/
_STATIC int _isterm(char *s, char tc)
{
int n;
int first;
n=0;
first=TRUE;
if(s[n] == '^') /* charcaters in set are deliminators */
{
n++;
while(((s[n] != ']') || (first)) && (s[n]))
{
first=FALSE;
if(tc == s[n++])
return(TRUE);
}
return(FALSE);
} /* characters not in set are deliminators */
else
{
while(((s[n] != ']') || (first)) && (s[n]))
{
first=FALSE;
if(tc == s[n++])
return(FALSE);
}
return(TRUE);
}
}
#pragma warn(wall => on)
#pragma warn(wpnu => off)
/*-------------------------------------------------------------------------*
* scanf.c - formatted input from stdin *
* This function provides formatted input from stdin for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int scanf(const char *format, ...)
{
va_list _v_argptr;
int temp_buf, ret;
temp_buf=0;
if(stdin->_size == 0)
{
char buffer[PF_TEMP_BUF];
stdin->_flag|=_F_RST;
_vp_setbuf(stdin, buffer);
stdin->_cnt=0;
temp_buf=1;
}
_vs_fill=_filler; /* set put_back function */
_stream=stdin;
va_start(_v_argptr, format); /* initialise argument pointer */
if(setjmp(_EOFhandler)) /* EOF in input function arrives here */
{
ret=-1;
goto sf_out;
}
_vscanner(format, _v_argptr); /* do it */
ret=_s_args;
sf_out:
if(temp_buf)
{
fflush(stdin);
_vp_freebuf(stdin);
}
return(ret); /* return number of fields assigned */
}
/*-------------------------------------------------------------------------*
* cscanf.c - formatted input from console *
* This function provides formatted input from console for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int _con_fil(FILE *st)
{
int c;
st->_ptr=st->_base;
st->_cnt=st->_size;
c=getche();
*st->_ptr= (char ) c;
if(c == 13)
ungetch(10);
if(c == _CTLZ)
return(EOF);
return(1);
}
int cscanf(const char *format, ...)
{
va_list _v_argptr;
FILE cst;
char cbuf[2];
cst._cnt=0;
cst._size=1;
cst._base=cbuf;
cst._ptr=cbuf;
_stream=&cst;
_vs_fill=_con_fil; /* set filler function */
va_start(_v_argptr, format); /* initialise argument pointer */
if(setjmp(_EOFhandler)) /* EOF in input function arrives here */
return(EOF);
_vscanner(format, _v_argptr); /* do it */
return(_s_args); /* return number of fields assigned */
}
/*-------------------------------------------------------------------------*
* sscanf.c - formatted input from buffer *
* This function provides formatted input from a character buffer for a *
* variable number of arguments. *
*--------------------------------------------------------------------------*/
int _buf_fil(FILE *st)
{
return(-1);
}
int sscanf(const char *s, const char *format, ...)
{
va_list _v_argptr;
FILE sst;
_vs_fill=_buf_fil; /* set filler function */
sst._cnt=strlen(s)+1;
sst._ptr=(char *) s;
sst._flag=_F_BIN;
_stream=&sst;
va_start(_v_argptr, format); /* initialise argument pointer */
if(setjmp(_EOFhandler)) /* EOF arrives here */
return(EOF);
_vscanner(format, _v_argptr); /* do it */
return(_s_args); /* return number of fields assigned */
}
/*-------------------------------------------------------------------------*
* fscanf.c - formatted input from stream *
* This function provides formatted input from stream for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int fscanf(FILE *st, const char *format, ...)
{
va_list _v_argptr;
int temp_buf, ret;
temp_buf=0;
if((st->_flag&_F_OUT) || (!(st->_flag&_F_READ)))
return(-1);
if(st->_size == 0)
{
char buffer[PF_TEMP_BUF];
st->_flag|=_F_RST;
_vp_setbuf(st, buffer);
st->_cnt=0;
temp_buf=1;
}
_vs_fill=_filler; /* set put_back function */
_stream=st;
va_start(_v_argptr, format); /* initialise argument pointer */
if(setjmp(_EOFhandler)) /* EOF in input function arrives here */
{
ret=-1;
goto fsf_out;
}
_vscanner(format, _v_argptr); /* do it */
ret=_s_args;
fsf_out:
if(temp_buf)
{
fflush(st);
_vp_freebuf(st);
}
return(ret); /* return number of fields assigned */
}
/*-------------------------------------------------------------------------*
* vscanf.c - formatted input from stdin *
* This function provides formatted input from stdin for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int vscanf(const char *format, va_list argptr)
{
va_list _v_argptr;
int temp_buf, ret;
temp_buf=0;
if(stdin->_size == 0)
{
char buffer[PF_TEMP_BUF];
stdin->_flag|=_F_RST;
_vp_setbuf(stdin, buffer);
stdin->_cnt=0;
temp_buf=1;
}
_vs_fill=_filler; /* set put_back function */
_stream=stdin;
_v_argptr=argptr; /* initialise argument pointer */
if(setjmp(_EOFhandler)) /* EOF in input function arrives here */
{
ret=-1;
goto vsf_out;
}
_vscanner(format, _v_argptr); /* do it */
ret=_s_args;
vsf_out:
if(temp_buf)
{
fflush(stdin);
_vp_freebuf(stdin);
}
return(ret); /* return number of fields assigned */
}
/*-------------------------------------------------------------------------*
* vsscanf.c - formatted input from buffer *
* This function provides formatted input from a character buffer for a *
* variable number of arguments. *
*--------------------------------------------------------------------------*/
int vsscanf(const char *s, const char *format, va_list argptr)
{
va_list _v_argptr;
FILE sst;
_vs_fill=_buf_fil; /* set filler function */
sst._cnt=strlen(s)+1;
sst._ptr=(char *) s;
sst._flag=_F_BIN;
_stream=&sst;
_v_argptr=argptr; /* initialise argument pointer */
if(setjmp(_EOFhandler)) /* EOF arrives here */
return(EOF);
_vscanner(format, _v_argptr); /* do it */
return(_s_args); /* return number of fields assigned */
}
/*-------------------------------------------------------------------------*
* vfscanf.c - formatted input from stream *
* This function provides formatted input from stream for a variable *
* number of arguments. *
*--------------------------------------------------------------------------*/
int vfscanf(FILE *st, const char *format, va_list argptr)
{
va_list _v_argptr;
int temp_buf, ret;
temp_buf=0;
if((st->_flag&_F_OUT) || (!(st->_flag&_F_READ)))
return(-1);
if(st->_size == 0)
{
char buffer[PF_TEMP_BUF];
st->_flag|=_F_RST;
_vp_setbuf(st, buffer);
st->_cnt=0;
temp_buf=1;
}
_vs_fill=_filler; /* set put_back function */
_stream=st;
_v_argptr=argptr; /* initialise argument pointer */
if(setjmp(_EOFhandler)) /* EOF in input function arrives here */
{
ret=-1;
goto vfsf_out;
}
_vscanner(format, _v_argptr); /* do it */
ret=_s_args;
vfsf_out:
if(temp_buf)
{
fflush(st);
_vp_freebuf(st);
}
return(ret); /* return number of fields assigned */
}
+157
View File
@@ -0,0 +1,157 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* STDIOSTR.CPP - 2.0 stream class implementations. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#include <clib.h>
#include <stdiostr.hpp>
#pragma module(init_prio=>22)
stdiobuf::stdiobuf(FILE *f) : streambuf(NULL, 0) {
if(unbuffered()) {
setb(lahead, &lahead[1], 0);
unbuffered(1);
}
setp(base(), base());
setg(base(), ebuf(), ebuf());
sio=f;
last_seek=0;
gs=0;
sync();
}
stdiobuf::~stdiobuf() {
// fclose(f);
}
int stdiobuf::overflow(int c) {
int nw;
if(unbuffered()) {
if((c == EOF) || (fputc(c, sio) == EOF))
return EOF;
}
else {
nw=pptr()-pbase();
if(nw) {
if(::fwrite(pbase(), sizeof(char), nw, sio) != nw)
return EOF;
}
}
last_seek=ftell(sio);
setp(pbase(), epptr());
if((c != EOF) && (!unbuffered()))
sputc(c);
return c;
}
int stdiobuf::last_op() {
int ret;
if(pptr() > pbase())
ret= ios::out;
else if(gs)
ret= ios::in;
else
ret = 0;
return ret;
}
int stdiobuf::pbackfail(int c) {
if(!unbuffered())
sync();
return ungetc(c, sio);
}
int stdiobuf::sync() {
if(unbuffered()) {
setp(base(), base());
setg(base(), ebuf(), ebuf());
return fflush(sio);
}
if(last_op() == ios::out)
overflow();
else if(last_op() == ios::in) {
last_seek+= gptr()-eback();
::fseek(sio, last_seek, SEEK_SET);
}
else
return 0;
setp(base(), ebuf());
setg(base(), ebuf(), ebuf());
gs=0;
return 0;
}
int stdiobuf::underflow() {
int nr, c;
gs=1;
nr=ebuf()-eback();
last_seek=ftell(sio);
if(nr == 1) {
c=fgetc(sio);
if(c == EOF)
return EOF;
*eback()=c;
}
else {
nr=fread(eback(), sizeof(char), nr, sio);
if(ferror(sio) || (nr == 0))
return EOF;
}
setg(eback(), eback(), eback()+nr);
return *gptr();
}
streampos stdiobuf::seekoff(streamoff off, ios::seek_dir d, int) {
streampos p;
ios::seek_dir dir;
if(d == ios::cur) {
if(last_op() == ios::out)
p = pptr()-pbase();
else if(last_op() == ios::in)
p = gptr()-eback();
else
p=0;
p += last_seek + off;
dir=ios::beg;
}
else {
p=off;
dir=d;
}
sync();
last_seek = p;
fseek(sio, p, dir);
setp(base(), epptr());
setg(base(), ebuf(), ebuf());
return last_seek;
}
stdiostream::stdiostream(FILE *f) : ios(&buf),
buf(f) {
}
stdiostream::~stdiostream() {
}

+709
View File
@@ -0,0 +1,709 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* STREAM.CPP - 1.2 stream class implementations. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#define _NO_IO
#include <clib.h>
#include <stream.hpp>
#pragma module(init_prio=>22)
struct whitespace WS;
#define CIRC_BUF_SIZE 1024
#define MAX_STRING 512
#pragma save
#pragma call(near_call=>on, reg_param=>(ax,bx,cx,dx), reg_saved=>(ax,bx,cx,dx,di,si,ds,st1,st2))
static void outstr(ostream& st, char *s);
static char *doconv(long val, int width, int radix);
static char *getbuf(int sz);
#pragma restore
int streambuf::allocate() {
base=new char[BUFSIZ];
if(base) {
didalloc=1;
setbuf(base, BUFSIZ, 0);
return(0);
}
return(-1);
}
streambuf * streambuf::setbuf(char *b, int sz, unsigned pos) {
if(didalloc && base)
delete base;
base=b;
if(base && pos < sz) {
eptr=b+sz;
pptr=b+pos;
gptr=b+pos;
return(this);
}
return(NULL);
}
int streambuf::overflow(int) {
return EOF;
}
int streambuf::underflow() {
return EOF;
}
void streambuf::terminate() {
if(pptr < eptr)
*pptr = '\0';
}
streambuf::~streambuf() {
if(didalloc)
delete base;
}
int streambuf::snextc() {
if(pptr == eptr)
return underflow();
return *pptr++;
}
int streambuf::sputc(int c) {
if(gptr == eptr)
return overflow(c);
*gptr++ = c;
return c;
}
void streambuf::sputbackc(char c) {
if((pptr != base) || (c != EOF))
*--pptr = c;
}
/****************************************************************************/
// conversion fiunction implementation
/****************************************************************************/
static char *getbuf(int sz) {
static char buffer[CIRC_BUF_SIZE];
static char *curpos=buffer;
char *ret;
if(curpos+sz < buffer+CIRC_BUF_SIZE) {
ret=curpos;
curpos+=sz;
}
else if(sz < CIRC_BUF_SIZE) {
ret=buffer;
curpos=buffer;
}
else
ret=NULL;
return ret;
}
static char *doconv(long val, int width, int radix) {
char nbuf[32];
char *obuf;
int l, pad;
ltoa(val, nbuf, radix);
l=strlen(nbuf);
if(width > 0) {
if(l > width) {
l = width;
nbuf[l]='\0';
}
pad = width-l;
if(pad+l > (MAX_STRING-1))
pad=(MAX_STRING-1)-l;
}
else
pad=0;
obuf=getbuf(pad+l+1);
if(pad)
memset(obuf, ' ', pad);
strcpy(&obuf[pad], nbuf);
return(obuf);
}
char *dec(long val, int width) {
return(doconv(val, width, 10));
}
char *hex(long val, int width) {
return(doconv(val, width, 16));
}
char *oct(long val, int width) {
return(doconv(val, width, 8));
}
char *chr(int c, int width) {
char *obuf;
if(--width > 0) {
if(width > (MAX_STRING-2))
width = (MAX_STRING-2);
}
else
width=0;
obuf=getbuf(width+2);
if(width)
memset(obuf, ' ', width);
obuf[width]=c;
obuf[width+1]='\0';
return obuf;
}
char *str(const char *s, int width) {
int l, pad;
char *obuf;
l=strlen(s);
if(width > 0) {
if(l > width)
l = width;
pad = width-l;
if(pad+l > (MAX_STRING-1))
pad=(MAX_STRING-1)-l;
}
else
pad=0;
obuf=getbuf(pad+l+1);
if(pad)
memset(obuf, ' ', pad);
memcpy(&obuf[pad], s, l);
obuf[pad+l]='\0';
return(obuf);
}
char *form(char *format, ...) {
va_list _v_argptr;
char nbuf[MAX_STRING];
char *obuf;
va_start(_v_argptr, format);
vsprintf(nbuf, format, _v_argptr);
obuf=getbuf(strlen(nbuf)+1);
strcpy(obuf, nbuf);
return obuf;
}
/****************************************************************************/
// filebuf implementation
/****************************************************************************/
filebuf::filebuf(FILE *f) {
file=f;
if(file) {
fd=fileno(f);
isopen=1;
didalloc=0;
}
else
isopen=0;
}
filebuf::filebuf(int h) {
file=::fdopen(h, "r+");
if(file) {
fd=h;
isopen=1;
didalloc=0;
}
else
isopen=0;
}
filebuf::filebuf(int h, char *buf, int sz) {
file=::fdopen(h, "r+");
if(file) {
fd=h;
isopen=1;
didalloc=0;
::setvbuf(file, buf, _IOFBF, sz);
}
else
isopen=0;
}
static char *modes[3]={"r",
"w",
"a" };
filebuf* filebuf::open(char *path, int open_mode) {
if(file)
close();
file=::fopen(path, modes[open_mode]);
if(file) {
fd=fileno(file);
isopen=1;
didalloc=0;
return(this);
}
isopen=0;
return(NULL);
}
int filebuf::close() {
isopen=0;
return ::fclose(file);
}
void filebuf::terminate() {
}
/****************************************************************************/
// ostream implementation
/****************************************************************************/
static void outstr(ostream& st, char *s) {
int c, n=0;
while((st.good()) && ((c=s[n++]) != '\0')) {
st.put(c);
}
}
ostream::ostream(streambuf *sb) {
stream=sb;
mystream=0;
state=_good;
}
ostream::ostream(int h) {
stream = new filebuf(h);
mystream=1;
state=_good;
}
ostream::ostream(int len, char *buf) {
stream = new streambuf(buf, len);
mystream=1;
state=_good;
}
ostream& ostream::operator <<(int i) {
char o[32];
ltoa((long) i, o, 10);
outstr(*this, o);
return *this;
}
ostream& ostream::operator <<(long l) {
char o[32];
ltoa(l, o, 10);
outstr(*this, o);
return *this;
}
ostream& ostream::operator <<(unsigned long ul) {
char o[32];
ultoa(ul, o, 10);
outstr(*this, o);
return *this;
}
ostream& ostream::operator <<(const char *s) {
outstr(*this, (char *)s);
return *this;
}
ostream& ostream::operator <<(double d) {
char o[32];
gcvtl((long double) d, 18, o);
outstr(*this, o);
return *this;
}
ostream& ostream::operator <<(long double ld) {
char o[32];
gcvtl(ld, 18, o);
outstr(*this, o);
return *this;
}
ostream& ostream::flush() {
if(stream->file)
fflush(stream->file);
else {
stream->pptr=stream->base;
stream->gptr=stream->base;
}
state=_good;
return *this;
}
/****************************************************************************/
// istream implementation
/****************************************************************************/
long double istream::getreal() {
int c, n=0;
char _fmt_buf[64];
if(tied_to)
tied_to->flush();
if(skipping)
*this >> WS;
c=stream->snextc();
while(c != EOF)
{
if((c == '+') || (c == '-')) { /* leading sign */
_fmt_buf[n++]= (char) c;
c=stream->snextc();
if(c == EOF)
break;
}
for(int q=0; q<2; q++) {
while(isdigit(c)) { /* get digits */
_fmt_buf[n++]= (char) c;
c=stream->snextc();
if(c == EOF)
break;
}
if((c == '.') && (q == 0)) { /* decimal point */
_fmt_buf[n++]= (char) c;
c=stream->snextc();
if(c == EOF)
break;
}
else if(q == 0)
break;
} /* go back for more digits if first iteration */
c= toupper(c);
if((c == 'E') || (c == 'D')) {
_fmt_buf[n++]= (char) c;
c=stream->snextc();
if(c == EOF)
break;
}
else
break;
if((c == '+') || (c == '-')) {
_fmt_buf[n++]= (char) c;
c=stream->snextc();
if(c == EOF)
break;
} /* exponent digits */
while(isdigit(c)) {
_fmt_buf[n++]= (char) c;
c=stream->snextc();
if(c == EOF)
break;
}
break;
}
_fmt_buf[n]=0; /* terminate string */
if(c != EOF)
stream->sputbackc(c);
else {
state = _fail|_eof;
if((stream->file) && (ferror(stream->file)))
state = _bad;
}
return atofl(_fmt_buf); /* convert and assign if not suppressed */
}
long istream::getlong(int us) {
int c, negative=0, flag=0;
long temp=0;
int _goodscan=0;
if(tied_to)
tied_to->flush();
if(skipping)
*this >> WS;
c=stream->snextc();
if(c == EOF)
goto error;
if(c == '+') {
_goodscan=1;
c=stream->snextc();
if(c == EOF)
goto error;
}
else if(c == '-') { /* number is negative */
_goodscan=1;
negative=1;
c=stream->snextc();
if(c == EOF)
goto error;
else if(us) {
state = _fail;
return(0);
}
}
if(c =='0') {
_goodscan=1;
flag=_OCT;
c=stream->snextc();
if(c == EOF)
goto error;
c=tolower(c);
if(c == 'x') {
flag=_HEX;
c=stream->snextc();
if(c == EOF)
goto error;
}
}
if(flag == _HEX) {
while(isxdigit(c=tolower(c))) {
temp*=16;
if(!isdigit(c))
c-=87;
else
c-='0';
temp+=c;
c=stream->snextc();
if(c == EOF)
goto error;
}
}
else if(flag == _OCT) {
while((c >= '0') && (c <= '7')) {
temp*=8;
temp+=c-'0';
c=stream->snextc();
if(c == EOF)
goto error;
}
}
else {
while(isdigit(c)) {
_goodscan=1;
temp*=10;
temp+=c-'0';
c=stream->snextc();
if(c == EOF)
goto error;
}
}
error:
if(!_goodscan) {
state = _fail|_eof;
if((stream->file) && (ferror(stream->file)))
state = _bad;
return(0);
}
c=tolower(c);
if((c != 'u') && (c != 'l'))
stream->sputbackc(c);
if(negative)
return -temp;
return temp;
}
istream::istream(streambuf *st, int sk, ostream* tie) {
tied_to=tie;
stream=st;
skipping=sk;
mystream=0;
if(st)
state=_good;
}
istream::istream(int sz, char* buf, int sk) {
tied_to=NULL;
stream= new streambuf(buf, sz);
skipping=sk;
mystream=1;
if(stream)
state=_good;
}
istream::istream(int h, int sk, ostream* tie) {
tied_to=tie;
stream= new filebuf(h);
skipping=sk;
mystream=1;
if(stream)
state=_good;
}
istream& istream::operator>>(unsigned char& c) {
int t;
if(state == _good) {
if(tied_to)
tied_to->flush();
do {
t=stream->snextc();
} while ((skipping) && (isspace(t)));
if(t == EOF) {
state = _fail|_eof;
if((stream->file) && (ferror(stream->file)))
state = _bad;
}
else
c=t;
}
return *this;
}
istream& istream::operator>>(float& f) {
f=(float) getreal();
return *this;
}
istream& istream::operator>>(double& d) {
d=(double) getreal();
return *this;
}
istream& istream::operator>>(long double& ld) {
ld= getreal();
return *this;
}
istream& istream::operator>>(char *s) {
int c, n=0;
if(state == _good) {
if(tied_to)
tied_to->flush();
do {
c=stream->snextc();
} while ((skipping) && (isspace(c)));
while(!isspace(c)) {
if(c == EOF) {
state = _fail|_eof;
if((stream->file) && (ferror(stream->file)))
state = _bad;
break;
}
s[n++]=c;
c=stream->snextc();
}
s[n] = '\0';
}
return *this;
}
istream& istream::operator>>(whitespace& w) {
if(state == _good) {
if(tied_to)
tied_to->flush();
do {
w.x=stream->snextc();
} while (isspace(w.x));
stream->sputbackc(w.x);
}
return *this;
}
istream& istream::get(char& c) {
int t;
if(state == _good) {
t=stream->snextc();
if(t == EOF) {
state = _fail|_eof;
if((stream->file) && (ferror(stream->file)))
state = _bad;
}
else
c=t;
}
return *this;
}
istream& istream::get(char *s, int len, int term) {
int c, n=0;
if(state == _good) {
while(n < len) {
c=stream->snextc();
if(c == EOF) {
state = _fail|_eof;
if((stream->file) && (ferror(stream->file)))
state = _bad;
break;
}
if(c == term) {
stream->sputbackc(c);
break;
}
s[n++]=c;
}
s[n] = '\0';
}
return *this;
}
static filebuf inbuf(&_iob[0]);
static filebuf outbuf(&_iob[1]);
static filebuf errbuf(&_iob[2]);
istream cin(&inbuf, 1, &cout);
ostream cout(&outbuf);
ostream cerr(&errbuf);

+291
View File
@@ -0,0 +1,291 @@
/* Release 3.10 */
/*-------------------------------------------------------------------------*
* *
* STRSTREAM.CPP - 2.1 file stream class implementations. *
* *
* COPYRIGHT (C) 1989..1992 Clarion Software Corporation. *
* All Rights Reserved *
* *
*--------------------------------------------------------------------------*/
#include <clib.h>
#include <strstrea.hpp>
#pragma module(init_prio=>22)
//**************************************************************************
// strstreambuf implementation
//**************************************************************************
strstreambuf::strstreambuf() : streambuf(NULL, 0) {
flags=dynamic;
allocf=NULL;
freef=NULL;
next_alloc=512;
init(NULL, 0, NULL);
}
strstreambuf::strstreambuf(int n) : streambuf(NULL, 0) {
flags=dynamic;
allocf=NULL;
freef=NULL;
next_alloc=n;
init(NULL, 0, NULL);
}
strstreambuf::strstreambuf(void * (*a)(long), void (*f)(void*)) : streambuf(NULL, 0) {
flags=dynamic;
allocf=a;
freef=f;
next_alloc=512;
init(NULL, 0, NULL);
}
strstreambuf::strstreambuf(char *ptr, int n, char *pstart) : streambuf(NULL, 0) {
int len;
if(n < 0) {
flags=unlimited;
len= INT_MAX;
}
else
flags=0;
if(n == 0)
len=strlen((char *)ptr);
else if(n > 0)
len=n;
next_alloc=0;
allocf=NULL;
freef=NULL;
init(ptr, len, pstart);
}
strstreambuf::~strstreambuf() {
if((flags&dynamic) && (!(flags&frozen))) {
if(freef)
freef(base());
else
delete base();
}
}
void strstreambuf::freeze(int f) {
flags |= frozen*(f == 1);
}
char *strstreambuf::str() {
flags |= frozen;
return base();
}
int strstreambuf::doallocate() {
char *b;
b=(char *) allocf(512);
if(b == NULL)
return EOF;
setb(b, b+512, 1);
setg(b, b, b+512);
setp(b, b+512);
return 1;
}
int strstreambuf::overflow(int c) {
char *nb, *ob;
int old_size, new_size, in_pbuf, in_gbuf;
if(flags&frozen)
return EOF;
old_size=ebuf()-base();
new_size=old_size+next_alloc;
in_pbuf=pptr()-pbase();
in_gbuf=gptr()-eback();
ob=base();
if(allocf)
nb = (char *) allocf(new_size);
else
nb = new char[new_size];
if(nb == NULL)
return EOF;
setb(nb, nb+new_size);
setg(nb, nb, nb+new_size);
setp(nb, nb+new_size);
if(ob) {
memcpy(nb, ob, old_size);
pbump(in_pbuf);
gbump(in_gbuf);
if(freef)
freef(ob);
else
delete ob;
}
if(c != EOF)
sputc(c);
return c;
}
int strstreambuf::underflow() {
return EOF;
}
streambuf *strstreambuf::setbuf(char *b, int n) {
if(b == NULL)
next_alloc=n;
else {
setb(b, b+512, 0);
setg(b, b, b+512);
setp(b, b+512);
}
return this;
}
streampos strstreambuf::seekoff(streamoff pos, ios::seek_dir d, int mode) {
streampos ret;
if(mode & ios::in) {
switch(d) {
case ios::beg :
setg(eback(), eback()+pos, egptr());
break;
case ios::cur :
gbump((int)pos);
break;
case ios::end :
setg(eback(), egptr()+pos, egptr());
break;
}
if((gptr() > egptr()) || (gptr() < eback()))
return -1L;
ret = gptr()-eback();
}
if(mode & ios::out) {
switch(d) {
case ios::beg :
setp(pbase(), epptr());
pbump((int)pos);
break;
case ios::cur :
pbump((int)pos);
break;
case ios::end :
setp(pbase(), epptr());
pbump((int)(epptr()-pbase()+pos));
break;
}
if((pptr() > epptr()) || (pptr() < base()))
return -1L;
ret = pptr()-pbase();
}
return ret;
}
void strstreambuf::init(char *ptr, int sz, char *pstart) {
char *eg, *pp;
setb(ptr, ptr+sz, 0);
if(pstart == NULL) {
eg=ebuf();
pp=ebuf();
}
else {
eg=pstart;
pp=pstart;
}
setg(ptr, ptr, eg);
setp(pp, ebuf());
}
//**************************************************************************
// strstreambase implementation
//**************************************************************************
strstreambase::strstreambase(char *g, int n, char *p) : buf(g, n, p) {
ios::init(&buf);
}
strstreambase::strstreambase() {
ios::init(&buf);
}
strstreambase::~strstreambase() {
}
//**************************************************************************
// istrstream implementation
//**************************************************************************
istrstream::istrstream(char *s) : strstreambase(s, 0, NULL),
istream(rdbuf()) {
}
istrstream::istrstream(char *s, int n) : strstreambase(s, n, NULL),
istream(rdbuf()) {
}
istrstream::~istrstream() {
}
ostrstream::ostrstream() : ostream(rdbuf()) {
}
ostrstream::ostrstream(char *cp, int n, int mode) : strstreambase(cp, n, cp),
ostream(rdbuf()) {
if(mode&(ios::ate|ios::app))
seekp(strlen(cp));
}
ostrstream::~ostrstream() {
}
//**************************************************************************
// istrstream implementation
//**************************************************************************
strstream::strstream() : strstreambase(),
iostream(rdbuf()) {
}
strstream::strstream(char *cp, int n, int mode) : strstreambase(cp, n, cp),
iostream(rdbuf()) {
if(mode&(ios::ate|ios::app))
seekp(strlen(cp));
}
strstream::~strstream() {
}