Run C files through clang-format.

This commit is contained in:
David Given 2018-06-17 16:11:29 +02:00
parent 9ede428e3c
commit 5784f5fabe
59 changed files with 977 additions and 730 deletions

View file

@ -18,6 +18,7 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
int _abi(i) int i; { int _abi(i) int i;
return(i>=0 ? i : -i); {
return (i >= 0 ? i : -i);
} }

View file

@ -18,6 +18,7 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
long _abl(i) long i; { long _abl(i) long i;
return(i>=0 ? i : -i); {
return (i >= 0 ? i : -i);
} }

View file

@ -18,6 +18,7 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
double _abr(r) double r; { double _abr(r) double r;
return(r>=0 ? r : -r); {
return (r >= 0 ? r : -r);
} }

View file

@ -23,34 +23,40 @@
/* procedure argshift; extern; */ /* procedure argshift; extern; */
/* function environ(i:integer):string; extern; */ /* function environ(i:integer):string; extern; */
extern int _pargc; extern int _pargc;
extern char **_pargv; extern char** _pargv;
extern char **_penvp; extern char** _penvp;
int argc() { int argc()
return(_pargc); {
return (_pargc);
} }
char *argv(i) { char* argv(i)
{
if (i >= _pargc) if (i >= _pargc)
return(0); return (0);
return(_pargv[i]); return (_pargv[i]);
} }
argshift() { argshift()
{
if (_pargc > 1) { if (_pargc > 1)
{
--_pargc; --_pargc;
_pargv++; _pargv++;
} }
} }
char *environ(i) { char* environ(i)
char **p; char *q; {
char** p;
char* q;
if (p = _penvp) if (p = _penvp)
while (q = *p++) while (q = *p++)
if (i-- < 0) if (i-- < 0)
return(q); return (q);
return(0); return (0);
} }

View file

@ -18,15 +18,17 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <em_abs.h> #include <em_abs.h>
#include <pc_err.h> #include <pc_err.h>
extern char *_hol0(); extern char* _hol0();
extern _trp(); extern _trp();
_ass(line,bool) int line,bool; { _ass(line, bool) int line, bool;
{
if (bool==0) { if (bool == 0)
{
LINO = line; LINO = line;
_trp(EASS); _trp(EASS);
} }

View file

@ -18,12 +18,14 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
struct descr { struct descr
int low; {
int diff; int low;
int size; int diff;
int size;
}; };
int _asz(dp) struct descr *dp; { int _asz(dp) struct descr* dp;
return(dp->size * (dp->diff + 1)); {
return (dp->size * (dp->diff + 1));
} }

View file

@ -15,8 +15,7 @@
#endif #endif
double double
_atn(x) _atn(x) double x;
double x;
{ {
/* Algorithm and coefficients from: /* Algorithm and coefficients from:
"Software manual for the elementary functions" "Software manual for the elementary functions"
@ -30,43 +29,47 @@ _atn(x)
-0.83758299368150059274e+0 -0.83758299368150059274e+0
}; };
static double q[] = { static double q[] = {
0.41066306682575781263e+2, 0.41066306682575781263e+2,
0.86157349597130242515e+2, 0.86157349597130242515e+2,
0.59578436142597344465e+2, 0.59578436142597344465e+2,
0.15024001160028576121e+2, 0.15024001160028576121e+2,
1.0 1.0
}; };
static double a[] = { static double a[] = {
0.0, 0.0,
0.52359877559829887307710723554658381, /* pi/6 */ 0.52359877559829887307710723554658381, /* pi/6 */
M_PI_2, M_PI_2,
1.04719755119659774615421446109316763 /* pi/3 */ 1.04719755119659774615421446109316763 /* pi/3 */
}; };
int neg = x < 0; int neg = x < 0;
int n; int n;
double g; double g;
if (neg) { if (neg)
{
x = -x; x = -x;
} }
if (x > 1.0) { if (x > 1.0)
x = 1.0/x; {
x = 1.0 / x;
n = 2; n = 2;
} }
else n = 0; else
n = 0;
if (x > 0.26794919243112270647) { /* 2-sqtr(3) */ if (x > 0.26794919243112270647)
{ /* 2-sqtr(3) */
n = n + 1; n = n + 1;
x = (((0.73205080756887729353*x-0.5)-0.5)+x)/ x = (((0.73205080756887729353 * x - 0.5) - 0.5) + x) / (1.73205080756887729353 + x);
(1.73205080756887729353+x);
} }
/* ??? avoid underflow ??? */ /* ??? avoid underflow ??? */
g = x * x; g = x * x;
x += x * g * POLYNOM3(g, p) / POLYNOM4(g, q); x += x * g * POLYNOM3(g, p) / POLYNOM4(g, q);
if (n > 1) x = -x; if (n > 1)
x = -x;
x += a[n]; x += a[n];
return neg ? -x : x; return neg ? -x : x;
} }

View file

@ -18,13 +18,16 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
int _bcp(sz,y,x) int sz; unsigned char *y,*x; { int _bcp(sz, y, x) int sz;
unsigned char *y, *x;
{
while (--sz >= 0) { while (--sz >= 0)
{
if (*x < *y) if (*x < *y)
return(-1); return (-1);
if (*x++ > *y++) if (*x++ > *y++)
return(1); return (1);
} }
return(0); return (0);
} }

View file

@ -18,18 +18,19 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
extern _flush(); extern _flush();
/* procedure buff(var f:file of ?); */ /* procedure buff(var f:file of ?); */
buff(f) struct file *f; { buff(f) struct file* f;
{
int sz; int sz;
if ((f->flags & (0377|WRBIT)) != (MAGIC|WRBIT)) if ((f->flags & (0377 | WRBIT)) != (MAGIC | WRBIT))
return; return;
_flush(f); _flush(f);
sz = f->size; sz = f->size;
f->count = f->buflen = (sz>PC_BUFLEN ? sz : PC_BUFLEN-PC_BUFLEN%sz); f->count = f->buflen = (sz > PC_BUFLEN ? sz : PC_BUFLEN - PC_BUFLEN % sz);
} }

View file

@ -24,78 +24,80 @@
#include <pc_file.h> #include <pc_file.h>
/* to make it easier to patch ... */ /* to make it easier to patch ... */
extern struct file *_curfil; extern struct file* _curfil;
static struct errm { static struct errm
{
int errno; int errno;
char *errmes; char* errmes;
} errors[] = { } errors[] = {
{ EARRAY, "array bound error"}, { EARRAY, "array bound error" },
{ ERANGE, "range bound error"}, { ERANGE, "range bound error" },
{ ESET, "set bound error"}, { ESET, "set bound error" },
{ EIOVFL, "integer overflow"}, { EIOVFL, "integer overflow" },
{ EFOVFL, "real overflow"}, { EFOVFL, "real overflow" },
{ EFUNFL, "real underflow"}, { EFUNFL, "real underflow" },
{ EIDIVZ, "divide by 0"}, { EIDIVZ, "divide by 0" },
{ EFDIVZ, "divide by 0.0"}, { EFDIVZ, "divide by 0.0" },
{ EIUND, "undefined integer"}, { EIUND, "undefined integer" },
{ EFUND, "undefined real"}, { EFUND, "undefined real" },
{ ECONV, "conversion error"}, { ECONV, "conversion error" },
{ ESTACK, "stack overflow"}, { ESTACK, "stack overflow" },
{ EHEAP, "heap overflow"}, { EHEAP, "heap overflow" },
{ EILLINS, "illegal instruction"}, { EILLINS, "illegal instruction" },
{ EODDZ, "illegal size argument"}, { EODDZ, "illegal size argument" },
{ ECASE, "case error"}, { ECASE, "case error" },
{ EMEMFLT, "addressing non existent memory"}, { EMEMFLT, "addressing non existent memory" },
{ EBADPTR, "bad pointer used"}, { EBADPTR, "bad pointer used" },
{ EBADPC, "program counter out of range"}, { EBADPC, "program counter out of range" },
{ EBADLAE, "bad argument of lae"}, { EBADLAE, "bad argument of lae" },
{ EBADMON, "bad monitor call"}, { EBADMON, "bad monitor call" },
{ EBADLIN, "argument if LIN too high"}, { EBADLIN, "argument if LIN too high" },
{ EBADGTO, "GTO descriptor error"}, { EBADGTO, "GTO descriptor error" },
{ EARGC, "more args expected" }, { EARGC, "more args expected" },
{ EEXP, "error in exp" }, { EEXP, "error in exp" },
{ ELOG, "error in ln" }, { ELOG, "error in ln" },
{ ESQT, "error in sqrt" }, { ESQT, "error in sqrt" },
{ EASS, "assertion failed" }, { EASS, "assertion failed" },
{ EPACK, "array bound error in pack" }, { EPACK, "array bound error in pack" },
{ EUNPACK, "array bound error in unpack" }, { EUNPACK, "array bound error in unpack" },
{ EMOD, "only positive j in 'i mod j'" }, { EMOD, "only positive j in 'i mod j'" },
{ EBADF, "file not yet open" }, { EBADF, "file not yet open" },
{ EFREE, "dispose error" }, { EFREE, "dispose error" },
{ EFUNASS, "function not assigned" }, { EFUNASS, "function not assigned" },
{ EWIDTH, "illegal field width" }, { EWIDTH, "illegal field width" },
{ EWRITEF, "not writable" }, { EWRITEF, "not writable" },
{ EREADF, "not readable" }, { EREADF, "not readable" },
{ EEOF, "end of file" }, { EEOF, "end of file" },
{ EFTRUNC, "truncated" }, { EFTRUNC, "truncated" },
{ ERESET, "reset error" }, { ERESET, "reset error" },
{ EREWR, "rewrite error" }, { EREWR, "rewrite error" },
{ ECLOSE, "close error" }, { ECLOSE, "close error" },
{ EREAD, "read error" }, { EREAD, "read error" },
{ EWRITE, "write error" }, { EWRITE, "write error" },
{ EDIGIT, "digit expected" }, { EDIGIT, "digit expected" },
{ EASCII, "non-ASCII char read" }, { EASCII, "non-ASCII char read" },
{ -1, 0} { -1, 0 }
}; };
extern int _pargc; extern int _pargc;
extern char **_pargv; extern char** _pargv;
extern char **_penvp; extern char** _penvp;
extern char *_hol0(); extern char* _hol0();
extern _trp(); extern _trp();
_catch(erno) unsigned erno; { _catch(erno) unsigned erno;
register struct errm *ep = &errors[0]; {
char *p,*q,*s,**qq; register struct errm* ep = &errors[0];
char *p, *q, *s, **qq;
char buf[20]; char buf[20];
unsigned i; unsigned i;
int j = erno; int j = erno;
char *pp[11]; char* pp[11];
char xbuf[100]; char xbuf[100];
qq = pp; qq = pp;
@ -104,52 +106,61 @@ _catch(erno) unsigned erno; {
else else
*qq++ = _pargv[0]; *qq++ = _pargv[0];
while (ep->errno != erno && ep->errmes != 0) ep++; while (ep->errno != erno && ep->errmes != 0)
ep++;
p = buf; p = buf;
s = xbuf; s = xbuf;
if (i = LINO) { if (i = LINO)
{
*qq++ = ", "; *qq++ = ", ";
do do
*p++ = i % 10 + '0'; *p++ = i % 10 + '0';
while (i /= 10); while (i /= 10);
while (p > buf) *s++ = *--p; while (p > buf)
*s++ = *--p;
} }
*s++ = ':'; *s++ = ':';
*s++ = ' '; *s++ = ' ';
*s++ = '\0'; *s++ = '\0';
*qq++ = xbuf; *qq++ = xbuf;
if ((erno & ~037) == 0140 && (_curfil->flags&0377)==MAGIC) { if ((erno & ~037) == 0140 && (_curfil->flags & 0377) == MAGIC)
{
/* file error */ /* file error */
*qq++ = "file "; *qq++ = "file ";
*qq++ = _curfil->fname; *qq++ = _curfil->fname;
*qq++ = ": "; *qq++ = ": ";
} }
if (ep->errmes) *qq++ = ep->errmes; if (ep->errmes)
else { *qq++ = ep->errmes;
else
{
*qq++ = "error number "; *qq++ = "error number ";
*qq++ = s; *qq++ = s;
p = buf; p = buf;
if (j < 0) { if (j < 0)
{
j = -j; j = -j;
*s++ = '-'; *s++ = '-';
} }
do do
*p++ = j % 10 + '0'; *p++ = j % 10 + '0';
while (j /= 10); while (j /= 10);
while (p > buf) *s++ = *--p; while (p > buf)
*s++ = *--p;
*s = 0; *s = 0;
} }
*qq++ = "\n"; *qq++ = "\n";
*qq = 0; *qq = 0;
qq = pp; qq = pp;
while (q = *qq++) { while (q = *qq++)
{
p = q; p = q;
while (*p) while (*p)
p++; p++;
if (write(2,q,(int)(p-q)) < 0) if (write(2, q, (int)(p - q)) < 0)
; ;
} }
_exit(erno+1); _exit(erno + 1);
error: error:
_trp(erno); _trp(erno);
} }

View file

@ -20,28 +20,30 @@
/* function clock:integer; extern; */ /* function clock:integer; extern; */
extern int _times(); extern int _times();
struct tbuf { struct tbuf
long utime; {
long stime; long utime;
long cutime; long stime;
long cstime; long cutime;
long cstime;
}; };
#ifndef EM_WSIZE #ifndef EM_WSIZE
#define EM_WSIZE _EM_WSIZE #define EM_WSIZE _EM_WSIZE
#endif #endif
int clock() { int clock()
{
struct tbuf t; struct tbuf t;
_times(&t); _times(&t);
return( (int)(t.utime + t.stime) & return ((int)(t.utime + t.stime) &
#if EM_WSIZE <= 2 #if EM_WSIZE <= 2
077777 077777
#else #else
0x7fffffffL 0x7fffffffL
#endif #endif
); );
} }

View file

@ -23,16 +23,18 @@
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern struct file *_curfil; extern struct file* _curfil;
extern _trp(); extern _trp();
extern _flush(); extern _flush();
extern _outcpt(); extern _outcpt();
_xcls(f) struct file *f; { _xcls(f) struct file* f;
{
if ((f->flags & WRBIT) == 0) if ((f->flags & WRBIT) == 0)
return; return;
if ((f->flags & (TXTBIT|ELNBIT)) == TXTBIT) { if ((f->flags & (TXTBIT | ELNBIT)) == TXTBIT)
{
#ifdef CPM #ifdef CPM
*f->ptr = '\r'; *f->ptr = '\r';
_outcpt(f); _outcpt(f);
@ -43,13 +45,14 @@ _xcls(f) struct file *f; {
_flush(f); _flush(f);
} }
_cls(f) struct file *f; { _cls(f) struct file* f;
{
#ifdef MAYBE #ifdef MAYBE
char *p; char* p;
#endif #endif
_curfil = f; _curfil = f;
if ((f->flags&0377) != MAGIC) if ((f->flags & 0377) != MAGIC)
return; return;
#ifdef MAYBE #ifdef MAYBE
p = f->bufadr; p = f->bufadr;

View file

@ -5,29 +5,28 @@
#include <float.h> #include <float.h>
#else #else
#include <math.h> #include <math.h>
#define DBL_MAX M_MAX_D #define DBL_MAX M_MAX_D
#endif #endif
static char *cvt(); static char* cvt();
#define NDIGITS 128 #define NDIGITS 128
char * char*
_ecvt(value, ndigit, decpt, sign) _ecvt(value, ndigit, decpt, sign) double value;
double value; int ndigit, *decpt, *sign;
int ndigit, *decpt, *sign;
{ {
return cvt(value, ndigit, decpt, sign, 1); return cvt(value, ndigit, decpt, sign, 1);
} }
char * char*
_fcvt(value, ndigit, decpt, sign) _fcvt(value, ndigit, decpt, sign) double value;
double value; int ndigit, *decpt, *sign;
int ndigit, *decpt, *sign;
{ {
return cvt(value, ndigit, decpt, sign, 0); return cvt(value, ndigit, decpt, sign, 0);
} }
static struct powers_of_10 { static struct powers_of_10
{
double pval; double pval;
double rpval; double rpval;
int exp; int exp;
@ -41,73 +40,92 @@ static struct powers_of_10 {
1.0e0, 1.0e0, 0 1.0e0, 1.0e0, 0
}; };
static char * static char*
cvt(value, ndigit, decpt, sign, ecvtflag) cvt(value, ndigit, decpt, sign, ecvtflag) double value;
double value; int ndigit, *decpt, *sign;
int ndigit, *decpt, *sign;
{ {
static char buf[NDIGITS+1]; static char buf[NDIGITS + 1];
register char *p = buf; register char* p = buf;
register char *pe; register char* pe;
if (ndigit < 0) ndigit = 0; if (ndigit < 0)
if (ndigit > NDIGITS) ndigit = NDIGITS; ndigit = 0;
if (ndigit > NDIGITS)
ndigit = NDIGITS;
pe = &buf[ndigit]; pe = &buf[ndigit];
buf[0] = '\0'; buf[0] = '\0';
*sign = 0; *sign = 0;
if (value < 0) { if (value < 0)
{
*sign = 1; *sign = 1;
value = -value; value = -value;
} }
*decpt = 0; *decpt = 0;
if (value >= DBL_MAX) { if (value >= DBL_MAX)
{
value = DBL_MAX; value = DBL_MAX;
} }
if (value != 0.0) { if (value != 0.0)
register struct powers_of_10 *pp = &p10[0]; {
register struct powers_of_10* pp = &p10[0];
if (value >= 10.0) do { if (value >= 10.0)
while (value >= pp->pval) { do
value *= pp->rpval; {
*decpt += pp->exp; while (value >= pp->pval)
} {
} while ((++pp)->exp > 0); value *= pp->rpval;
*decpt += pp->exp;
}
} while ((++pp)->exp > 0);
pp = &p10[0]; pp = &p10[0];
if (value < 1.0) do { if (value < 1.0)
while (value * pp->pval < 10.0) { do
value *= pp->pval; {
*decpt -= pp->exp; while (value * pp->pval < 10.0)
} {
} while ((++pp)->exp > 0); value *= pp->pval;
*decpt -= pp->exp;
}
} while ((++pp)->exp > 0);
(*decpt)++; /* because now value in [1.0, 10.0) */ (*decpt)++; /* because now value in [1.0, 10.0) */
} }
if (! ecvtflag) { if (!ecvtflag)
{
/* for fcvt() we need ndigit digits behind the dot */ /* for fcvt() we need ndigit digits behind the dot */
pe += *decpt; pe += *decpt;
if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS]; if (pe > &buf[NDIGITS])
pe = &buf[NDIGITS];
} }
while (p <= pe) { while (p <= pe)
{
*p++ = (int)value + '0'; *p++ = (int)value + '0';
value = 10.0 * (value - (int)value); value = 10.0 * (value - (int)value);
} }
if (pe >= buf) { if (pe >= buf)
{
p = pe; p = pe;
*p += 5; /* round of at the end */ *p += 5; /* round of at the end */
while (*p > '9') { while (*p > '9')
{
*p = '0'; *p = '0';
if (p > buf) ++*--p; if (p > buf)
else { ++*--p;
else
{
*p = '1'; *p = '1';
++*decpt; ++*decpt;
if (! ecvtflag) { if (!ecvtflag)
{
/* maybe add another digit at the end, /* maybe add another digit at the end,
because the point was shifted right because the point was shifted right
*/ */
if (pe > buf) *pe = '0'; if (pe > buf)
*pe = '0';
pe++; pe++;
} }
} }

View file

@ -18,14 +18,15 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
/* procedure diag(var f:text); */ /* procedure diag(var f:text); */
diag(f) struct file *f; { diag(f) struct file* f;
{
f->ptr = f->bufadr; f->ptr = f->bufadr;
f->flags = WRBIT|EOFBIT|ELNBIT|TXTBIT|MAGIC; f->flags = WRBIT | EOFBIT | ELNBIT | TXTBIT | MAGIC;
f->fname = "DIAG"; f->fname = "DIAG";
f->ufd = 2; f->ufd = 2;
f->size = 1; f->size = 1;

View file

@ -23,16 +23,17 @@
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern struct file *_curfil; extern struct file* _curfil;
extern _trp(); extern _trp();
extern _incpt(); extern _incpt();
int _efl(f) struct file *f; { int _efl(f) struct file* f;
{
_curfil = f; _curfil = f;
if ((f->flags & 0377) != MAGIC) if ((f->flags & 0377) != MAGIC)
_trp(EBADF); _trp(EBADF);
if ((f->flags & (WINDOW|WRBIT|EOFBIT)) == 0) if ((f->flags & (WINDOW | WRBIT | EOFBIT)) == 0)
_incpt(f); _incpt(f);
return((f->flags & EOFBIT) != 0); return ((f->flags & EOFBIT) != 0);
} }

View file

@ -18,16 +18,17 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
extern _rf(); extern _rf();
int _eln(f) struct file *f; { int _eln(f) struct file* f;
{
_rf(f); _rf(f);
if (f->flags & EOFBIT) if (f->flags & EOFBIT)
_trp(EEOF); _trp(EEOF);
return((f->flags & ELNBIT) != 0); return ((f->flags & ELNBIT) != 0);
} }

View file

@ -9,53 +9,56 @@
#define __NO_DEFS #define __NO_DEFS
#include <math.h> #include <math.h>
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
#if __STDC__ #if __STDC__
#include <float.h> #include <float.h>
#include <pc_math.h> #include <pc_math.h>
#define M_MIN_D DBL_MIN #define M_MIN_D DBL_MIN
#define M_MAX_D DBL_MAX #define M_MAX_D DBL_MAX
#define M_DMINEXP DBL_MIN_EXP #define M_DMINEXP DBL_MIN_EXP
#endif #endif
#undef HUGE #undef HUGE
#define HUGE 1e1000 #define HUGE 1e1000
static double static double
Ldexp(fl,exp) Ldexp(fl, exp) double fl;
double fl; int exp;
int exp;
{ {
extern double _fef(); extern double _fef();
int sign = 1; int sign = 1;
int currexp; int currexp;
if (fl<0) { if (fl < 0)
{
fl = -fl; fl = -fl;
sign = -1; sign = -1;
} }
fl = _fef(fl,&currexp); fl = _fef(fl, &currexp);
exp += currexp; exp += currexp;
if (exp > 0) { if (exp > 0)
while (exp>30) { {
fl *= (double) (1L << 30); while (exp > 30)
{
fl *= (double)(1L << 30);
exp -= 30; exp -= 30;
} }
fl *= (double) (1L << exp); fl *= (double)(1L << exp);
} }
else { else
while (exp<-30) { {
fl /= (double) (1L << 30); while (exp < -30)
{
fl /= (double)(1L << 30);
exp += 30; exp += 30;
} }
fl /= (double) (1L << -exp); fl /= (double)(1L << -exp);
} }
return sign * fl; return sign * fl;
} }
double double
_exp(x) _exp(x) double x;
double x;
{ {
/* Algorithm and coefficients from: /* Algorithm and coefficients from:
"Software manual for the elementary functions" "Software manual for the elementary functions"
@ -63,56 +66,65 @@ _exp(x)
*/ */
static double p[] = { static double p[] = {
0.25000000000000000000e+0, 0.25000000000000000000e+0,
0.75753180159422776666e-2, 0.75753180159422776666e-2,
0.31555192765684646356e-4 0.31555192765684646356e-4
}; };
static double q[] = { static double q[] = {
0.50000000000000000000e+0, 0.50000000000000000000e+0,
0.56817302698551221787e-1, 0.56817302698551221787e-1,
0.63121894374398503557e-3, 0.63121894374398503557e-3,
0.75104028399870046114e-6 0.75104028399870046114e-6
}; };
double xn, g; double xn, g;
int n; int n;
int negative = x < 0; int negative = x < 0;
if (x <= M_LN_MIN_D) { if (x <= M_LN_MIN_D)
g = M_MIN_D/4.0; {
g = M_MIN_D / 4.0;
if (g != 0.0) { if (g != 0.0)
{
/* unnormalized numbers apparently exist */ /* unnormalized numbers apparently exist */
if (x < (M_LN2 * (M_DMINEXP - 53))) return 0.0; if (x < (M_LN2 * (M_DMINEXP - 53)))
return 0.0;
} }
else { else
if (x < M_LN_MIN_D) return 0.0; {
if (x < M_LN_MIN_D)
return 0.0;
return M_MIN_D; return M_MIN_D;
} }
} }
if (x >= M_LN_MAX_D) { if (x >= M_LN_MAX_D)
if (x > M_LN_MAX_D) { {
if (x > M_LN_MAX_D)
{
_trp(EEXP); _trp(EEXP);
return HUGE; return HUGE;
} }
return M_MAX_D; return M_MAX_D;
} }
if (negative) x = -x; if (negative)
x = -x;
n = x * M_LOG2E + 0.5; /* 1/ln(2) = log2(e), 0.5 added for rounding */ n = x * M_LOG2E + 0.5; /* 1/ln(2) = log2(e), 0.5 added for rounding */
xn = n; xn = n;
{ {
double x1 = (long) x; double x1 = (long)x;
double x2 = x - x1; double x2 = x - x1;
g = ((x1-xn*0.693359375)+x2) - xn*(-2.1219444005469058277e-4); g = ((x1 - xn * 0.693359375) + x2) - xn * (-2.1219444005469058277e-4);
} }
if (negative) { if (negative)
{
g = -g; g = -g;
n = -n; n = -n;
} }
xn = g * g; xn = g * g;
x = g * POLYNOM2(xn, p); x = g * POLYNOM2(xn, p);
n += 1; n += 1;
return (Ldexp(0.5 + x/(POLYNOM3(xn, q) - x), n)); return (Ldexp(0.5 + x / (POLYNOM3(xn, q) - x), n));
} }

View file

@ -16,16 +16,17 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern _rf(); extern _rf();
extern _trp(); extern _trp();
_get(f) struct file *f; { _get(f) struct file* f;
{
_rf(f); _rf(f);
if (f->flags&EOFBIT) if (f->flags & EOFBIT)
_trp(EEOF); _trp(EEOF);
f->flags &= ~WINDOW; f->flags &= ~WINDOW;
} }

View file

@ -18,18 +18,19 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
extern struct file **_extfl; extern struct file** _extfl;
extern int _extflc; extern int _extflc;
extern _cls(); extern _cls();
extern _exit(); extern _exit();
_hlt(ecode) int ecode; { _hlt(ecode) int ecode;
{
int i; int i;
for (i = 0; i < _extflc; i++) for (i = 0; i < _extflc; i++)
if (_extfl[i] != (struct file *) 0) if (_extfl[i] != (struct file*)0)
_cls(_extfl[i]); _cls(_extfl[i]);
_exit(ecode); _exit(ecode);
} }

View file

@ -24,48 +24,58 @@
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
_incpt(f) struct file *f; { _incpt(f) struct file* f;
{
if (f->flags & EOFBIT) if (f->flags & EOFBIT)
_trp(EEOF); _trp(EEOF);
f->flags |= WINDOW; f->flags |= WINDOW;
f->flags &= ~ELNBIT; f->flags &= ~ELNBIT;
#ifdef CPM #ifdef CPM
do { do
{
#endif #endif
f->ptr += f->size; f->ptr += f->size;
if (f->count == 0) { if (f->count == 0)
f->ptr = f->bufadr; {
for(;;) { f->ptr = f->bufadr;
f->count=read(f->ufd,f->bufadr,f->buflen); for (;;)
if ( f->count<0 ) { {
if (errno != EINTR) _trp(EREAD) ; f->count = read(f->ufd, f->bufadr, f->buflen);
continue ; if (f->count < 0)
{
if (errno != EINTR)
_trp(EREAD);
continue;
}
break;
}
if (f->count == 0)
{
f->flags |= EOFBIT;
*f->ptr = '\0';
return;
} }
break ;
} }
if (f->count == 0) { if ((f->count -= f->size) < 0)
f->flags |= EOFBIT; _trp(EFTRUNC);
*f->ptr = '\0';
return;
}
}
if ((f->count -= f->size) < 0)
_trp(EFTRUNC);
#ifdef CPM #ifdef CPM
} while ((f->flags&TXTBIT) && *f->ptr == '\r'); } while ((f->flags & TXTBIT) && *f->ptr == '\r');
#endif #endif
if (f->flags & TXTBIT) { if (f->flags & TXTBIT)
{
if (*f->ptr & 0200) if (*f->ptr & 0200)
_trp(EASCII); _trp(EASCII);
if (*f->ptr == '\n') { if (*f->ptr == '\n')
{
f->flags |= ELNBIT; f->flags |= ELNBIT;
*f->ptr = ' '; *f->ptr = ' ';
} }
#ifdef CPM #ifdef CPM
if (*f->ptr == 26) { if (*f->ptr == 26)
{
f->flags |= EOFBIT; f->flags |= EOFBIT;
*f->ptr = 0; *f->ptr = 0;
} }

View file

@ -18,44 +18,52 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern (*_sig())(); extern (*_sig())();
extern _catch(); extern _catch();
struct file **_extfl; struct file** _extfl;
int _extflc; /* number of external files */ int _extflc; /* number of external files */
char *_m_lb; /* LB of _m_a_i_n */ char* _m_lb; /* LB of _m_a_i_n */
struct file *_curfil; /* points to file struct in case of errors */ struct file* _curfil; /* points to file struct in case of errors */
int _pargc; int _pargc;
char **_pargv; char** _pargv;
char **_penvp; char** _penvp;
int _fp_hook = 1; /* This is for Minix, but does not harm others */ int _fp_hook = 1; /* This is for Minix, but does not harm others */
_ini(args,c,p,mainlb) char *args,*mainlb; int c; struct file **p; { _ini(args, c, p, mainlb) char* args, *mainlb;
struct file *f; int c;
struct file** p;
{
struct file* f;
_pargc= *(int *)args; args += sizeof (int); _pargc = *(int*)args;
_pargv= *(char ***)args; args += sizeof (char **); args += sizeof(int);
_penvp= *(char ***)args; _pargv = *(char***)args;
args += sizeof(char**);
_penvp = *(char***)args;
_sig(_catch); _sig(_catch);
_extfl = p; _extfl = p;
_extflc = c; _extflc = c;
if( !c ) return; if (!c)
return;
_m_lb = mainlb; _m_lb = mainlb;
if ( (f = _extfl[0]) != (struct file *) 0) { if ((f = _extfl[0]) != (struct file*)0)
{
f->ptr = f->bufadr; f->ptr = f->bufadr;
f->flags = MAGIC|TXTBIT; f->flags = MAGIC | TXTBIT;
f->fname = "INPUT"; f->fname = "INPUT";
f->ufd = 0; f->ufd = 0;
f->size = 1; f->size = 1;
f->count = 0; f->count = 0;
f->buflen = PC_BUFLEN; f->buflen = PC_BUFLEN;
} }
if ( (f = _extfl[1]) != (struct file *) 0) { if ((f = _extfl[1]) != (struct file*)0)
{
f->ptr = f->bufadr; f->ptr = f->bufadr;
f->flags = MAGIC|TXTBIT|WRBIT|EOFBIT|ELNBIT; f->flags = MAGIC | TXTBIT | WRBIT | EOFBIT | ELNBIT;
f->fname = "OUTPUT"; f->fname = "OUTPUT";
f->ufd = 1; f->ufd = 1;
f->size = 1; f->size = 1;

View file

@ -16,11 +16,10 @@
#include <float.h> #include <float.h>
#endif #endif
#undef HUGE #undef HUGE
#define HUGE 1e1000 #define HUGE 1e1000
double double
_log(x) _log(x) double x;
double x;
{ {
/* Algorithm and coefficients from: /* Algorithm and coefficients from:
"Software manual for the elementary functions" "Software manual for the elementary functions"
@ -28,37 +27,41 @@ _log(x)
*/ */
static double a[] = { static double a[] = {
-0.64124943423745581147e2, -0.64124943423745581147e2,
0.16383943563021534222e2, 0.16383943563021534222e2,
-0.78956112887491257267e0 -0.78956112887491257267e0
}; };
static double b[] = { static double b[] = {
-0.76949932108494879777e3, -0.76949932108494879777e3,
0.31203222091924532844e3, 0.31203222091924532844e3,
-0.35667977739034646171e2, -0.35667977739034646171e2,
1.0 1.0
}; };
extern double _fef(); extern double _fef();
double znum, zden, z, w; double znum, zden, z, w;
int exponent; int exponent;
if (x <= 0) { if (x <= 0)
{
_trp(ELOG); _trp(ELOG);
return -HUGE; return -HUGE;
} }
x = _fef(x, &exponent); x = _fef(x, &exponent);
if (x > M_1_SQRT2) { if (x > M_1_SQRT2)
{
znum = (x - 0.5) - 0.5; znum = (x - 0.5) - 0.5;
zden = x * 0.5 + 0.5; zden = x * 0.5 + 0.5;
} }
else { else
{
znum = x - 0.5; znum = x - 0.5;
zden = znum * 0.5 + 0.5; zden = znum * 0.5 + 0.5;
exponent--; exponent--;
} }
z = znum/zden; w = z * z; z = znum / zden;
x = z + z * w * (POLYNOM2(w,a)/POLYNOM3(w,b)); w = z * z;
x = z + z * w * (POLYNOM2(w, a) / POLYNOM3(w, b));
z = exponent; z = exponent;
x += z * (-2.121944400546905827679e-4); x += z * (-2.121944400546905827679e-4);
return x + z * 0.693359375; return x + z * 0.693359375;

View file

@ -18,54 +18,68 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
int _mdi(j,i) int j,i; { int _mdi(j, i) int j, i;
{
if (j <= 0)
_trp(EMOD);
i = i % j;
if (i < 0)
i += j;
return(i);
}
long _mdil(j,i) long j,i; {
if (j <= 0) if (j <= 0)
_trp(EMOD); _trp(EMOD);
i = i % j; i = i % j;
if (i < 0) if (i < 0)
i += j; i += j;
return(i); return (i);
} }
int _dvi(j, i) unsigned int j,i; { long _mdil(j, i) long j, i;
{
if (j <= 0)
_trp(EMOD);
i = i % j;
if (i < 0)
i += j;
return (i);
}
int _dvi(j, i) unsigned int j, i;
{
int neg = 0; int neg = 0;
if ((int)j < 0) { if ((int)j < 0)
j = -(int)j; neg = 1; {
j = -(int)j;
neg = 1;
} }
if ((int)i < 0) { if ((int)i < 0)
i = -(int)i; neg = !neg; {
i = -(int)i;
neg = !neg;
} }
i = i / j; i = i / j;
if (neg) return -(int)i; if (neg)
return -(int)i;
return i; return i;
} }
long _dvil(j, i) unsigned long j,i; { long _dvil(j, i) unsigned long j, i;
{
int neg = 0; int neg = 0;
if ((long)j < 0) { if ((long)j < 0)
j = -(long)j; neg = 1; {
j = -(long)j;
neg = 1;
} }
if ((long)i < 0) { if ((long)i < 0)
i = -(long)i; neg = !neg; {
i = -(long)i;
neg = !neg;
} }
i = i / j; i = i / j;
if (neg) return -(long)i; if (neg)
return -(long)i;
return i; return i;
} }

View file

@ -18,16 +18,17 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
long _mdl(j,i) long j,i; { long _mdl(j, i) long j, i;
{
if (j <= 0) if (j <= 0)
_trp(EMOD); _trp(EMOD);
i = i % j; i = i % j;
if (i < 0) if (i < 0)
i += j; i += j;
return(i); return (i);
} }

View file

@ -2,7 +2,7 @@
#include <em_abs.h> #include <em_abs.h>
#include <pc_err.h> #include <pc_err.h>
extern void _trp(int); /* called on error */ extern void _trp(int); /* called on error */
void _new(int n, void** ptr) void _new(int n, void** ptr)
{ {

View file

@ -6,11 +6,12 @@
/* Author: Hans van Eck */ /* Author: Hans van Eck */
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
_nfa(bool) _nfa(bool)
{ {
if (! bool) _trp(EFUNASS); if (!bool)
_trp(EFUNASS);
} }

View file

@ -18,15 +18,16 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
extern _flush(); extern _flush();
/* procedure nobuff(var f:file of ?); */ /* procedure nobuff(var f:file of ?); */
nobuff(f) struct file *f; { nobuff(f) struct file* f;
{
if ((f->flags & (0377|WRBIT)) != (MAGIC|WRBIT)) if ((f->flags & (0377 | WRBIT)) != (MAGIC | WRBIT))
return; return;
_flush(f); _flush(f);
f->count = f->buflen = f->size; f->count = f->buflen = f->size;

View file

@ -16,8 +16,9 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
notext(f) struct file *f; { notext(f) struct file* f;
{
f->flags &= ~TXTBIT; f->flags &= ~TXTBIT;
} }

View file

@ -23,20 +23,22 @@
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern struct file **_extfl; extern struct file** _extfl;
extern int _extflc; extern int _extflc;
extern struct file *_curfil; extern struct file* _curfil;
extern int _pargc; extern int _pargc;
extern char **_pargv; extern char** _pargv;
extern char **_penvp; extern char** _penvp;
extern _cls(); extern _cls();
extern _xcls(); extern _xcls();
extern _trp(); extern _trp();
static int tmpfil() { static int tmpfil()
{
static char namebuf[] = "/tmp/plf.xxxxx"; static char namebuf[] = "/tmp/plf.xxxxx";
int i; char *p,*q; int i;
char *p, *q;
i = getpid(); i = getpid();
p = namebuf; p = namebuf;
@ -45,70 +47,88 @@ static int tmpfil() {
*q++ = (i & 07) + '0'; *q++ = (i & 07) + '0';
while (i >>= 3); while (i >>= 3);
*q = '\0'; *q = '\0';
if ((i = creat(p,0644)) < 0) if ((i = creat(p, 0644)) < 0)
if ((i = creat(p += 4,0644)) < 0) if ((i = creat(p += 4, 0644)) < 0)
if ((i = creat(p += 5,0644)) < 0) if ((i = creat(p += 5, 0644)) < 0)
goto error; goto error;
if (close(i) != 0) if (close(i) != 0)
goto error; goto error;
if ((i = open(p,2)) < 0) if ((i = open(p, 2)) < 0)
goto error; goto error;
if (remove(p) != 0) if (remove(p) != 0)
error: _trp(EREWR); error:
return(i); _trp(EREWR);
return (i);
} }
static int initfl(descr,sz,f) int descr; int sz; struct file *f; { static int initfl(descr, sz, f) int descr;
int sz;
struct file* f;
{
int i; int i;
_curfil = f; _curfil = f;
if (sz == 0) { if (sz == 0)
{
sz++; sz++;
descr |= TXTBIT; descr |= TXTBIT;
} }
for (i=0; i<_extflc; i++) for (i = 0; i < _extflc; i++)
if (f == _extfl[i]) if (f == _extfl[i])
break; break;
if (i >= _extflc) { /* local file */ if (i >= _extflc)
{ /* local file */
f->fname = "LOCAL"; f->fname = "LOCAL";
if ((descr & WRBIT) == 0 && (f->flags & 0377) == MAGIC) { if ((descr & WRBIT) == 0 && (f->flags & 0377) == MAGIC)
{
_xcls(f); _xcls(f);
if (lseek(f->ufd,(long)0,0) == -1) if (lseek(f->ufd, (long)0, 0) == -1)
_trp(ERESET); _trp(ERESET);
} else { }
else
{
_cls(f); _cls(f);
f->ufd = tmpfil(); f->ufd = tmpfil();
} }
} else { /* external file */ }
else
{ /* external file */
if (--i <= 0) if (--i <= 0)
return(0); return (0);
if (i >= _pargc) if (i >= _pargc)
_trp(EARGC); _trp(EARGC);
f->fname = _pargv[i]; f->fname = _pargv[i];
_cls(f); _cls(f);
if ((descr & WRBIT) == 0) { if ((descr & WRBIT) == 0)
if ((f->ufd = open(f->fname,0)) < 0) {
if ((f->ufd = open(f->fname, 0)) < 0)
_trp(ERESET); _trp(ERESET);
} else { }
if ((f->ufd = creat(f->fname,0644)) < 0) else
{
if ((f->ufd = creat(f->fname, 0644)) < 0)
_trp(EREWR); _trp(EREWR);
} }
} }
f->buflen = (sz>PC_BUFLEN ? sz : PC_BUFLEN-PC_BUFLEN%sz); f->buflen = (sz > PC_BUFLEN ? sz : PC_BUFLEN - PC_BUFLEN % sz);
f->size = sz; f->size = sz;
f->ptr = f->bufadr; f->ptr = f->bufadr;
f->flags = descr; f->flags = descr;
return(1); return (1);
} }
_opn(sz,f) int sz; struct file *f; { _opn(sz, f) int sz;
struct file* f;
{
if (initfl(MAGIC,sz,f)) if (initfl(MAGIC, sz, f))
f->count = 0; f->count = 0;
} }
_cre(sz,f) int sz; struct file *f; { _cre(sz, f) int sz;
struct file* f;
{
if (initfl(WRBIT|EOFBIT|ELNBIT|MAGIC,sz,f)) if (initfl(WRBIT | EOFBIT | ELNBIT | MAGIC, sz, f))
f->count = f->buflen; f->count = f->buflen;
} }

View file

@ -24,23 +24,25 @@
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
_flush(f) struct file *f; { _flush(f) struct file* f;
int i,n; {
int i, n;
f->ptr = f->bufadr; f->ptr = f->bufadr;
n = f->buflen - f->count; n = f->buflen - f->count;
if (n <= 0) if (n <= 0)
return; return;
f->count = f->buflen; f->count = f->buflen;
if ((i = write(f->ufd,f->bufadr,n)) < 0 && errno == EINTR) if ((i = write(f->ufd, f->bufadr, n)) < 0 && errno == EINTR)
return; return;
if (i != n) if (i != n)
_trp(EWRITE); _trp(EWRITE);
} }
_outcpt(f) struct file *f; { _outcpt(f) struct file* f;
{
f->flags &= ~ELNBIT; f->flags &= ~ELNBIT;
f->ptr += f->size; f->ptr += f->size;

View file

@ -18,44 +18,51 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
#define assert(x) /* nothing */ #define assert(x) /* nothing */
#ifndef EM_WSIZE #ifndef EM_WSIZE
#define EM_WSIZE _EM_WSIZE #define EM_WSIZE _EM_WSIZE
#endif #endif
struct descr { struct descr
int low; {
int diff; int low;
int size; int diff;
int size;
}; };
_pac(ad,zd,zp,i,ap) int i; struct descr *ad,*zd; char *zp,*ap; { _pac(ad, zd, zp, i, ap) int i;
struct descr *ad, *zd;
char *zp, *ap;
{
if (zd->diff > ad->diff || if (zd->diff > ad->diff || (i -= ad->low) < 0 || (i + zd->diff) > ad->diff)
(i -= ad->low) < 0 ||
(i+zd->diff) > ad->diff)
_trp(EPACK); _trp(EPACK);
ap += (i * ad->size); ap += (i * ad->size);
i = (zd->diff + 1) * zd->size; i = (zd->diff + 1) * zd->size;
if (zd->size == 1) { if (zd->size == 1)
int *aptmp = (int *)ap; {
int* aptmp = (int*)ap;
assert(ad->size == EM_WSIZE); assert(ad->size == EM_WSIZE);
while (--i >= 0) while (--i >= 0)
*zp++ = *aptmp++; *zp++ = *aptmp++;
#if EM_WSIZE > 2 #if EM_WSIZE > 2
} else if (zd->size == 2) { }
int *aptmp = (int *)ap; else if (zd->size == 2)
short *zptmp = (short *) zp; {
int* aptmp = (int*)ap;
short* zptmp = (short*)zp;
assert(ad->size == EM_WSIZE); assert(ad->size == EM_WSIZE);
while (--i >= 0) while (--i >= 0)
*zptmp++ = *aptmp++; *zptmp++ = *aptmp++;
#endif #endif
} else { }
else
{
assert(ad->size == zd->size); assert(ad->size == zd->size);
while (--i >= 0) while (--i >= 0)
*zp++ = *ap++; *zp++ = *ap++;

View file

@ -16,12 +16,13 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
extern _cls(); extern _cls();
/* procedure pclose(var f:file of ??); */ /* procedure pclose(var f:file of ??); */
pclose(f) struct file *f; { pclose(f) struct file* f;
{
_cls(f); _cls(f);
} }

View file

@ -18,24 +18,26 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <unistd.h> #include <unistd.h>
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern _cls(); extern _cls();
extern _trp(); extern _trp();
/* procedure pcreat(var f:text; s:string); */ /* procedure pcreat(var f:text; s:string); */
pcreat(f,s) struct file *f; char *s; { pcreat(f, s) struct file* f;
char* s;
{
_cls(f); /* initializes _curfil */ _cls(f); /* initializes _curfil */
f->ptr = f->bufadr; f->ptr = f->bufadr;
f->flags = WRBIT|EOFBIT|ELNBIT|TXTBIT|MAGIC; f->flags = WRBIT | EOFBIT | ELNBIT | TXTBIT | MAGIC;
f->fname = s; f->fname = s;
f->size = 1; f->size = 1;
f->count = PC_BUFLEN; f->count = PC_BUFLEN;
f->buflen = PC_BUFLEN; f->buflen = PC_BUFLEN;
if ((f->ufd = creat(s,0644)) < 0) if ((f->ufd = creat(s, 0644)) < 0)
_trp(EREWR); _trp(EREWR);
} }

View file

@ -18,18 +18,19 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
extern struct file **_extfl; extern struct file** _extfl;
extern _wrs(); extern _wrs();
extern _wrz(); extern _wrz();
extern _wln(); extern _wln();
procentry(name) char *name; { procentry(name) char* name;
struct file *f; {
struct file* f;
f = _extfl[1]; f = _extfl[1];
_wrs(5,"call ",f); _wrs(5, "call ", f);
_wrz(name,f); _wrz(name, f);
_wln(f); _wln(f);
} }

View file

@ -20,6 +20,7 @@
#include <errno.h> #include <errno.h>
int perrno() { int perrno()
return(errno); {
return (errno);
} }

View file

@ -16,18 +16,19 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
extern struct file **_extfl; extern struct file** _extfl;
extern _wrs(); extern _wrs();
extern _wrz(); extern _wrz();
extern _wln(); extern _wln();
procexit(name) char *name; { procexit(name) char* name;
struct file *f; {
struct file* f;
f = _extfl[1]; f = _extfl[1];
_wrs(5,"exit ",f); _wrs(5, "exit ", f);
_wrz(name,f); _wrz(name, f);
_wln(f); _wln(f);
} }

View file

@ -18,24 +18,26 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern _cls(); extern _cls();
extern _trp(); extern _trp();
extern int _open(); extern int _open();
/* procedure popen(var f:text; s:string); */ /* procedure popen(var f:text; s:string); */
popen(f,s) struct file *f; char *s; { popen(f, s) struct file* f;
char* s;
{
_cls(f); /* initializes _curfil */ _cls(f); /* initializes _curfil */
f->ptr = f->bufadr; f->ptr = f->bufadr;
f->flags = TXTBIT|MAGIC; f->flags = TXTBIT | MAGIC;
f->fname = s; f->fname = s;
f->size = 1; f->size = 1;
f->count = 0; f->count = 0;
f->buflen = PC_BUFLEN; f->buflen = PC_BUFLEN;
if ((f->ufd = _open(s,0)) < 0) if ((f->ufd = _open(s, 0)) < 0)
_trp(ERESET); _trp(ERESET);
} }

View file

@ -16,12 +16,13 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
extern _wf(); extern _wf();
extern _outcpt(); extern _outcpt();
_put(f) struct file *f; { _put(f) struct file* f;
{
_wf(f); _wf(f);
_outcpt(f); _outcpt(f);
} }

View file

@ -6,20 +6,19 @@
/* Author: Hans van Eck */ /* Author: Hans van Eck */
#include <em_abs.h> #include <em_abs.h>
extern _trp(); extern _trp();
struct array_descr { struct array_descr
int lbound;
unsigned n_elts_min_one;
unsigned size; /* doesn't really matter */
};
_rcka(descr, index)
struct array_descr *descr;
{ {
if( index < descr->lbound || int lbound;
index > (int) descr->n_elts_min_one + descr->lbound ) unsigned n_elts_min_one;
unsigned size; /* doesn't really matter */
};
_rcka(descr, index) struct array_descr* descr;
{
if (index < descr->lbound || index > (int)descr->n_elts_min_one + descr->lbound)
_trp(EARRAY); _trp(EARRAY);
} }

View file

@ -16,16 +16,17 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
extern _rf(); extern _rf();
extern _incpt(); extern _incpt();
int _rdc(f) struct file *f; { int _rdc(f) struct file* f;
{
int c; int c;
_rf(f); _rf(f);
c = *f->ptr; c = *f->ptr;
_incpt(f); _incpt(f);
return(c); return (c);
} }

View file

@ -18,61 +18,68 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
extern _rf(); extern _rf();
extern _incpt(); extern _incpt();
_skipsp(f) struct file *f; { _skipsp(f) struct file* f;
{
while ((*f->ptr == ' ') || (*f->ptr == '\t')) while ((*f->ptr == ' ') || (*f->ptr == '\t'))
_incpt(f); _incpt(f);
} }
int _getsig(f) struct file *f; { int _getsig(f) struct file* f;
{
int sign; int sign;
if ((sign = (*f->ptr == '-')) || *f->ptr == '+') if ((sign = (*f->ptr == '-')) || *f->ptr == '+')
_incpt(f); _incpt(f);
return(sign); return (sign);
} }
int _fstdig(f) struct file *f; { int _fstdig(f) struct file* f;
{
int ch; int ch;
ch = *f->ptr - '0'; ch = *f->ptr - '0';
if ((unsigned) ch > 9) { if ((unsigned)ch > 9)
{
_trp(EDIGIT); _trp(EDIGIT);
ch = 0; ch = 0;
} }
return(ch); return (ch);
} }
int _nxtdig(f) struct file *f; { int _nxtdig(f) struct file* f;
{
int ch; int ch;
_incpt(f); _incpt(f);
ch = *f->ptr - '0'; ch = *f->ptr - '0';
if ((unsigned) ch > 9) if ((unsigned)ch > 9)
return(-1); return (-1);
return(ch); return (ch);
} }
int _getint(f) struct file *f; { int _getint(f) struct file* f;
int is_signed,i,ch; {
int is_signed, i, ch;
is_signed = _getsig(f); is_signed = _getsig(f);
ch = _fstdig(f); ch = _fstdig(f);
i = 0; i = 0;
do do
i = i*10 - ch; i = i * 10 - ch;
while ((ch = _nxtdig(f)) >= 0); while ((ch = _nxtdig(f)) >= 0);
return(is_signed ? i : -i); return (is_signed ? i : -i);
} }
int _rdi(f) struct file *f; { int _rdi(f) struct file* f;
{
_rf(f); _rf(f);
_skipsp(f); _skipsp(f);
return(_getint(f)); return (_getint(f));
} }

View file

@ -18,16 +18,18 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
extern _rf(); extern _rf();
extern _skipsp(); extern _skipsp();
extern int _getsig(); extern int _getsig();
extern int _fstdig(); extern int _fstdig();
extern int _nxtdig(); extern int _nxtdig();
long _rdl(f) struct file *f; { long _rdl(f) struct file* f;
int is_signed,ch; long l; {
int is_signed, ch;
long l;
_rf(f); _rf(f);
_skipsp(f); _skipsp(f);
@ -35,7 +37,7 @@ long _rdl(f) struct file *f; {
ch = _fstdig(f); ch = _fstdig(f);
l = 0; l = 0;
do do
l = l*10 - ch; l = l * 10 - ch;
while ((ch = _nxtdig(f)) >= 0); while ((ch = _nxtdig(f)) >= 0);
return(is_signed ? l : -l); return (is_signed ? l : -l);
} }

View file

@ -18,31 +18,35 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_file.h> #include <pc_file.h>
#define BIG 1e17 #define BIG 1e17
extern _rf(); extern _rf();
extern _incpt(); extern _incpt();
extern _skipsp(); extern _skipsp();
extern int _getsig(); extern int _getsig();
extern int _getint(); extern int _getint();
extern int _fstdig(); extern int _fstdig();
extern int _nxtdig(); extern int _nxtdig();
static double r; static double r;
static int pow10; static int pow10;
static dig(ch) int ch; { static dig(ch) int ch;
{
if (r>BIG) if (r > BIG)
pow10++; pow10++;
else else
r = r*10.0 + ch; r = r * 10.0 + ch;
} }
double _rdr(f) struct file *f; { double _rdr(f) struct file* f;
int i; double e; int is_signed,ch; {
int i;
double e;
int is_signed, ch;
r = 0; r = 0;
pow10 = 0; pow10 = 0;
@ -53,15 +57,18 @@ double _rdr(f) struct file *f; {
do do
dig(ch); dig(ch);
while ((ch = _nxtdig(f)) >= 0); while ((ch = _nxtdig(f)) >= 0);
if (*f->ptr == '.') { if (*f->ptr == '.')
{
_incpt(f); _incpt(f);
ch = _fstdig(f); ch = _fstdig(f);
do { do
{
dig(ch); dig(ch);
pow10--; pow10--;
} while ((ch = _nxtdig(f)) >= 0); } while ((ch = _nxtdig(f)) >= 0);
} }
if ((*f->ptr == 'e') || (*f->ptr == 'E')) { if ((*f->ptr == 'e') || (*f->ptr == 'E'))
{
_incpt(f); _incpt(f);
pow10 += _getint(f); pow10 += _getint(f);
} }
@ -70,9 +77,9 @@ double _rdr(f) struct file *f; {
e = 1.0; e = 1.0;
while (--i >= 0) while (--i >= 0)
e *= 10.0; e *= 10.0;
if (pow10<0) if (pow10 < 0)
r /= e; r /= e;
else else
r *= e; r *= e;
return(is_signed? -r : r); return (is_signed ? -r : r);
} }

View file

@ -16,17 +16,18 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern struct file *_curfil; extern struct file* _curfil;
extern _trp(); extern _trp();
extern _incpt(); extern _incpt();
_rf(f) struct file *f; { _rf(f) struct file* f;
{
_curfil = f; _curfil = f;
if ((f->flags&0377) != MAGIC) if ((f->flags & 0377) != MAGIC)
_trp(EBADF); _trp(EBADF);
if (f->flags & WRBIT) if (f->flags & WRBIT)
_trp(EREADF); _trp(EREADF);

View file

@ -16,12 +16,13 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
extern _rf(); extern _rf();
extern _incpt(); extern _incpt();
_rln(f) struct file *f; { _rln(f) struct file* f;
{
_rf(f); _rf(f);
while ((f->flags & ELNBIT) == 0) while ((f->flags & ELNBIT) == 0)

View file

@ -16,6 +16,7 @@
* *
*/ */
double _rnd(r) double r; { double _rnd(r) double r;
return(r + (r<0 ? -0.5 : 0.5)); {
return (r + (r < 0 ? -0.5 : 0.5));
} }

View file

@ -15,8 +15,7 @@
#endif #endif
static double static double
sinus(x, cos_flag) sinus(x, cos_flag) double x;
double x;
{ {
/* Algorithm and coefficients from: /* Algorithm and coefficients from:
"Software manual for the elementary functions" "Software manual for the elementary functions"
@ -25,34 +24,37 @@ sinus(x, cos_flag)
static double r[] = { static double r[] = {
-0.16666666666666665052e+0, -0.16666666666666665052e+0,
0.83333333333331650314e-2, 0.83333333333331650314e-2,
-0.19841269841201840457e-3, -0.19841269841201840457e-3,
0.27557319210152756119e-5, 0.27557319210152756119e-5,
-0.25052106798274584544e-7, -0.25052106798274584544e-7,
0.16058936490371589114e-9, 0.16058936490371589114e-9,
-0.76429178068910467734e-12, -0.76429178068910467734e-12,
0.27204790957888846175e-14 0.27204790957888846175e-14
}; };
double xsqr; double xsqr;
double y; double y;
int neg = 0; int neg = 0;
if (x < 0) { if (x < 0)
{
x = -x; x = -x;
neg = 1; neg = 1;
} }
if (cos_flag) { if (cos_flag)
{
neg = 0; neg = 0;
y = M_PI_2 + x; y = M_PI_2 + x;
} }
else y = x; else
y = x;
/* ??? avoid loss of significance, if y is too large, error ??? */ /* ??? avoid loss of significance, if y is too large, error ??? */
y = y * M_1_PI + 0.5; y = y * M_1_PI + 0.5;
/* Use extended precision to calculate reduced argument. /* Use extended precision to calculate reduced argument.
Here we used 12 bits of the mantissa for a1. Here we used 12 bits of the mantissa for a1.
Also split x in integer part x1 and fraction part x2. Also split x in integer part x1 and fraction part x2.
*/ */
@ -60,11 +62,13 @@ sinus(x, cos_flag)
#define A2 -8.908910206761537356617e-6 #define A2 -8.908910206761537356617e-6
{ {
double x1, x2; double x1, x2;
extern double _fif(); extern double _fif();
_fif(y, 1.0, &y); _fif(y, 1.0, &y);
if (_fif(y, 0.5, &x1)) neg = !neg; if (_fif(y, 0.5, &x1))
if (cos_flag) y -= 0.5; neg = !neg;
if (cos_flag)
y -= 0.5;
x2 = _fif(x, 1.0, &x1); x2 = _fif(x, 1.0, &x1);
x = x1 - y * A1; x = x1 - y * A1;
x += x2; x += x2;
@ -73,7 +77,8 @@ sinus(x, cos_flag)
#undef A2 #undef A2
} }
if (x < 0) { if (x < 0)
{
neg = !neg; neg = !neg;
x = -x; x = -x;
} }
@ -86,16 +91,15 @@ sinus(x, cos_flag)
} }
double double
_sin(x) _sin(x) double x;
double x;
{ {
return sinus(x, 0); return sinus(x, 0);
} }
double double
_cos(x) _cos(x) double x;
double x;
{ {
if (x < 0) x = -x; if (x < 0)
x = -x;
return sinus(x, 1); return sinus(x, 1);
} }

View file

@ -9,63 +9,70 @@
#define __NO_DEFS #define __NO_DEFS
#include <math.h> #include <math.h>
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
#define NITER 5 #define NITER 5
static double static double
Ldexp(fl,exp) Ldexp(fl, exp) double fl;
double fl; int exp;
int exp;
{ {
extern double _fef(); extern double _fef();
int sign = 1; int sign = 1;
int currexp; int currexp;
if (fl<0) { if (fl < 0)
{
fl = -fl; fl = -fl;
sign = -1; sign = -1;
} }
fl = _fef(fl,&currexp); fl = _fef(fl, &currexp);
exp += currexp; exp += currexp;
if (exp > 0) { if (exp > 0)
while (exp>30) { {
fl *= (double) (1L << 30); while (exp > 30)
{
fl *= (double)(1L << 30);
exp -= 30; exp -= 30;
} }
fl *= (double) (1L << exp); fl *= (double)(1L << exp);
} }
else { else
while (exp<-30) { {
fl /= (double) (1L << 30); while (exp < -30)
{
fl /= (double)(1L << 30);
exp += 30; exp += 30;
} }
fl /= (double) (1L << -exp); fl /= (double)(1L << -exp);
} }
return sign * fl; return sign * fl;
} }
double double
_sqt(x) _sqt(x) double x;
double x;
{ {
extern double _fef(); extern double _fef();
int exponent; int exponent;
double val; double val;
if (x <= 0) { if (x <= 0)
if (x < 0) _trp(ESQT); {
if (x < 0)
_trp(ESQT);
return 0; return 0;
} }
val = _fef(x, &exponent); val = _fef(x, &exponent);
if (exponent & 1) { if (exponent & 1)
{
exponent--; exponent--;
val *= 2; val *= 2;
} }
val = Ldexp(val + 1.0, exponent/2 - 1); val = Ldexp(val + 1.0, exponent / 2 - 1);
/* was: val = (val + 1.0)/2.0; val = Ldexp(val, exponent/2); */ /* was: val = (val + 1.0)/2.0; val = Ldexp(val, exponent/2); */
for (exponent = NITER - 1; exponent >= 0; exponent--) { for (exponent = NITER - 1; exponent >= 0; exponent--)
{
val = (val + x / val) / 2.0; val = (val + x / val) / 2.0;
} }
return val; return val;

View file

@ -18,43 +18,49 @@
/* function strbuf(var b:charbuf):string; */ /* function strbuf(var b:charbuf):string; */
char *strbuf(s) char *s; { char* strbuf(s) char* s;
return(s); {
return (s);
} }
/* function strtobuf(s:string; var b:charbuf; blen:integer):integer; */ /* function strtobuf(s:string; var b:charbuf; blen:integer):integer; */
int strtobuf(s,b,l) char *s,*b; { int strtobuf(s, b, l) char *s, *b;
{
int i; int i;
i = 0; i = 0;
while (--l>=0) { while (--l >= 0)
{
if ((*b++ = *s++) == 0) if ((*b++ = *s++) == 0)
break; break;
i++; i++;
} }
return(i); return (i);
} }
/* function strlen(s:string):integer; */ /* function strlen(s:string):integer; */
int strlen(s) char *s; { int strlen(s) char* s;
{
int i; int i;
i = 0; i = 0;
while (*s++) while (*s++)
i++; i++;
return(i); return (i);
} }
/* function strfetch(s:string; i:integer):char; */ /* function strfetch(s:string; i:integer):char; */
int strfetch(s,i) char *s; { int strfetch(s, i) char* s;
return(s[i-1]); {
return (s[i - 1]);
} }
/* procedure strstore(s:string; i:integer; c:char); */ /* procedure strstore(s:string; i:integer; c:char); */
strstore(s,i,c) char *s; { strstore(s, i, c) char* s;
s[i-1] = c; {
s[i - 1] = c;
} }

View file

@ -18,46 +18,58 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_err.h> #include <pc_err.h>
extern _trp(); extern _trp();
#define assert(x) /* nothing */ #define assert(x) /* nothing */
#ifndef EM_WSIZE #ifndef EM_WSIZE
#define EM_WSIZE _EM_WSIZE #define EM_WSIZE _EM_WSIZE
#endif #endif
struct descr { struct descr
int low; {
int diff; int low;
int size; int diff;
int size;
}; };
_unp(ad,zd,i,ap,zp,noext) int i; struct descr *ad,*zd; char *ap,*zp; int noext; { _unp(ad, zd, i, ap, zp, noext) int i;
struct descr *ad, *zd;
char *ap, *zp;
int noext;
{
if (zd->diff > ad->diff || if (zd->diff > ad->diff || (i -= ad->low) < 0 || (i + zd->diff) > ad->diff)
(i -= ad->low) < 0 ||
(i+zd->diff) > ad->diff)
_trp(EUNPACK); _trp(EUNPACK);
ap += (i * ad->size); ap += (i * ad->size);
i = (zd->diff + 1) * zd->size; i = (zd->diff + 1) * zd->size;
if (zd->size == 1) { if (zd->size == 1)
int *aptmp = (int *) ap; {
int* aptmp = (int*)ap;
assert(ad->size == EM_WSIZE); assert(ad->size == EM_WSIZE);
while (--i >= 0) while (--i >= 0)
if (noext) *aptmp++ = *zp++ & 0377; if (noext)
else *aptmp++ = *zp++; *aptmp++ = *zp++ & 0377;
else
*aptmp++ = *zp++;
#if EM_WSIZE > 2 #if EM_WSIZE > 2
} else if (zd->size == 2) { }
int *aptmp = (int *) ap; else if (zd->size == 2)
short *zptmp = (short *) zp; {
int* aptmp = (int*)ap;
short* zptmp = (short*)zp;
assert(ad->size == EM_WSIZE); assert(ad->size == EM_WSIZE);
while (--i >= 0) while (--i >= 0)
if (noext) *aptmp++ = *zptmp++ & 0177777; if (noext)
else *aptmp++ = *zptmp++; *aptmp++ = *zptmp++ & 0177777;
else
*aptmp++ = *zptmp++;
#endif #endif
} else { }
else
{
assert(ad->size == zd->size); assert(ad->size == zd->size);
while (--i >= 0) while (--i >= 0)
*ap++ = *zp++; *ap++ = *zp++;

View file

@ -21,6 +21,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
int uread(fd,b,n) char *b; int fd,n; { int uread(fd, b, n) char* b;
return(read(fd,b,n)); int fd, n;
{
return (read(fd, b, n));
} }

View file

@ -21,6 +21,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
int uwrite(fd,b,n) char *b; int fd,n; { int uwrite(fd, b, n) char* b;
return(write(fd,b,n)); int fd, n;
{
return (write(fd, b, n));
} }

View file

@ -16,15 +16,16 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
extern struct file *_curfil; extern struct file* _curfil;
extern _incpt(); extern _incpt();
char *_wdw(f) struct file *f; { char* _wdw(f) struct file* f;
{
_curfil = f; _curfil = f;
if ((f->flags & (WINDOW|WRBIT|0377)) == MAGIC) if ((f->flags & (WINDOW | WRBIT | 0377)) == MAGIC)
_incpt(f); _incpt(f);
return(f->ptr); return (f->ptr);
} }

View file

@ -16,16 +16,17 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
#include <pc_err.h> #include <pc_err.h>
extern struct file *_curfil; extern struct file* _curfil;
extern _trp(); extern _trp();
_wf(f) struct file *f; { _wf(f) struct file* f;
{
_curfil = f; _curfil = f;
if ((f->flags&0377) != MAGIC) if ((f->flags & 0377) != MAGIC)
_trp(EBADF); _trp(EBADF);
if ((f->flags & WRBIT) == 0) if ((f->flags & WRBIT) == 0)
_trp(EWRITEF); _trp(EWRITEF);

View file

@ -16,26 +16,30 @@
* *
*/ */
#include <pc_file.h> #include <pc_file.h>
extern _wf(); extern _wf();
extern _outcpt(); extern _outcpt();
_wrc(c,f) int c; struct file *f; { _wrc(c, f) int c;
struct file* f;
{
*f->ptr = c; *f->ptr = c;
_wf(f); _wf(f);
_outcpt(f); _outcpt(f);
} }
_wln(f) struct file *f; { _wln(f) struct file* f;
{
#ifdef CPM #ifdef CPM
_wrc('\r',f); _wrc('\r', f);
#endif #endif
_wrc('\n',f); _wrc('\n', f);
f->flags |= ELNBIT; f->flags |= ELNBIT;
} }
_pag(f) struct file *f; { _pag(f) struct file* f;
_wrc('\014',f); {
_wrc('\014', f);
f->flags |= ELNBIT; f->flags |= ELNBIT;
} }

View file

@ -18,36 +18,42 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_err.h> #include <pc_err.h>
#include <pc_file.h> #include <pc_file.h>
extern _wstrin(); extern _wstrin();
extern char *_fcvt(); extern char* _fcvt();
#define assert(x) /* nothing */ #define assert(x) /* nothing */
#if __STDC__ #if __STDC__
#include <float.h> #include <float.h>
#define HUGE_DIG DBL_MAX_10_EXP /* log10(maxreal) */ #define HUGE_DIG DBL_MAX_10_EXP /* log10(maxreal) */
#else #else
#define HUGE_DIG 400 /* log10(maxreal) */ #define HUGE_DIG 400 /* log10(maxreal) */
#endif #endif
#define PREC_DIG 80 /* the maximum digits returned by _fcvt() */ #define PREC_DIG 80 /* the maximum digits returned by _fcvt() */
#define FILL_CHAR '0' /* char printed if all of _fcvt() used */ #define FILL_CHAR '0' /* char printed if all of _fcvt() used */
#define BUFSIZE HUGE_DIG + PREC_DIG + 3 #define BUFSIZE HUGE_DIG + PREC_DIG + 3
_wrf(n,w,r,f) int n,w; double r; struct file *f; { _wrf(n, w, r, f) int n, w;
char *p,*b; int s,d; char buf[BUFSIZE]; double r;
struct file* f;
{
char *p, *b;
int s, d;
char buf[BUFSIZE];
if ( n < 0 || w < 0) _trp(EWIDTH); if (n < 0 || w < 0)
_trp(EWIDTH);
p = buf; p = buf;
if (n > PREC_DIG) if (n > PREC_DIG)
n = PREC_DIG; n = PREC_DIG;
b = _fcvt(r,n,&d,&s); b = _fcvt(r, n, &d, &s);
assert(abs(d) <= HUGE_DIG); assert(abs(d) <= HUGE_DIG);
if (s) if (s)
*p++ = '-'; *p++ = '-';
if (d<=0) if (d <= 0)
*p++ = '0'; *p++ = '0';
else else
do do
@ -55,14 +61,16 @@ _wrf(n,w,r,f) int n,w; double r; struct file *f; {
while (--d > 0); while (--d > 0);
if (n > 0) if (n > 0)
*p++ = '.'; *p++ = '.';
while (++d <= 0) { while (++d <= 0)
{
if (--n < 0) if (--n < 0)
break; break;
*p++ = '0'; *p++ = '0';
} }
while (--n >= 0) { while (--n >= 0)
{
*p++ = (*b ? *b++ : FILL_CHAR); *p++ = (*b ? *b++ : FILL_CHAR);
assert(p <= buf+BUFSIZE); assert(p <= buf + BUFSIZE);
} }
_wstrin(w,(int)(p-buf),buf,f); _wstrin(w, (int)(p - buf), buf, f);
} }

View file

@ -16,10 +16,10 @@
* *
*/ */
#include <pc_err.h> #include <pc_err.h>
#include <pc_file.h> #include <pc_file.h>
extern _wstrin(); extern _wstrin();
#ifndef EM_WSIZE #ifndef EM_WSIZE
#ifdef _EM_WSIZE #ifdef _EM_WSIZE
@ -27,46 +27,56 @@ extern _wstrin();
#endif #endif
#endif #endif
#if EM_WSIZE==4 #if EM_WSIZE == 4
#define SZ 11 #define SZ 11
#define MININT -2147483648 #define MININT -2147483648
#define STRMININT "-2147483648" #define STRMININT "-2147483648"
#endif #endif
#if EM_WSIZE==2 #if EM_WSIZE == 2
#define SZ 6 #define SZ 6
#define MININT -32768 #define MININT -32768
#define STRMININT "-32768" #define STRMININT "-32768"
#endif #endif
#if EM_WSIZE==1 #if EM_WSIZE == 1
#define SZ 4 #define SZ 4
#define MININT -128 #define MININT -128
#define STRMININT "-128" #define STRMININT "-128"
#endif #endif
#ifndef STRMININT #ifndef STRMININT
Something wrong here! Something wrong here !
#endif #endif
_wsi(w,i,f) int w,i; struct file *f; { _wsi(w, i, f) int w,
char *p; int j; char buf[SZ]; i;
struct file* f;
{
char* p;
int j;
char buf[SZ];
if (w < 0) _trp(EWIDTH); if (w < 0)
_trp(EWIDTH);
p = &buf[SZ]; p = &buf[SZ];
if ((j=i) < 0) { if ((j = i) < 0)
if (i == MININT) { {
_wstrin(w,SZ,STRMININT,f); if (i == MININT)
{
_wstrin(w, SZ, STRMININT, f);
return; return;
} }
j = -j; j = -j;
} }
do do
*--p = '0' + j%10; *--p = '0' + j % 10;
while (j /= 10); while (j /= 10);
if (i<0) if (i < 0)
*--p = '-'; *--p = '-';
_wstrin(w,(int)(&buf[SZ]-p),p,f); _wstrin(w, (int)(&buf[SZ] - p), p, f);
} }
_wri(i,f) int i; struct file *f; { _wri(i, f) int i;
_wsi(SZ,i,f); struct file* f;
{
_wsi(SZ, i, f);
} }

View file

@ -18,34 +18,45 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_err.h> #include <pc_err.h>
#include <pc_file.h> #include <pc_file.h>
extern _wstrin(); extern _wstrin();
#define MAXNEGLONG -2147483648 #define MAXNEGLONG -2147483648
_wsl(w,l,f) int w; long l; struct file *f; { _wsl(w, l, f) int w;
char *p,c; long j; char buf[11]; long l;
struct file* f;
{
char *p, c;
long j;
char buf[11];
if (w < 0) _trp(EWIDTH); if (w < 0)
_trp(EWIDTH);
p = &buf[11]; p = &buf[11];
if ((j=l) < 0) { if ((j = l) < 0)
if (l == MAXNEGLONG) { {
_wstrin(w,11,"-2147483648",f); if (l == MAXNEGLONG)
{
_wstrin(w, 11, "-2147483648", f);
return; return;
} }
j = -j; j = -j;
} }
do { do
c = j%10; {
c = j % 10;
*--p = c + '0'; *--p = c + '0';
} while (j /= 10); } while (j /= 10);
if (l<0) if (l < 0)
*--p = '-'; *--p = '-';
_wstrin(w,(int)(&buf[11]-p),p,f); _wstrin(w, (int)(&buf[11] - p), p, f);
} }
_wrl(l,f) long l; struct file *f; { _wrl(l, f) long l;
_wsl(11,l,f); struct file* f;
{
_wsl(11, l, f);
} }

View file

@ -18,23 +18,29 @@
/* Author: J.W. Stevenson */ /* Author: J.W. Stevenson */
#include <pc_err.h> #include <pc_err.h>
#include <pc_file.h> #include <pc_file.h>
extern _wstrin(); extern _wstrin();
extern char *_ecvt(); extern char* _ecvt();
#define PREC_DIG 80 /* maximum digits produced by _ecvt() */ #define PREC_DIG 80 /* maximum digits produced by _ecvt() */
_wsr(w,r,f) int w; double r; struct file *f; { _wsr(w, r, f) int w;
char *p,*b; int s,d,i; char buf[PREC_DIG+7]; double r;
struct file* f;
{
char *p, *b;
int s, d, i;
char buf[PREC_DIG + 7];
if (w < 0) _trp(EWIDTH); if (w < 0)
_trp(EWIDTH);
p = buf; p = buf;
if ((i = w-6) < 2) if ((i = w - 6) < 2)
i = 2; i = 2;
b = _ecvt(r,i,&d,&s); b = _ecvt(r, i, &d, &s);
*p++ = s? '-' : ' '; *p++ = s ? '-' : ' ';
if (*b == '0') if (*b == '0')
d++; d++;
*p++ = *b++; *p++ = *b++;
@ -43,25 +49,31 @@ _wsr(w,r,f) int w; double r; struct file *f; {
*p++ = *b++; *p++ = *b++;
*p++ = 'e'; *p++ = 'e';
d--; d--;
if (d < 0) { if (d < 0)
{
d = -d; d = -d;
*p++ = '-'; *p++ = '-';
} else }
else
*p++ = '+'; *p++ = '+';
if (d >= 1000) { if (d >= 1000)
{
*p++ = '*'; *p++ = '*';
*p++ = '*'; *p++ = '*';
*p++ = '*'; *p++ = '*';
} }
else { else
*p++ = '0' + d/100; {
*p++ = '0' + (d/10) % 10; *p++ = '0' + d / 100;
*p++ = '0' + d%10; *p++ = '0' + (d / 10) % 10;
*p++ = '0' + d % 10;
} }
_wstrin(w,(int)(p-buf),buf,f); _wstrin(w, (int)(p - buf), buf, f);
} }
_wrr(r,f) double r; struct file *f; { _wrr(r, f) double r;
_wsr(13,r,f); struct file* f;
{
_wsr(13, r, f);
} }