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; {
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; {
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; {
double _abr(r) double r;
{
return (r >= 0 ? r : -r);
}

View file

@ -27,26 +27,32 @@ extern int _pargc;
extern char** _pargv;
extern char** _penvp;
int argc() {
int argc()
{
return (_pargc);
}
char *argv(i) {
char* argv(i)
{
if (i >= _pargc)
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++)

View file

@ -24,9 +24,11 @@
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 {
struct descr
{
int low;
int diff;
int size;
};
int _asz(dp) struct descr *dp; {
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"
@ -47,26 +46,30 @@ _atn(x)
int n;
double g;
if (neg) {
if (neg)
{
x = -x;
}
if (x > 1.0) {
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,9 +18,12 @@
/* 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);
if (*x++ > *y++)

View file

@ -24,7 +24,8 @@ 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))

View file

@ -26,7 +26,8 @@
/* to make it easier to patch ... */
extern struct file* _curfil;
static struct errm {
static struct errm
{
int errno;
char* errmes;
} errors[] = {
@ -89,7 +90,8 @@ extern char **_penvp;
extern char* _hol0();
extern _trp();
_catch(erno) unsigned erno; {
_catch(erno) unsigned erno;
{
register struct errm* ep = &errors[0];
char *p, *q, *s, **qq;
char buf[20];
@ -104,45 +106,54 @@ _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++;

View file

@ -22,7 +22,8 @@
extern int _times();
struct tbuf {
struct tbuf
{
long utime;
long stime;
long cutime;
@ -33,7 +34,8 @@ struct tbuf {
#define EM_WSIZE _EM_WSIZE
#endif
int clock() {
int clock()
{
struct tbuf t;
_times(&t);

View file

@ -28,11 +28,13 @@ 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,7 +45,8 @@ _xcls(f) struct file *f; {
_flush(f);
}
_cls(f) struct file *f; {
_cls(f) struct file* f;
{
#ifdef MAYBE
char* p;
#endif

View file

@ -12,22 +12,21 @@ static char *cvt();
#define NDIGITS 128
char*
_ecvt(value, ndigit, decpt, sign)
double value;
_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;
_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;
@ -42,42 +41,52 @@ static struct powers_of_10 {
};
static char*
cvt(value, ndigit, decpt, sign, ecvtflag)
double value;
cvt(value, ndigit, decpt, sign, ecvtflag) double value;
int ndigit, *decpt, *sign;
{
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) {
if (value != 0.0)
{
register struct powers_of_10* pp = &p10[0];
if (value >= 10.0) do {
while (value >= pp->pval) {
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) {
if (value < 1.0)
do
{
while (value * pp->pval < 10.0)
{
value *= pp->pval;
*decpt -= pp->exp;
}
@ -85,29 +94,38 @@ cvt(value, ndigit, decpt, sign, ecvtflag)
(*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') {
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

@ -22,7 +22,8 @@
/* 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;

View file

@ -27,7 +27,8 @@ 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)

View file

@ -24,7 +24,8 @@
extern _trp();
extern _rf();
int _eln(f) struct file *f; {
int _eln(f) struct file* f;
{
_rf(f);
if (f->flags & EOFBIT)

View file

@ -22,29 +22,33 @@ extern _trp();
#define HUGE 1e1000
static double
Ldexp(fl,exp)
double fl;
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);
exp += currexp;
if (exp > 0) {
while (exp>30) {
if (exp > 0)
{
while (exp > 30)
{
fl *= (double)(1L << 30);
exp -= 30;
}
fl *= (double)(1L << exp);
}
else {
while (exp<-30) {
else
{
while (exp < -30)
{
fl /= (double)(1L << 30);
exp += 30;
}
@ -54,8 +58,7 @@ Ldexp(fl,exp)
}
double
_exp(x)
double x;
_exp(x) double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
@ -78,26 +81,34 @@ _exp(x)
int n;
int negative = x < 0;
if (x <= M_LN_MIN_D) {
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 */
xn = n;
@ -107,7 +118,8 @@ _exp(x)
g = ((x1 - xn * 0.693359375) + x2) - xn * (-2.1219444005469058277e-4);
}
if (negative) {
if (negative)
{
g = -g;
n = -n;
}

View file

@ -22,7 +22,8 @@
extern _rf();
extern _trp();
_get(f) struct file *f; {
_get(f) struct file* f;
{
_rf(f);
if (f->flags & EOFBIT)

View file

@ -25,7 +25,8 @@ extern int _extflc;
extern _cls();
extern _exit();
_hlt(ecode) int ecode; {
_hlt(ecode) int ecode;
{
int i;
for (i = 0; i < _extflc; i++)

View file

@ -26,27 +26,34 @@
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) {
if (f->count == 0)
{
f->ptr = f->bufadr;
for(;;) {
for (;;)
{
f->count = read(f->ufd, f->bufadr, f->buflen);
if ( f->count<0 ) {
if (errno != EINTR) _trp(EREAD) ;
if (f->count < 0)
{
if (errno != EINTR)
_trp(EREAD);
continue;
}
break;
}
if (f->count == 0) {
if (f->count == 0)
{
f->flags |= EOFBIT;
*f->ptr = '\0';
return;
@ -57,15 +64,18 @@ _incpt(f) struct file *f; {
#ifdef CPM
} 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

@ -33,18 +33,25 @@ 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; {
_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 **);
_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->fname = "INPUT";
@ -53,7 +60,8 @@ _ini(args,c,p,mainlb) char *args,*mainlb; int c; struct file **p; {
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->fname = "OUTPUT";

View file

@ -19,8 +19,7 @@
#define HUGE 1e1000
double
_log(x)
double x;
_log(x) double x;
{
/* Algorithm and coefficients from:
"Software manual for the elementary functions"
@ -42,22 +41,26 @@ _log(x)
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;
z = znum / zden;
w = z * z;
x = z + z * w * (POLYNOM2(w, a) / POLYNOM3(w, b));
z = exponent;
x += z * (-2.121944400546905827679e-4);

View file

@ -22,7 +22,8 @@
extern _trp();
int _mdi(j,i) int j,i; {
int _mdi(j, i) int j, i;
{
if (j <= 0)
_trp(EMOD);
@ -32,7 +33,8 @@ int _mdi(j,i) int j,i; {
return (i);
}
long _mdil(j,i) long j,i; {
long _mdil(j, i) long j, i;
{
if (j <= 0)
_trp(EMOD);
@ -42,30 +44,42 @@ long _mdil(j,i) long j,i; {
return (i);
}
int _dvi(j, i) unsigned int j,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

@ -22,7 +22,8 @@
extern _trp();
long _mdl(j,i) long j,i; {
long _mdl(j, i) long j, i;
{
if (j <= 0)
_trp(EMOD);

View file

@ -12,5 +12,6 @@ extern _trp();
_nfa(bool)
{
if (! bool) _trp(EFUNASS);
if (!bool)
_trp(EFUNASS);
}

View file

@ -24,7 +24,8 @@ 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))
return;

View file

@ -18,6 +18,7 @@
#include <pc_file.h>
notext(f) struct file *f; {
notext(f) struct file* f;
{
f->flags &= ~TXTBIT;
}

View file

@ -34,9 +34,11 @@ 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;
@ -54,42 +56,56 @@ static int tmpfil() {
if ((i = open(p, 2)) < 0)
goto error;
if (remove(p) != 0)
error: _trp(EREWR);
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++)
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)
_trp(ERESET);
} else {
}
else
{
_cls(f);
f->ufd = tmpfil();
}
} else { /* external file */
}
else
{ /* external file */
if (--i <= 0)
return (0);
if (i >= _pargc)
_trp(EARGC);
f->fname = _pargv[i];
_cls(f);
if ((descr & WRBIT) == 0) {
if ((descr & WRBIT) == 0)
{
if ((f->ufd = open(f->fname, 0)) < 0)
_trp(ERESET);
} else {
}
else
{
if ((f->ufd = creat(f->fname, 0644)) < 0)
_trp(EREWR);
}
@ -101,13 +117,17 @@ static int initfl(descr,sz,f) int descr; int sz; struct file *f; {
return (1);
}
_opn(sz,f) int sz; struct file *f; {
_opn(sz, f) int sz;
struct file* 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))
f->count = f->buflen;

View file

@ -26,7 +26,8 @@
extern _trp();
_flush(f) struct file *f; {
_flush(f) struct file* f;
{
int i, n;
f->ptr = f->bufadr;
@ -40,7 +41,8 @@ _flush(f) struct file *f; {
_trp(EWRITE);
}
_outcpt(f) struct file *f; {
_outcpt(f) struct file* f;
{
f->flags &= ~ELNBIT;
f->ptr += f->size;

View file

@ -28,34 +28,41 @@ extern _trp();
#define EM_WSIZE _EM_WSIZE
#endif
struct descr {
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) {
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) {
}
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

@ -22,6 +22,7 @@ extern _cls();
/* procedure pclose(var f:file of ??); */
pclose(f) struct file *f; {
pclose(f) struct file* f;
{
_cls(f);
}

View file

@ -27,7 +27,9 @@ 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 */
f->ptr = f->bufadr;

View file

@ -25,7 +25,8 @@ extern _wrs();
extern _wrz();
extern _wln();
procentry(name) char *name; {
procentry(name) char* name;
{
struct file* f;
f = _extfl[1];

View file

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

View file

@ -23,7 +23,8 @@ extern _wrs();
extern _wrz();
extern _wln();
procexit(name) char *name; {
procexit(name) char* name;
{
struct file* f;
f = _extfl[1];

View file

@ -27,7 +27,9 @@ 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 */
f->ptr = f->bufadr;

View file

@ -21,7 +21,8 @@
extern _wf();
extern _outcpt();
_put(f) struct file *f; {
_put(f) struct file* f;
{
_wf(f);
_outcpt(f);
}

View file

@ -10,16 +10,15 @@
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;
_rcka(descr, index) struct array_descr* descr;
{
if( index < descr->lbound ||
index > (int) descr->n_elts_min_one + descr->lbound )
if (index < descr->lbound || index > (int)descr->n_elts_min_one + descr->lbound)
_trp(EARRAY);
}

View file

@ -21,7 +21,8 @@
extern _rf();
extern _incpt();
int _rdc(f) struct file *f; {
int _rdc(f) struct file* f;
{
int c;
_rf(f);

View file

@ -25,12 +25,14 @@ 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 == '+')
@ -38,18 +40,21 @@ int _getsig(f) struct file *f; {
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);
}
int _nxtdig(f) struct file *f; {
int _nxtdig(f) struct file* f;
{
int ch;
_incpt(f);
@ -59,7 +64,8 @@ int _nxtdig(f) struct file *f; {
return (ch);
}
int _getint(f) struct file *f; {
int _getint(f) struct file* f;
{
int is_signed, i, ch;
is_signed = _getsig(f);
@ -71,7 +77,8 @@ int _getint(f) struct file *f; {
return (is_signed ? i : -i);
}
int _rdi(f) struct file *f; {
int _rdi(f) struct file* f;
{
_rf(f);
_skipsp(f);
return (_getint(f));

View file

@ -26,8 +26,10 @@ 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);

View file

@ -33,7 +33,8 @@ extern int _nxtdig();
static double r;
static int pow10;
static dig(ch) int ch; {
static dig(ch) int ch;
{
if (r > BIG)
pow10++;
@ -41,8 +42,11 @@ static dig(ch) int 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);
}

View file

@ -23,7 +23,8 @@ 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)

View file

@ -21,7 +21,8 @@
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; {
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"
@ -38,15 +37,18 @@ sinus(x, cos_flag)
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 ??? */
@ -63,8 +65,10 @@ sinus(x, cos_flag)
extern double _fif();
_fif(y, 1.0, &y);
if (_fif(y, 0.5, &x1)) neg = !neg;
if (cos_flag) y -= 0.5;
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

@ -14,29 +14,33 @@ extern _trp();
#define NITER 5
static double
Ldexp(fl,exp)
double fl;
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);
exp += currexp;
if (exp > 0) {
while (exp>30) {
if (exp > 0)
{
while (exp > 30)
{
fl *= (double)(1L << 30);
exp -= 30;
}
fl *= (double)(1L << exp);
}
else {
while (exp<-30) {
else
{
while (exp < -30)
{
fl /= (double)(1L << 30);
exp += 30;
}
@ -46,26 +50,29 @@ Ldexp(fl,exp)
}
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);
/* 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,17 +18,20 @@
/* function strbuf(var b:charbuf):string; */
char *strbuf(s) char *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++;
@ -38,7 +41,8 @@ int strtobuf(s,b,l) char *s,*b; {
/* function strlen(s:string):integer; */
int strlen(s) char *s; {
int strlen(s) char* s;
{
int i;
i = 0;
@ -49,12 +53,14 @@ int strlen(s) char *s; {
/* function strfetch(s:string; i:integer):char; */
int strfetch(s,i) char *s; {
int strfetch(s, i) char* s;
{
return (s[i - 1]);
}
/* procedure strstore(s:string; i:integer; c:char); */
strstore(s,i,c) char *s; {
strstore(s, i, c) char* s;
{
s[i - 1] = c;
}

View file

@ -28,36 +28,48 @@ extern _trp();
#define EM_WSIZE _EM_WSIZE
#endif
struct descr {
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) {
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) {
}
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; {
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; {
int uwrite(fd, b, n) char* b;
int fd, n;
{
return (write(fd, b, n));
}

View file

@ -21,7 +21,8 @@
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)

View file

@ -22,7 +22,8 @@
extern struct file* _curfil;
extern _trp();
_wf(f) struct file *f; {
_wf(f) struct file* f;
{
_curfil = f;
if ((f->flags & 0377) != MAGIC)

View file

@ -21,13 +21,16 @@
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);
#endif
@ -35,7 +38,8 @@ _wln(f) struct file *f; {
f->flags |= ELNBIT;
}
_pag(f) struct file *f; {
_pag(f) struct file* f;
{
_wrc('\014', f);
f->flags |= ELNBIT;
}

View file

@ -36,10 +36,16 @@ extern char *_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;
@ -55,12 +61,14 @@ _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);
}

View file

@ -47,13 +47,21 @@ extern _wstrin();
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) {
if ((j = i) < 0)
{
if (i == MININT)
{
_wstrin(w, SZ, STRMININT, f);
return;
}
@ -67,6 +75,8 @@ _wsi(w,i,f) int w,i; struct file *f; {
_wstrin(w, (int)(&buf[SZ] - p), p, f);
}
_wri(i,f) int i; struct file *f; {
_wri(i, f) int i;
struct file* f;
{
_wsi(SZ, i, f);
}

View file

@ -25,19 +25,28 @@ extern _wstrin();
#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) {
if ((j = l) < 0)
{
if (l == MAXNEGLONG)
{
_wstrin(w, 11, "-2147483648", f);
return;
}
j = -j;
}
do {
do
{
c = j % 10;
*--p = c + '0';
} while (j /= 10);
@ -46,6 +55,8 @@ _wsl(w,l,f) int w; long l; struct file *f; {
_wstrin(w, (int)(&buf[11] - p), p, f);
}
_wrl(l,f) long l; struct file *f; {
_wrl(l, f) long l;
struct file* f;
{
_wsl(11, l, f);
}

View file

@ -26,10 +26,16 @@ extern char *_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)
i = 2;
@ -43,18 +49,22 @@ _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 {
else
{
*p++ = '0' + d / 100;
*p++ = '0' + (d / 10) % 10;
*p++ = '0' + d % 10;
@ -62,6 +72,8 @@ _wsr(w,r,f) int w; double r; struct file *f; {
_wstrin(w, (int)(p - buf), buf, f);
}
_wrr(r,f) double r; struct file *f; {
_wrr(r, f) double r;
struct file* f;
{
_wsr(13, r, f);
}