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 */
int _abi(i) int i; {
return(i>=0 ? i : -i);
int _abi(i) int i;
{
return (i >= 0 ? i : -i);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,13 +18,16 @@
/* 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)
return(-1);
return (-1);
if (*x++ > *y++)
return(1);
return (1);
}
return(0);
return (0);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -9,53 +9,56 @@
#define __NO_DEFS
#include <math.h>
#include <pc_err.h>
extern _trp();
extern _trp();
#if __STDC__
#include <float.h>
#include <pc_math.h>
#define M_MIN_D DBL_MIN
#define M_MAX_D DBL_MAX
#define M_MIN_D DBL_MIN
#define M_MAX_D DBL_MAX
#define M_DMINEXP DBL_MIN_EXP
#endif
#undef HUGE
#define HUGE 1e1000
#define HUGE 1e1000
static double
Ldexp(fl,exp)
double fl;
int exp;
Ldexp(fl, exp) double fl;
int exp;
{
extern double _fef();
int sign = 1;
int currexp;
if (fl<0) {
if (fl < 0)
{
fl = -fl;
sign = -1;
}
fl = _fef(fl,&currexp);
fl = _fef(fl, &currexp);
exp += currexp;
if (exp > 0) {
while (exp>30) {
fl *= (double) (1L << 30);
if (exp > 0)
{
while (exp > 30)
{
fl *= (double)(1L << 30);
exp -= 30;
}
fl *= (double) (1L << exp);
fl *= (double)(1L << exp);
}
else {
while (exp<-30) {
fl /= (double) (1L << 30);
else
{
while (exp < -30)
{
fl /= (double)(1L << 30);
exp += 30;
}
fl /= (double) (1L << -exp);
fl /= (double)(1L << -exp);
}
return sign * fl;
}
double
_exp(x)
double x;
_exp(x) double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
@ -63,56 +66,65 @@ _exp(x)
*/
static double p[] = {
0.25000000000000000000e+0,
0.75753180159422776666e-2,
0.25000000000000000000e+0,
0.75753180159422776666e-2,
0.31555192765684646356e-4
};
static double q[] = {
0.50000000000000000000e+0,
0.56817302698551221787e-1,
0.63121894374398503557e-3,
0.50000000000000000000e+0,
0.56817302698551221787e-1,
0.63121894374398503557e-3,
0.75104028399870046114e-6
};
double xn, g;
int n;
int negative = x < 0;
double xn, g;
int n;
int negative = x < 0;
if (x <= M_LN_MIN_D) {
g = M_MIN_D/4.0;
if (x <= M_LN_MIN_D)
{
g = M_MIN_D / 4.0;
if (g != 0.0) {
if (g != 0.0)
{
/* 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 {
if (x < M_LN_MIN_D) return 0.0;
else
{
if (x < M_LN_MIN_D)
return 0.0;
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);
return HUGE;
}
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;
{
double x1 = (long) x;
double x2 = x - x1;
double x1 = (long)x;
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;
n = -n;
}
xn = g * g;
x = g * POLYNOM2(xn, p);
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_err.h>
#include <pc_file.h>
#include <pc_err.h>
extern _rf();
extern _trp();
extern _rf();
extern _trp();
_get(f) struct file *f; {
_get(f) struct file* f;
{
_rf(f);
if (f->flags&EOFBIT)
if (f->flags & EOFBIT)
_trp(EEOF);
f->flags &= ~WINDOW;
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,16 +18,17 @@
/* 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)
_trp(EMOD);
i = i % j;
if (i < 0)
i += j;
return(i);
return (i);
}

View file

@ -2,7 +2,7 @@
#include <em_abs.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)
{

View file

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

View file

@ -18,15 +18,16 @@
/* Author: J.W. Stevenson */
#include <pc_file.h>
#include <pc_file.h>
extern _flush();
extern _flush();
/* 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;
_flush(f);
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;
}

View file

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

View file

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

View file

@ -18,44 +18,51 @@
/* 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
#define EM_WSIZE _EM_WSIZE
#endif
struct descr {
int low;
int diff;
int size;
struct descr
{
int low;
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 ||
(i -= ad->low) < 0 ||
(i+zd->diff) > ad->diff)
if (zd->diff > ad->diff || (i -= ad->low) < 0 || (i + zd->diff) > ad->diff)
_trp(EPACK);
ap += (i * ad->size);
i = (zd->diff + 1) * zd->size;
if (zd->size == 1) {
int *aptmp = (int *)ap;
if (zd->size == 1)
{
int* aptmp = (int*)ap;
assert(ad->size == EM_WSIZE);
while (--i >= 0)
*zp++ = *aptmp++;
#if EM_WSIZE > 2
} else if (zd->size == 2) {
int *aptmp = (int *)ap;
short *zptmp = (short *) zp;
}
else if (zd->size == 2)
{
int* aptmp = (int*)ap;
short* zptmp = (short*)zp;
assert(ad->size == EM_WSIZE);
while (--i >= 0)
*zptmp++ = *aptmp++;
#endif
} else {
}
else
{
assert(ad->size == zd->size);
while (--i >= 0)
*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 ??); */
pclose(f) struct file *f; {
pclose(f) struct file* f;
{
_cls(f);
}

View file

@ -18,24 +18,26 @@
/* Author: J.W. Stevenson */
#include <unistd.h>
#include <pc_file.h>
#include <pc_err.h>
#include <unistd.h>
#include <pc_file.h>
#include <pc_err.h>
extern _cls();
extern _trp();
extern _cls();
extern _trp();
/* 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->flags = WRBIT|EOFBIT|ELNBIT|TXTBIT|MAGIC;
f->flags = WRBIT | EOFBIT | ELNBIT | TXTBIT | MAGIC;
f->fname = s;
f->size = 1;
f->count = PC_BUFLEN;
f->buflen = PC_BUFLEN;
if ((f->ufd = creat(s,0644)) < 0)
if ((f->ufd = creat(s, 0644)) < 0)
_trp(EREWR);
}

View file

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

View file

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

View file

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

View file

@ -18,24 +18,26 @@
/* Author: J.W. Stevenson */
#include <pc_file.h>
#include <pc_err.h>
#include <pc_file.h>
#include <pc_err.h>
extern _cls();
extern _trp();
extern int _open();
extern _cls();
extern _trp();
extern int _open();
/* 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->flags = TXTBIT|MAGIC;
f->flags = TXTBIT | MAGIC;
f->fname = s;
f->size = 1;
f->count = 0;
f->buflen = PC_BUFLEN;
if ((f->ufd = _open(s,0)) < 0)
if ((f->ufd = _open(s, 0)) < 0)
_trp(ERESET);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,46 +18,58 @@
/* 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
#define EM_WSIZE _EM_WSIZE
#endif
struct descr {
int low;
int diff;
int size;
struct descr
{
int low;
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 ||
(i -= ad->low) < 0 ||
(i+zd->diff) > ad->diff)
if (zd->diff > ad->diff || (i -= ad->low) < 0 || (i + zd->diff) > ad->diff)
_trp(EUNPACK);
ap += (i * ad->size);
i = (zd->diff + 1) * zd->size;
if (zd->size == 1) {
int *aptmp = (int *) ap;
if (zd->size == 1)
{
int* aptmp = (int*)ap;
assert(ad->size == EM_WSIZE);
while (--i >= 0)
if (noext) *aptmp++ = *zp++ & 0377;
else *aptmp++ = *zp++;
if (noext)
*aptmp++ = *zp++ & 0377;
else
*aptmp++ = *zp++;
#if EM_WSIZE > 2
} else if (zd->size == 2) {
int *aptmp = (int *) ap;
short *zptmp = (short *) zp;
}
else if (zd->size == 2)
{
int* aptmp = (int*)ap;
short* zptmp = (short*)zp;
assert(ad->size == EM_WSIZE);
while (--i >= 0)
if (noext) *aptmp++ = *zptmp++ & 0177777;
else *aptmp++ = *zptmp++;
if (noext)
*aptmp++ = *zptmp++ & 0177777;
else
*aptmp++ = *zptmp++;
#endif
} else {
}
else
{
assert(ad->size == zd->size);
while (--i >= 0)
*ap++ = *zp++;

View file

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

View file

@ -21,6 +21,8 @@
#include <stdlib.h>
#include <unistd.h>
int uwrite(fd,b,n) char *b; int fd,n; {
return(write(fd,b,n));
int uwrite(fd, b, n) char* b;
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 _incpt();
extern struct file* _curfil;
extern _incpt();
char *_wdw(f) struct file *f; {
char* _wdw(f) struct file* f;
{
_curfil = f;
if ((f->flags & (WINDOW|WRBIT|0377)) == MAGIC)
if ((f->flags & (WINDOW | WRBIT | 0377)) == MAGIC)
_incpt(f);
return(f->ptr);
return (f->ptr);
}

View file

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

View file

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

View file

@ -18,36 +18,42 @@
/* Author: J.W. Stevenson */
#include <pc_err.h>
#include <pc_file.h>
#include <pc_err.h>
#include <pc_file.h>
extern _wstrin();
extern char *_fcvt();
extern _wstrin();
extern char* _fcvt();
#define assert(x) /* nothing */
#define assert(x) /* nothing */
#if __STDC__
#include <float.h>
#define HUGE_DIG DBL_MAX_10_EXP /* log10(maxreal) */
#define HUGE_DIG DBL_MAX_10_EXP /* log10(maxreal) */
#else
#define HUGE_DIG 400 /* log10(maxreal) */
#define HUGE_DIG 400 /* log10(maxreal) */
#endif
#define PREC_DIG 80 /* the maximum digits returned by _fcvt() */
#define FILL_CHAR '0' /* char printed if all of _fcvt() used */
#define BUFSIZE HUGE_DIG + PREC_DIG + 3
#define PREC_DIG 80 /* the maximum digits returned by _fcvt() */
#define FILL_CHAR '0' /* char printed if all of _fcvt() used */
#define BUFSIZE HUGE_DIG + PREC_DIG + 3
_wrf(n,w,r,f) int n,w; double r; struct file *f; {
char *p,*b; int s,d; char buf[BUFSIZE];
_wrf(n, w, r, f) int n, w;
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;
if (n > PREC_DIG)
n = PREC_DIG;
b = _fcvt(r,n,&d,&s);
b = _fcvt(r, n, &d, &s);
assert(abs(d) <= HUGE_DIG);
if (s)
*p++ = '-';
if (d<=0)
if (d <= 0)
*p++ = '0';
else
do
@ -55,14 +61,16 @@ _wrf(n,w,r,f) int n,w; double r; struct file *f; {
while (--d > 0);
if (n > 0)
*p++ = '.';
while (++d <= 0) {
while (++d <= 0)
{
if (--n < 0)
break;
*p++ = '0';
}
while (--n >= 0) {
while (--n >= 0)
{
*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_file.h>
#include <pc_err.h>
#include <pc_file.h>
extern _wstrin();
extern _wstrin();
#ifndef EM_WSIZE
#ifdef _EM_WSIZE
@ -27,46 +27,56 @@ extern _wstrin();
#endif
#endif
#if EM_WSIZE==4
#if EM_WSIZE == 4
#define SZ 11
#define MININT -2147483648
#define STRMININT "-2147483648"
#endif
#if EM_WSIZE==2
#if EM_WSIZE == 2
#define SZ 6
#define MININT -32768
#define STRMININT "-32768"
#endif
#if EM_WSIZE==1
#if EM_WSIZE == 1
#define SZ 4
#define MININT -128
#define STRMININT "-128"
#endif
#ifndef STRMININT
Something wrong here!
Something wrong here !
#endif
_wsi(w,i,f) int w,i; struct file *f; {
char *p; int j; char buf[SZ];
_wsi(w, i, f) int w,
i;
struct file* f;
{
char* p;
int j;
char buf[SZ];
if (w < 0) _trp(EWIDTH);
if (w < 0)
_trp(EWIDTH);
p = &buf[SZ];
if ((j=i) < 0) {
if (i == MININT) {
_wstrin(w,SZ,STRMININT,f);
if ((j = i) < 0)
{
if (i == MININT)
{
_wstrin(w, SZ, STRMININT, f);
return;
}
j = -j;
}
do
*--p = '0' + j%10;
*--p = '0' + j % 10;
while (j /= 10);
if (i<0)
if (i < 0)
*--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; {
_wsi(SZ,i,f);
_wri(i, f) int i;
struct file* f;
{
_wsi(SZ, i, f);
}

View file

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

View file

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