From a53b51001b0309ccb5adb75eff5120cf0cd121d0 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 12 Dec 2016 21:15:25 +0100 Subject: [PATCH 1/3] Ansify function definitions. --- lang/basic/lib/abs.c | 4 ++-- lang/basic/lib/asc.c | 3 +-- lang/basic/lib/asrt.c | 5 ++-- lang/basic/lib/chr.c | 3 +-- lang/basic/lib/conversion.c | 10 ++++---- lang/basic/lib/error.c | 3 +-- lang/basic/lib/file.c | 17 +++++-------- lang/basic/lib/hlt.c | 5 ++-- lang/basic/lib/io.c | 16 +++++-------- lang/basic/lib/mki.c | 12 ++++------ lang/basic/lib/oct.c | 9 +++---- lang/basic/lib/peek.c | 6 ++--- lang/basic/lib/print.c | 17 +++++-------- lang/basic/lib/random.c | 7 +++--- lang/basic/lib/read.c | 19 ++++++--------- lang/basic/lib/return.c | 5 ++-- lang/basic/lib/salloc.c | 6 ++--- lang/basic/lib/sgn.c | 6 ++--- lang/basic/lib/string.c | 48 ++++++++++++------------------------- lang/basic/lib/swap.c | 9 +++---- lang/basic/lib/trace.c | 3 +-- lang/basic/lib/trap.c | 14 ++++------- lang/basic/lib/write.c | 13 ++++------ 23 files changed, 86 insertions(+), 154 deletions(-) diff --git a/lang/basic/lib/abs.c b/lang/basic/lib/abs.c index 6e7d375ac..00f682942 100644 --- a/lang/basic/lib/abs.c +++ b/lang/basic/lib/abs.c @@ -5,11 +5,11 @@ * See the copyright notice in the ACK home directory, in the file "Copyright". */ -long _abl(i) long i; +long _abl(long i) { return( i>=0?i:-i); } -double _abr(f) double f; +double _abr(double f) { return( f>=0.0?f: -f); } diff --git a/lang/basic/lib/asc.c b/lang/basic/lib/asc.c index 293f9bf58..3e3585de9 100644 --- a/lang/basic/lib/asc.c +++ b/lang/basic/lib/asc.c @@ -2,8 +2,7 @@ /* $Id$ */ -int _asc(str) -String *str; +int _asc(String* str) { if(str==0 || str->strval==0) error(3); diff --git a/lang/basic/lib/asrt.c b/lang/basic/lib/asrt.c index 17cf34c7a..8d0b40b86 100644 --- a/lang/basic/lib/asrt.c +++ b/lang/basic/lib/asrt.c @@ -1,6 +1,7 @@ -/* $Id$ */ +#include +#include -asrt(b) +void asrt(int b) { if(!b){ printf("ASSERTION ERROR\n"); diff --git a/lang/basic/lib/chr.c b/lang/basic/lib/chr.c index 81d3e799c..5825ec1e6 100644 --- a/lang/basic/lib/chr.c +++ b/lang/basic/lib/chr.c @@ -2,8 +2,7 @@ /* $Id$ */ -String *_chr(i) -int i; +String *_chr(int i) { String *s; char buf[2]; diff --git a/lang/basic/lib/conversion.c b/lang/basic/lib/conversion.c index f4774b9bf..e65650fb6 100644 --- a/lang/basic/lib/conversion.c +++ b/lang/basic/lib/conversion.c @@ -1,6 +1,6 @@ /* $Id$ */ -int _cint(f) double f; +int _cint(double f) { int r; if( f<-32768 || f>32767) error(4); @@ -10,8 +10,7 @@ int _cint(f) double f; return(r); } -double _trunc(f) -double f; +double _trunc(double f) { long d; d=f; @@ -19,7 +18,7 @@ double f; return( f ); } -double _fcint(f) double f; +double _fcint(double f) { long r; if(f<0){ @@ -29,8 +28,7 @@ double _fcint(f) double f; f=r; return(f); } -int _fix(f) -double f; +int _fix(double f) { int r; diff --git a/lang/basic/lib/error.c b/lang/basic/lib/error.c index becc69d7a..4ab981639 100644 --- a/lang/basic/lib/error.c +++ b/lang/basic/lib/error.c @@ -52,8 +52,7 @@ char *errortable[255]={ 0 }; -error(index) -int index; +void error(int index) { _setline(); if( index<0 || index >40 ) diff --git a/lang/basic/lib/file.c b/lang/basic/lib/file.c index a227e3927..f6ba63cf1 100644 --- a/lang/basic/lib/file.c +++ b/lang/basic/lib/file.c @@ -18,8 +18,7 @@ int _chann = -1; FILE *_chanrd = stdin; FILE *_chanwr = stdout; -_setchan(index) -int index; +void _setchan(int index) { #ifdef DEBUG printf("setchannel %d\n",index); @@ -38,7 +37,7 @@ int index; _chanrd= _chanwr= _fdtable[index].fd; } -_asschn() +void _asschn(void) { #ifdef DEBUG printf("_asschn %d\n",_chann); @@ -55,17 +54,14 @@ _asschn() error(2); } -_clochn(nr) -int nr; +void _clochn(int nr) { if( nr<1 || nr >15 || _fdtable[nr].fd==0) error(3); fclose(_fdtable[nr].fd); _fdtable[nr].fd=0; _fdtable[nr].fname=0; } -_opnchn(reclen,fname,mode) -String *mode,*fname; -int reclen; +void _opnchn(int reclen, String* fname, String* mode) { /* channel has been set */ FILE *f; @@ -110,8 +106,7 @@ int reclen; #endif } -_ioeof(channel) -int channel; +int _ioeof(int channel) { FILE *fd; char c; @@ -125,7 +120,7 @@ int channel; return(0); } -_close() +void _close(void) { /* close all open files */ int i; diff --git a/lang/basic/lib/hlt.c b/lang/basic/lib/hlt.c index 20f4d5276..c0d7f7511 100644 --- a/lang/basic/lib/hlt.c +++ b/lang/basic/lib/hlt.c @@ -1,12 +1,11 @@ #include -_hlt(nr) -int nr; +void _hlt(int nr) { exit(nr); } -_goto_err() +void _goto_err(void) { error(3); } diff --git a/lang/basic/lib/io.c b/lang/basic/lib/io.c index e0d7581f0..842cd16e5 100644 --- a/lang/basic/lib/io.c +++ b/lang/basic/lib/io.c @@ -10,8 +10,7 @@ int _width = 75, _pos=0, _zonewidth=15; -_out(str) -char *str; +void _out(char* str) { int pos; @@ -27,7 +26,7 @@ char *str; else _fdtable[_chann].pos= pos; } -_outnl() +void _outnl(void) { fputc('\n',_chanwr); if( _chann == -1) @@ -35,7 +34,7 @@ _outnl() else _fdtable[_chann].pos=0; } -_zone() +void _zone(void) { /* go to next zone */ int pos; @@ -55,8 +54,7 @@ _zone() if( _chann== -1) _pos=pos; else _fdtable[_chann].pos= pos; } -_in(buf) -char *buf; +void _in(char* buf) { register int holder ; char *c; @@ -77,15 +75,13 @@ char *buf; _pos=pos; } else _fdtable[_chann].pos= pos; } -_tab(x) -int x; +void _tab(int x) { if( x> _width) error(3); if( x< _pos) _outnl(); _spc(x-_pos); } -_spc(x) -int x; +void _spc(int x) { while(x-->0) _out(" "); } diff --git a/lang/basic/lib/mki.c b/lang/basic/lib/mki.c index 98de092be..ce2822c8c 100644 --- a/lang/basic/lib/mki.c +++ b/lang/basic/lib/mki.c @@ -2,8 +2,7 @@ /* $Id$ */ -String *_mki(i) -long i; +String *_mki(long i) { char *buffer =" "; String *s; @@ -12,8 +11,7 @@ long i; * ( (long *)s->strval ) = i ; return(s); } -String *_mkd(d) -double d; +String *_mkd(double d) { char *buffer =" "; String *s; @@ -22,13 +20,11 @@ double d; * ( (double *)s->strval ) = d ; return(s); } -long _cvi(s) -String *s; +long _cvi(String* s) { return *( (long *) s->strval) ; } -double _cvd(s) -String *s; +double _cvd(String* s) { return *( (double *) s->strval) ; } diff --git a/lang/basic/lib/oct.c b/lang/basic/lib/oct.c index ea73bc11d..04a0c34e0 100644 --- a/lang/basic/lib/oct.c +++ b/lang/basic/lib/oct.c @@ -4,16 +4,14 @@ /* $Id$ */ -String *_oct(i) -int i; +String *_oct(int i) { char buffer[30]; sprintf(buffer,"%o",i); return( (String *)_newstr(buffer)); } -String *_hex(i) -int i; +String *_hex(int i) { char buffer[30]; @@ -21,8 +19,7 @@ int i; return( (String *)_newstr(buffer)); } -String *_nstr(f) - double f; +String *_nstr(double f) { char buffer[80]; diff --git a/lang/basic/lib/peek.c b/lang/basic/lib/peek.c index d4d629d1e..a8810f8b8 100644 --- a/lang/basic/lib/peek.c +++ b/lang/basic/lib/peek.c @@ -1,7 +1,6 @@ /* $Id$ */ -int peek(addr) -int addr; +int peek(int addr) { /* this can not work properly for machines in which the POINTERSIZE differs from the integer size @@ -17,8 +16,7 @@ int addr; return(i); } -_poke(i,j) -int i,j; +void _poke(int i, int j) { char *p; p= (char *) i; diff --git a/lang/basic/lib/print.c b/lang/basic/lib/print.c index a4bdebfc1..d59b58283 100644 --- a/lang/basic/lib/print.c +++ b/lang/basic/lib/print.c @@ -7,19 +7,18 @@ /* Here all routine to generate terminal oriented output is located */ -_qstmark() +void _qstmark(void) { /* prompt for terminal input */ putchar('?'); } -_nl() +void _nl(void) { _asschn(); _outnl(); } -_prinum(i) -int i; +void _prinum(int i) { char buffer[40]; @@ -29,9 +28,7 @@ int i; else sprintf(buffer,"-%d ",-i); _out(buffer); } -_str(f,buffer) -double f; -char *buffer; +void _str(double f, char* buffer) { register char *c = buffer; int eformat = 0; @@ -59,8 +56,7 @@ char *buffer; if( *c=='.') *c=0; } } -_prfnum(f) -double f; +void _prfnum(double f) { /* BASIC strings trailing zeroes */ char buffer[100]; @@ -72,8 +68,7 @@ double f; strcat(buffer," "); _out(buffer); } -_prstr(str) -String *str; +void _prstr(String* str) { _asschn(); if( str==0) _out(""); diff --git a/lang/basic/lib/random.c b/lang/basic/lib/random.c index 17340eddb..2d47e53d4 100644 --- a/lang/basic/lib/random.c +++ b/lang/basic/lib/random.c @@ -5,7 +5,7 @@ #define EM_WSIZE _EM_WSIZE #endif -_randomi() +void _randomi(void) { int i; _setchan(-1); @@ -14,12 +14,11 @@ _randomi() _setrand(i); } -_setrand(i) - int i; +void _setrand(int i) { srand(i); } -double _rnd(d) double d; +double _rnd(double d) { double f; f= (int) rand(); return(f/ diff --git a/lang/basic/lib/read.c b/lang/basic/lib/read.c index e1e4d3893..ac8bba3c9 100644 --- a/lang/basic/lib/read.c +++ b/lang/basic/lib/read.c @@ -4,14 +4,14 @@ /* $Id$ */ -_readln() +void _readln(void) { register int c; while( (c=fgetc(_chanrd)) != EOF && c!= '\n') ; } -readskip() +void readskip(void) { register int c; #ifdef DEBUG @@ -20,8 +20,7 @@ readskip() while( (c=fgetc(_chanrd)) != EOF && c!= ',' && c!= '\n') ; } -_readint(addr) -int *addr; +void _readint(int* addr) { int i; char buf[1024]; @@ -45,8 +44,7 @@ int *addr; error(40); }else { readskip(); *addr=i;} } -_readflt(addr) -double *addr; +void _readflt(double* addr) { double f; char buf[1024]; @@ -69,8 +67,7 @@ double *addr; error(40); }else { readskip(); *addr=f;} } -_readstr(s) -String **s; +void _readstr(String** s) { char buffer[1024]; register int kar ; @@ -130,8 +127,7 @@ String **s; extern int _seektab[]; -_restore(line) -int line; +void _restore(int line) { int nr; char buffer[1024]; @@ -155,8 +151,7 @@ int line; while(nr-- >0 ) fgets(buffer,1024,_chanrd); } } -_rdline(s) -String **s; +void _rdline(String** s) { char buffer[1024]; if( fgets(buffer,1024,_chanrd) == 0) diff --git a/lang/basic/lib/return.c b/lang/basic/lib/return.c index 15798f9d4..a5126bdc6 100644 --- a/lang/basic/lib/return.c +++ b/lang/basic/lib/return.c @@ -5,8 +5,7 @@ int _gotable[MAXNESTING]; int topstk=0; -_gosub(x) -int x; +void _gosub(int x) { /* administer gosub */ #ifdef DEBUG @@ -16,7 +15,7 @@ int x; _gotable[topstk]= x; topstk++; } -_retstmt() +int _retstmt(void) { /* make sure that a return label index is on top of the stack */ diff --git a/lang/basic/lib/salloc.c b/lang/basic/lib/salloc.c index ef221a273..89bb705c5 100644 --- a/lang/basic/lib/salloc.c +++ b/lang/basic/lib/salloc.c @@ -1,7 +1,6 @@ #include -char * salloc(length) -unsigned length; +char * salloc(unsigned length) { char *c, *s; c= malloc(length); @@ -10,8 +9,7 @@ unsigned length; return(c); } -sfree(c) -char *c; +void sfree(char* c) { if( !c ) return; free(c); diff --git a/lang/basic/lib/sgn.c b/lang/basic/lib/sgn.c index 30eeb8a95..8c1d57bf4 100644 --- a/lang/basic/lib/sgn.c +++ b/lang/basic/lib/sgn.c @@ -1,15 +1,13 @@ /* $Id$ */ -_sgn(v) -double v; +int _sgn(double v) { if( v>0) return(1); if( v<0) return(-1); return(0); } -_forsgn(v) -double v; +int _forsgn(double v) { if (v >= 0) return 1; return -1; diff --git a/lang/basic/lib/string.c b/lang/basic/lib/string.c index 4ccc69191..10dfe9e80 100644 --- a/lang/basic/lib/string.c +++ b/lang/basic/lib/string.c @@ -9,14 +9,12 @@ extern char *salloc() ; -_length(str) -String *str; +int _length(String* str) { okr(str); return(str->strlength); } -String *_newstr(str) -char *str; +String *_newstr(char* str) { String *s; okr(str); @@ -27,15 +25,13 @@ char *str; strcpy(s->strval,str); return(s); } -_incstr(src) -String *src; +void _incstr(String* src) { /* one more variable uses the string */ ok(src); src->strcount++; } -_decstr(str) -String *str; +void _decstr(String* str) { ok(str); /* Strings in ROM are initialized with this count */ @@ -43,8 +39,7 @@ String *str; str->strcount--; if(str->strcount<=0) _delstr(str); } -_strcpy(dst,src) -String *src,*dst; +void _strcpy(String* dst, String* src) { ok(src); ok(dst); @@ -52,15 +47,13 @@ String *src,*dst; *dst = *src; _incstr(src); } -_delstr(src) -String *src; +void _delstr(String* src) { ok(src); sfree(src->strval); sfree((char *)src); } -String *_concat(s1,s2) -String *s1,*s2; +String *_concat(String* s1,String* s2) { String *s; int length; @@ -73,16 +66,13 @@ String *s1,*s2; strcat(s->strval,s1->strval); return(s); } -_strcomp(s1,s2) -String *s1,*s2; +int _strcomp(String* s1,String* s2) { okr(s1);okr(s2); return(strcmp(s2->strval,s1->strval)); } -String *_left(size,s) -String *s; -int size; +String *_left(int size, String* s) { String *ns; int i; @@ -99,8 +89,7 @@ int size; return(ns); } -String *_space(d) -int d; +String *_space(int d) { String *s; int i,len; @@ -116,11 +105,10 @@ int d; return(s); } -String *_strascii() +String *_strascii(void) { } -String *_string(f, d) -double d,f; +String *_string(double f, double d) { int i,j; String *s; @@ -136,9 +124,7 @@ double d,f; s->strval[i]= j; return(s); } -_midstmt(s2,i1,i2,s) -int i1,i2; -String *s, *s2; +void _midstmt(String* s2, int i1, int i2, String* s) { int l; @@ -150,9 +136,7 @@ String *s, *s2; if( i1>l ) i1=l; strncpy(s->strval+i2-1,s2->strval,i1); } -String *_mid(i1,i2,s) -int i1,i2; -String *s; +String *_mid(int i1, int i2, String* s) { int l; String *s2; @@ -170,9 +154,7 @@ String *s; return(s2); } -String *_right(length,str) -String *str; -int length; +String *_right(int length, String* str) { String *s; int i; diff --git a/lang/basic/lib/swap.c b/lang/basic/lib/swap.c index a9b745435..17ec21b4b 100644 --- a/lang/basic/lib/swap.c +++ b/lang/basic/lib/swap.c @@ -2,8 +2,7 @@ /* $Id$ */ -_intswap(i1,i2) -int *i1,*i2; +void _intswap(int* i1, int* i2) { int i3; i3= *i1; @@ -11,8 +10,7 @@ int *i1,*i2; *i2=i3; } -_fltswap(i1,i2) -double *i1,*i2; +void _fltswap(double* i1, double* i2) { double i3; i3= *i1; @@ -20,8 +18,7 @@ double *i1,*i2; *i2=i3; } -_strswap(s1,s2) -String **s1,**s2; +void _strswap(String** s1, String** s2) { String *s; s= *s1; diff --git a/lang/basic/lib/trace.c b/lang/basic/lib/trace.c index 5cc86eca2..5a28c6b75 100644 --- a/lang/basic/lib/trace.c +++ b/lang/basic/lib/trace.c @@ -1,7 +1,6 @@ /* $Id$ */ -_trace(i) -int i; +void _trace(int i) { printf("[%d]",i); } diff --git a/lang/basic/lib/trap.c b/lang/basic/lib/trap.c index 4bcf742ee..43c74d6d2 100644 --- a/lang/basic/lib/trap.c +++ b/lang/basic/lib/trap.c @@ -13,15 +13,12 @@ int _trpline; /* BASIC return label */ jmp_buf trpbuf; -_trpset(nr) -int nr; +void _trpset(int nr) { /*debug printf("trap set to %d\n",nr);*/ _trpline=nr; } -void -_trpfatal(i) -int i; +void _trpfatal(int i) { extern int _errsym,_erlsym; @@ -35,7 +32,7 @@ int i; _trap(); } -_ini_trp() +void _ini_trp(void) { /* initialize trap routines */ int i; @@ -45,12 +42,11 @@ _ini_trp() } -_settrap(nr) -int nr; +void _settrap(int nr) { _trpline=nr; } -_trap() +void _trap(void) { int line; diff --git a/lang/basic/lib/write.c b/lang/basic/lib/write.c index 25e3c2f98..fe3adf9ca 100644 --- a/lang/basic/lib/write.c +++ b/lang/basic/lib/write.c @@ -5,30 +5,27 @@ /* assume that the channel has been set */ -_wrnl() +void _wrnl(void) { if( fputc('\n',_chanwr) == EOF) error(29); } -_wrcomma() +void _wrcomma(void) { if( fputc(',',_chanwr) == EOF) error(29); } -_wrint(i) -int i; +void _wrint(int i) { if(i>0) if( fputc(' ',_chanwr)==EOF) error(29); fprintf(_chanwr,"%d",i); if( ferror(_chanwr) ) error(29); } -_wrflt(f) -double f; +void _wrflt(double f) { fprintf(_chanwr,"%f",f); if( ferror(_chanwr) ) error(29); } -_wrstr(s) -String *s; +void _wrstr(String* s) { fprintf(_chanwr,"\"%s\"",s->strval); if( ferror(_chanwr) ) error(29); From 04e54d6cb1b228d9c887f0b3967888c0a5def228 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 12 Dec 2016 21:16:32 +0100 Subject: [PATCH 2/3] Run lang/basic/lib through clang-format. --- lang/basic/lib/abs.c | 6 +- lang/basic/lib/asc.c | 4 +- lang/basic/lib/asrt.c | 3 +- lang/basic/lib/atn.c | 1 - lang/basic/lib/chr.c | 16 +-- lang/basic/lib/conversion.c | 40 ++++---- lang/basic/lib/error.c | 95 ++++++++--------- lang/basic/lib/file.c | 99 +++++++++--------- lang/basic/lib/io.c | 100 +++++++++++------- lang/basic/lib/mki.c | 28 ++--- lang/basic/lib/oct.c | 16 +-- lang/basic/lib/peek.c | 16 +-- lang/basic/lib/power.c | 1 - lang/basic/lib/print.c | 78 ++++++++------ lang/basic/lib/random.c | 11 +- lang/basic/lib/read.c | 129 +++++++++++++---------- lang/basic/lib/return.c | 21 ++-- lang/basic/lib/salloc.c | 17 ++-- lang/basic/lib/sgn.c | 11 +- lang/basic/lib/sin.c | 1 - lang/basic/lib/sqt.c | 1 - lang/basic/lib/string.c | 198 ++++++++++++++++++++---------------- lang/basic/lib/swap.c | 18 ++-- lang/basic/lib/trace.c | 4 +- lang/basic/lib/trap.c | 32 +++--- lang/basic/lib/write.c | 26 +++-- 26 files changed, 534 insertions(+), 438 deletions(-) diff --git a/lang/basic/lib/abs.c b/lang/basic/lib/abs.c index 00f682942..46d6fd39c 100644 --- a/lang/basic/lib/abs.c +++ b/lang/basic/lib/abs.c @@ -7,9 +7,9 @@ long _abl(long i) { - return( i>=0?i:-i); + return (i >= 0 ? i : -i); } double _abr(double f) -{ - return( f>=0.0?f: -f); +{ + return (f >= 0.0 ? f : -f); } diff --git a/lang/basic/lib/asc.c b/lang/basic/lib/asc.c index 3e3585de9..1e7ed8cd0 100644 --- a/lang/basic/lib/asc.c +++ b/lang/basic/lib/asc.c @@ -4,7 +4,7 @@ int _asc(String* str) { - if(str==0 || str->strval==0) + if (str == 0 || str->strval == 0) error(3); - return( *str->strval); + return (*str->strval); } diff --git a/lang/basic/lib/asrt.c b/lang/basic/lib/asrt.c index 8d0b40b86..1517eb580 100644 --- a/lang/basic/lib/asrt.c +++ b/lang/basic/lib/asrt.c @@ -3,7 +3,8 @@ void asrt(int b) { - if(!b){ + if (!b) + { printf("ASSERTION ERROR\n"); abort(); } diff --git a/lang/basic/lib/atn.c b/lang/basic/lib/atn.c index 18c4dc6ef..4b3247d68 100644 --- a/lang/basic/lib/atn.c +++ b/lang/basic/lib/atn.c @@ -10,4 +10,3 @@ #include double _atn(double x) { return atan(x); } - diff --git a/lang/basic/lib/chr.c b/lang/basic/lib/chr.c index 5825ec1e6..527f1537b 100644 --- a/lang/basic/lib/chr.c +++ b/lang/basic/lib/chr.c @@ -2,15 +2,15 @@ /* $Id$ */ -String *_chr(int i) +String* _chr(int i) { - String *s; - char buf[2]; + String* s; + char buf[2]; - if( i<0 || i>127) + if (i < 0 || i > 127) error(3); - buf[0]=i; - buf[1]=0; - s= _newstr(buf); - return(s); + buf[0] = i; + buf[1] = 0; + s = _newstr(buf); + return (s); } diff --git a/lang/basic/lib/conversion.c b/lang/basic/lib/conversion.c index e65650fb6..4667b1ce9 100644 --- a/lang/basic/lib/conversion.c +++ b/lang/basic/lib/conversion.c @@ -3,36 +3,42 @@ int _cint(double f) { int r; - if( f<-32768 || f>32767) error(4); - if(f<0) - r= f-0.5; - else r= f+0.5; - return(r); + if (f < -32768 || f > 32767) + error(4); + if (f < 0) + r = f - 0.5; + else + r = f + 0.5; + return (r); } double _trunc(double f) { long d; - d=f; - f=d; - return( f ); + d = f; + f = d; + return (f); } double _fcint(double f) { long r; - if(f<0){ - r= -f; - r= -r -1; - }else r= f; - f=r; - return(f); + if (f < 0) + { + r = -f; + r = -r - 1; + } + else + r = f; + f = r; + return (f); } int _fix(double f) { int r; - if( f<-32768.0 || f>32767.0) error(4); - r= _sgn(f) * _fcint((f>0.0? f : -f)); - return(r); + if (f < -32768.0 || f > 32767.0) + error(4); + r = _sgn(f) * _fcint((f > 0.0 ? f : -f)); + return (r); } diff --git a/lang/basic/lib/error.c b/lang/basic/lib/error.c index 4ab981639..b526377c2 100644 --- a/lang/basic/lib/error.c +++ b/lang/basic/lib/error.c @@ -7,57 +7,58 @@ int _erlsym; /* error takes an error value in the range of 0-255 */ /* and generates a trap */ -char *errortable[255]={ -/* 0 */ "", -/* 1 */ "RETURN without GOSUB", -/* 2 */ "Out of data", -/* 3 */ "Illegal function call", -/* 4 */ "Overflow", -/* 5 */ "Out of memory", -/* 6 */ "Undefined line ", -/* 7 */ "Subscript out of range", -/* 8 */ "Redimensioned array", -/* 9 */ "Division by zero", -/* 10 */ "Illegal indirect", -/* 11 */ "Type mismatch", -/* 12 */ "Out of string space", -/* 13 */ "String too long", -/* 14 */ "String formula too complex", -/* 15 */ "Can't continue", -/* 16 */ "Undefined user function", -/* 17 */ "No resume", -/* 18 */ "Resume without error", -/* 19 */ "Unprintable error", -/* 20 */ "Missing operand", -/* 21 */ "Line buffer overflow", -/* 22 */ "FOR without NEXT", -/* 23 */ "WHILE without WEND", -/* 24 */ "WEND without WHILE", -/* 25 */ "Field overflow", -/* 26 */ "Internal error", -/* 27 */ "Bad file number", -/* 28 */ "File not found", -/* 29 */ "Bad file mode", -/* 30 */ "File already open", -/* 31 */ "Disk IO error", -/* 32 */ "File already exists", -/* 33 */ "Disk full", -/* 34 */ "Input past end", -/* 35 */ "Bad record number", -/* 36 */ "Bad file name", -/* 37 */ "Direct statement in file", -/* 38 */ "Too many files", -/* 39 */ "File not open", -/* 40 */ "Syntax error in data", -0 +char* errortable[255] = { + /* 0 */ "", + /* 1 */ "RETURN without GOSUB", + /* 2 */ "Out of data", + /* 3 */ "Illegal function call", + /* 4 */ "Overflow", + /* 5 */ "Out of memory", + /* 6 */ "Undefined line ", + /* 7 */ "Subscript out of range", + /* 8 */ "Redimensioned array", + /* 9 */ "Division by zero", + /* 10 */ "Illegal indirect", + /* 11 */ "Type mismatch", + /* 12 */ "Out of string space", + /* 13 */ "String too long", + /* 14 */ "String formula too complex", + /* 15 */ "Can't continue", + /* 16 */ "Undefined user function", + /* 17 */ "No resume", + /* 18 */ "Resume without error", + /* 19 */ "Unprintable error", + /* 20 */ "Missing operand", + /* 21 */ "Line buffer overflow", + /* 22 */ "FOR without NEXT", + /* 23 */ "WHILE without WEND", + /* 24 */ "WEND without WHILE", + /* 25 */ "Field overflow", + /* 26 */ "Internal error", + /* 27 */ "Bad file number", + /* 28 */ "File not found", + /* 29 */ "Bad file mode", + /* 30 */ "File already open", + /* 31 */ "Disk IO error", + /* 32 */ "File already exists", + /* 33 */ "Disk full", + /* 34 */ "Input past end", + /* 35 */ "Bad record number", + /* 36 */ "Bad file name", + /* 37 */ "Direct statement in file", + /* 38 */ "Too many files", + /* 39 */ "File not open", + /* 40 */ "Syntax error in data", + 0 }; void error(int index) { _setline(); - if( index<0 || index >40 ) - printf("LINE %d:ERROR %d: Unprintable error\n",_erlsym,index); - else printf("LINE %d:ERROR %d: %s\n",_erlsym,index,errortable[index]); - _errsym= index; + if (index < 0 || index > 40) + printf("LINE %d:ERROR %d: Unprintable error\n", _erlsym, index); + else + printf("LINE %d:ERROR %d: %s\n", _erlsym, index, errortable[index]); + _errsym = index; _trap(); } diff --git a/lang/basic/lib/file.c b/lang/basic/lib/file.c index f6ba63cf1..3c558a82a 100644 --- a/lang/basic/lib/file.c +++ b/lang/basic/lib/file.c @@ -4,7 +4,7 @@ /* $Id$ */ -Filedesc _fdtable[16]; +Filedesc _fdtable[16]; /* BASIC file descriptor table */ /* Channel assignment: -1 terminal IO @@ -12,119 +12,122 @@ Filedesc _fdtable[16]; 1-15 user files */ - - -int _chann = -1; -FILE *_chanrd = stdin; -FILE *_chanwr = stdout; +int _chann = -1; +FILE* _chanrd = stdin; +FILE* _chanwr = stdout; void _setchan(int index) { #ifdef DEBUG - printf("setchannel %d\n",index); + printf("setchannel %d\n", index); #endif fflush(_chanwr); - if( index == -1) + if (index == -1) { - _chann= -1; - _chanrd= stdin; - _chanwr= stdout; + _chann = -1; + _chanrd = stdin; + _chanwr = stdout; return; } - if( index<0 || index>15) + if (index < 0 || index > 15) error(27); - _chann=index; - _chanrd= _chanwr= _fdtable[index].fd; + _chann = index; + _chanrd = _chanwr = _fdtable[index].fd; } void _asschn(void) { #ifdef DEBUG - printf("_asschn %d\n",_chann); + printf("_asschn %d\n", _chann); #endif - if( _chann == -1) return; + if (_chann == -1) + return; #ifdef DEBUG printf(" file %d\n", _fdtable[_chann].fd); #endif - if( _chann<0 || _chann>15) + if (_chann < 0 || _chann > 15) error(27); - if( _fdtable[_chann].fd== 0) + if (_fdtable[_chann].fd == 0) error(39); - if( feof( _fdtable[_chann].fd)) + if (feof(_fdtable[_chann].fd)) error(2); } void _clochn(int nr) { - if( nr<1 || nr >15 || _fdtable[nr].fd==0) error(3); + if (nr < 1 || nr > 15 || _fdtable[nr].fd == 0) + error(3); fclose(_fdtable[nr].fd); - _fdtable[nr].fd=0; _fdtable[nr].fname=0; + _fdtable[nr].fd = 0; + _fdtable[nr].fname = 0; } void _opnchn(int reclen, String* fname, String* mode) { /* channel has been set */ - FILE *f; + FILE* f; int m; #ifdef DEBUG - printf("open %d %s %s \n",reclen,mode->strval,fname->strval); + printf("open %d %s %s \n", reclen, mode->strval, fname->strval); #endif /* check for opened/closed file */ - if(_fdtable[_chann].fd) + if (_fdtable[_chann].fd) error(30); - switch(*mode->strval) + switch (*mode->strval) { case 'O': case 'o': - if( (f=fopen(fname->strval,"w")) == NULL) + if ((f = fopen(fname->strval, "w")) == NULL) error(28); - m= OMODE; + m = OMODE; break; case 'I': case 'i': - if( (f=fopen(fname->strval,"r")) == NULL) + if ((f = fopen(fname->strval, "r")) == NULL) error(28); - m= IMODE; + m = IMODE; break; case 'r': case 'R': - if( (f=fopen(fname->strval,"a")) == NULL) + if ((f = fopen(fname->strval, "a")) == NULL) error(28); - m= RMODE; + m = RMODE; break; default: - printf("file mode %s\n",mode->strval); + printf("file mode %s\n", mode->strval); error(29); } - _chanwr= _chanrd= _fdtable[_chann].fd= f; - _fdtable[_chann].fname= fname->strval; - _fdtable[_chann].reclength= reclen; - _fdtable[_chann].mode= m; + _chanwr = _chanrd = _fdtable[_chann].fd = f; + _fdtable[_chann].fname = fname->strval; + _fdtable[_chann].reclength = reclen; + _fdtable[_chann].mode = m; #ifdef DEBUG - printf("file descr %d\n",f); + printf("file descr %d\n", f); #endif } int _ioeof(int channel) { - FILE *fd; + FILE* fd; char c; - if( channel<0 || channel >15) error(3); - fd= _fdtable[channel].fd; - if( fd==0) + if (channel < 0 || channel > 15) error(3); - c=fgetc(fd); - if( feof(_fdtable[channel].fd) ) return(-1); - ungetc(c,fd); - return(0); + fd = _fdtable[channel].fd; + if (fd == 0) + error(3); + c = fgetc(fd); + if (feof(_fdtable[channel].fd)) + return (-1); + ungetc(c, fd); + return (0); } void _close(void) { /* close all open files */ int i; - for(i=1;i<16;i++) - if( _fdtable[i].fd) - _clochn(i); + for (i = 1; i < 16; i++) + if (_fdtable[i].fd) + _clochn(i); } diff --git a/lang/basic/lib/io.c b/lang/basic/lib/io.c index 842cd16e5..dd1f6cf2a 100644 --- a/lang/basic/lib/io.c +++ b/lang/basic/lib/io.c @@ -8,80 +8,102 @@ #define MAXWIDTH 255 -int _width = 75, _pos=0, _zonewidth=15; +int _width = 75, _pos = 0, _zonewidth = 15; void _out(char* str) { int pos; - if( _chann== -1) pos= _pos; - else pos= _fdtable[_chann].pos; - while( *str) + if (_chann == -1) + pos = _pos; + else + pos = _fdtable[_chann].pos; + while (*str) { - if( pos>= _width){ _outnl(); pos=0;} + if (pos >= _width) + { + _outnl(); + pos = 0; + } fputc(*str++, _chanwr); pos++; } - if( _chann== -1) _pos=pos; - else _fdtable[_chann].pos= pos; + if (_chann == -1) + _pos = pos; + else + _fdtable[_chann].pos = pos; } void _outnl(void) { - fputc('\n',_chanwr); - if( _chann == -1) - _pos=0; + fputc('\n', _chanwr); + if (_chann == -1) + _pos = 0; else - _fdtable[_chann].pos=0; + _fdtable[_chann].pos = 0; } void _zone(void) { /* go to next zone */ int pos; - if( _chann == -1) - pos= _pos; - else pos= _fdtable[_chann].pos; - do{ - fputc(' ',_chanwr); + if (_chann == -1) + pos = _pos; + else + pos = _fdtable[_chann].pos; + do + { + fputc(' ', _chanwr); pos++; - if( pos==_width) + if (pos == _width) { _outnl(); - pos=0; + pos = 0; break; } - } while( pos % _zonewidth != 0); - if( _chann== -1) _pos=pos; - else _fdtable[_chann].pos= pos; + } while (pos % _zonewidth != 0); + if (_chann == -1) + _pos = pos; + else + _fdtable[_chann].pos = pos; } void _in(char* buf) { - register int holder ; - char *c; + register int holder; + char* c; int pos; - if( _chann == -1) + if (_chann == -1) { - pos= _pos; - }else pos= _fdtable[_chann].pos; - c= buf; - while( (holder = fgetc(_chanrd)) != EOF && holder != '\n'){ - *c= holder ; - if( _chann == -1) putchar(holder); - c++; pos++; + pos = _pos; } - *c= 0; - if( _chann== -1) + else + pos = _fdtable[_chann].pos; + c = buf; + while ((holder = fgetc(_chanrd)) != EOF && holder != '\n') { - _pos=pos; - } else _fdtable[_chann].pos= pos; + *c = holder; + if (_chann == -1) + putchar(holder); + c++; + pos++; + } + *c = 0; + if (_chann == -1) + { + _pos = pos; + } + else + _fdtable[_chann].pos = pos; } void _tab(int x) { - if( x> _width) error(3); - if( x< _pos) _outnl(); - _spc(x-_pos); + if (x > _width) + error(3); + if (x < _pos) + _outnl(); + _spc(x - _pos); } void _spc(int x) { - while(x-->0) _out(" "); + while (x-- > 0) + _out(" "); } diff --git a/lang/basic/lib/mki.c b/lang/basic/lib/mki.c index ce2822c8c..f14d18da5 100644 --- a/lang/basic/lib/mki.c +++ b/lang/basic/lib/mki.c @@ -2,29 +2,29 @@ /* $Id$ */ -String *_mki(long i) +String* _mki(long i) { - char *buffer =" "; - String *s; + char* buffer = " "; + String* s; - s= _newstr(buffer); - * ( (long *)s->strval ) = i ; - return(s); + s = _newstr(buffer); + *((long*)s->strval) = i; + return (s); } -String *_mkd(double d) +String* _mkd(double d) { - char *buffer =" "; - String *s; + char* buffer = " "; + String* s; - s= _newstr(buffer); - * ( (double *)s->strval ) = d ; - return(s); + s = _newstr(buffer); + *((double*)s->strval) = d; + return (s); } long _cvi(String* s) { - return *( (long *) s->strval) ; + return *((long*)s->strval); } double _cvd(String* s) { - return *( (double *) s->strval) ; + return *((double*)s->strval); } diff --git a/lang/basic/lib/oct.c b/lang/basic/lib/oct.c index 04a0c34e0..fb7eb419f 100644 --- a/lang/basic/lib/oct.c +++ b/lang/basic/lib/oct.c @@ -4,25 +4,25 @@ /* $Id$ */ -String *_oct(int i) +String* _oct(int i) { char buffer[30]; - sprintf(buffer,"%o",i); - return( (String *)_newstr(buffer)); + sprintf(buffer, "%o", i); + return ((String*)_newstr(buffer)); } -String *_hex(int i) +String* _hex(int i) { char buffer[30]; - sprintf(buffer,"%x",i); - return( (String *)_newstr(buffer)); + sprintf(buffer, "%x", i); + return ((String*)_newstr(buffer)); } -String *_nstr(double f) +String* _nstr(double f) { char buffer[80]; _str(f, buffer); - return (String *) _newstr(buffer); + return (String*)_newstr(buffer); } diff --git a/lang/basic/lib/peek.c b/lang/basic/lib/peek.c index a8810f8b8..a3383f761 100644 --- a/lang/basic/lib/peek.c +++ b/lang/basic/lib/peek.c @@ -5,20 +5,20 @@ int peek(int addr) /* this can not work properly for machines in which the POINTERSIZE differs from the integer size */ - char *p; + char* p; int i; - p= (char *)addr; - i= *p; + p = (char*)addr; + i = *p; #ifdef DEBUG - printf("peek %d = %d\n",addr,i); + printf("peek %d = %d\n", addr, i); #endif - return(i); + return (i); } void _poke(int i, int j) { - char *p; - p= (char *) i; - *p=j; + char* p; + p = (char*)i; + *p = j; } diff --git a/lang/basic/lib/power.c b/lang/basic/lib/power.c index 4a33806cd..a22d8e5a5 100644 --- a/lang/basic/lib/power.c +++ b/lang/basic/lib/power.c @@ -1,4 +1,3 @@ #include double _power(double x, double y) { return pow(x, y); } - diff --git a/lang/basic/lib/print.c b/lang/basic/lib/print.c index d59b58283..c2078058f 100644 --- a/lang/basic/lib/print.c +++ b/lang/basic/lib/print.c @@ -20,57 +20,71 @@ void _nl(void) } void _prinum(int i) { - char buffer[40]; + char buffer[40]; _asschn(); - if(i>=0) - sprintf(buffer," %d ",i); - else sprintf(buffer,"-%d ",-i); + if (i >= 0) + sprintf(buffer, " %d ", i); + else + sprintf(buffer, "-%d ", -i); _out(buffer); } void _str(double f, char* buffer) { - register char *c = buffer; + register char* c = buffer; int eformat = 0; - if( f>=0){ - if( f> 1.0e8) { - eformat = 1; - sprintf(buffer," %e",f); - } - else sprintf(buffer," %f",f); - c++; - }else { - if(-f> 1.0e8) { - eformat = 1; - sprintf(buffer,"-%e",-f); - } - else sprintf(buffer,"-%f",-f); - } - if (! eformat) { - for( ; *c && *c!= ' ';c++) ; - c--; - while( c>buffer && *c== '0') + if (f >= 0) + { + if (f > 1.0e8) { - *c= 0;c--; + eformat = 1; + sprintf(buffer, " %e", f); } - if( *c=='.') *c=0; + else + sprintf(buffer, " %f", f); + c++; + } + else + { + if (-f > 1.0e8) + { + eformat = 1; + sprintf(buffer, "-%e", -f); + } + else + sprintf(buffer, "-%f", -f); + } + if (!eformat) + { + for (; *c && *c != ' '; c++) + ; + c--; + while (c > buffer && *c == '0') + { + *c = 0; + c--; + } + if (*c == '.') + *c = 0; } } void _prfnum(double f) { /* BASIC strings trailing zeroes */ - char buffer[100]; - char *c; + char buffer[100]; + char* c; _asschn(); - c= buffer; - _str(f,c); - strcat(buffer," "); + c = buffer; + _str(f, c); + strcat(buffer, " "); _out(buffer); } void _prstr(String* str) { _asschn(); - if( str==0) _out(""); - else _out(str->strval); + if (str == 0) + _out(""); + else + _out(str->strval); } diff --git a/lang/basic/lib/random.c b/lang/basic/lib/random.c index 2d47e53d4..511c877b0 100644 --- a/lang/basic/lib/random.c +++ b/lang/basic/lib/random.c @@ -20,12 +20,13 @@ void _setrand(int i) } double _rnd(double d) { - double f; f= (int) rand(); - return(f/ + double f; + f = (int)rand(); + return (f / #if EM_WSIZE == 4 - 2147483647.0 + 2147483647.0 #else - 32767.0 + 32767.0 #endif - ); + ); } diff --git a/lang/basic/lib/read.c b/lang/basic/lib/read.c index ac8bba3c9..63061fc8e 100644 --- a/lang/basic/lib/read.c +++ b/lang/basic/lib/read.c @@ -7,7 +7,7 @@ void _readln(void) { register int c; - while( (c=fgetc(_chanrd)) != EOF && c!= '\n') + while ((c = fgetc(_chanrd)) != EOF && c != '\n') ; } @@ -17,32 +17,39 @@ void readskip(void) #ifdef DEBUG printf("readskip\n"); #endif - while( (c=fgetc(_chanrd)) != EOF && c!= ',' && c!= '\n') + while ((c = fgetc(_chanrd)) != EOF && c != ',' && c != '\n') ; } void _readint(int* addr) { int i; - char buf[1024]; + char buf[1024]; #ifdef DEBUG - printf("read int from %d\n",_chann); + printf("read int from %d\n", _chann); #endif _asschn(); - if( fscanf(_chanrd,"%d",&i) != 1) + if (fscanf(_chanrd, "%d", &i) != 1) { - if( ferror(_chanrd)) error(29); - if( feof(_chanrd)) error(2); - if( _chann == -1) + if (ferror(_chanrd)) + error(29); + if (feof(_chanrd)) + error(2); + if (_chann == -1) { - _asschn(); /* may be closed by now */ - fgets(buf,1024,_chanrd); + _asschn(); /* may be closed by now */ + fgets(buf, 1024, _chanrd); printf("?Redo "); _readint(addr); return; } error(40); - }else { readskip(); *addr=i;} + } + else + { + readskip(); + *addr = i; + } } void _readflt(double* addr) { @@ -50,66 +57,77 @@ void _readflt(double* addr) char buf[1024]; #ifdef DEBUG - printf("read flt from %d\n",_chann); + printf("read flt from %d\n", _chann); #endif _asschn(); - if( fscanf(_chanrd,"%lf",&f) != 1) + if (fscanf(_chanrd, "%lf", &f) != 1) { - if( ferror(_chanrd)) error(29); - if( feof(_chanrd)) error(2); - if( _chann == -1) + if (ferror(_chanrd)) + error(29); + if (feof(_chanrd)) + error(2); + if (_chann == -1) { - fgets(buf,1024,_chanrd); + fgets(buf, 1024, _chanrd); printf("?Redo "); _readflt(addr); return; } error(40); - }else { readskip(); *addr=f;} + } + else + { + readskip(); + *addr = f; + } } void _readstr(String** s) { char buffer[1024]; - register int kar ; - char *c; + register int kar; + char* c; #ifdef DEBUG - printf("read str from %d\n",_chann); + printf("read str from %d\n", _chann); #endif _asschn(); - c= buffer; - kar= fgetc(_chanrd); - while(isspace(kar) && kar!= EOF) - kar= fgetc(_chanrd); - *c=kar ; - if( kar== '"') + c = buffer; + kar = fgetc(_chanrd); + while (isspace(kar) && kar != EOF) + kar = fgetc(_chanrd); + *c = kar; + if (kar == '"') { - /* read quoted string */ +/* read quoted string */ #ifdef DEBUG printf("qouted string\n"); #endif - while ( (kar= fgetc(_chanrd)) != EOF && kar!='"' ) *c++ = kar ; - ungetc(kar,_chanrd); - *c=0; - }else - if( isalpha(*c)) + while ((kar = fgetc(_chanrd)) != EOF && kar != '"') + *c++ = kar; + ungetc(kar, _chanrd); + *c = 0; + } + else if (isalpha(*c)) { /* read normal string */ c++; #ifdef DEBUG printf("non-qouted string\n"); #endif - while( (kar= fgetc(_chanrd)) != ',' && kar!= EOF && - !isspace(kar) && kar!='\n') - *c++= kar ; - ungetc(kar,_chanrd); - *c=0; - }else{ - if( ferror(_chanrd)) error(29); - if( feof(_chanrd)) error(2); - if( _chann == -1) + while ((kar = fgetc(_chanrd)) != ',' && kar != EOF && !isspace(kar) && kar != '\n') + *c++ = kar; + ungetc(kar, _chanrd); + *c = 0; + } + else + { + if (ferror(_chanrd)) + error(29); + if (feof(_chanrd)) + error(2); + if (_chann == -1) { - fgets(buffer,1024,_chanrd); + fgets(buffer, 1024, _chanrd); printf("?Redo "); _rdline(s); return; @@ -117,12 +135,12 @@ void _readstr(String** s) error(40); } #ifdef DEBUG - printf("string read: %s\n",buffer); + printf("string read: %s\n", buffer); #endif readskip(); /* save value read */ _decstr(*s); - *s= (String *) _newstr(buffer); + *s = (String*)_newstr(buffer); } extern int _seektab[]; @@ -133,30 +151,31 @@ void _restore(int line) char buffer[1024]; #ifdef DEBUG - printf("seek to %d",line); + printf("seek to %d", line); #endif - fseek(_chanrd,0l,0); - if( line) + fseek(_chanrd, 0l, 0); + if (line) { /* search number of lines to skip */ - for(nr=0; _seektab[nr] && _seektab[nr]< line; nr+=2) + for (nr = 0; _seektab[nr] && _seektab[nr] < line; nr += 2) #ifdef DEBUG - printf("test %d %d\n",_seektab[nr], _seektab[nr+1]); + printf("test %d %d\n", _seektab[nr], _seektab[nr + 1]); #endif ; nr /= 2; #ifdef DEBUG - printf(" %d lines to skip\n",nr); + printf(" %d lines to skip\n", nr); #endif - while(nr-- >0 ) fgets(buffer,1024,_chanrd); + while (nr-- > 0) + fgets(buffer, 1024, _chanrd); } } void _rdline(String** s) { char buffer[1024]; - if( fgets(buffer,1024,_chanrd) == 0) + if (fgets(buffer, 1024, _chanrd) == 0) { - if( _chann == -1) + if (_chann == -1) { printf("?Redo "); _rdline(s); @@ -165,5 +184,5 @@ void _rdline(String** s) error(40); } _decstr(*s); - *s= (String *) _newstr(buffer); + *s = (String*)_newstr(buffer); } diff --git a/lang/basic/lib/return.c b/lang/basic/lib/return.c index a5126bdc6..d6b122e01 100644 --- a/lang/basic/lib/return.c +++ b/lang/basic/lib/return.c @@ -1,28 +1,29 @@ /* $Id$ */ -#define MAXNESTING 1000 +#define MAXNESTING 1000 int _gotable[MAXNESTING]; -int topstk=0; +int topstk = 0; void _gosub(int x) { - /* administer gosub */ +/* administer gosub */ #ifdef DEBUG - printf("store %d in %d\n",x,topstk); + printf("store %d in %d\n", x, topstk); #endif - if( topstk== MAXNESTING) error(26); - _gotable[topstk]= x; + if (topstk == MAXNESTING) + error(26); + _gotable[topstk] = x; topstk++; } int _retstmt(void) { - /* make sure that a return label index is on top +/* make sure that a return label index is on top of the stack */ #ifdef DEBUG - printf("return to %d %d\n",_gotable[topstk-1],topstk-1); + printf("return to %d %d\n", _gotable[topstk - 1], topstk - 1); #endif - if( topstk==0 || topstk==MAXNESTING) + if (topstk == 0 || topstk == MAXNESTING) error(1); - return( _gotable[--topstk]); + return (_gotable[--topstk]); } diff --git a/lang/basic/lib/salloc.c b/lang/basic/lib/salloc.c index 89bb705c5..0970df509 100644 --- a/lang/basic/lib/salloc.c +++ b/lang/basic/lib/salloc.c @@ -1,16 +1,19 @@ #include -char * salloc(unsigned length) +char* salloc(unsigned length) { - char *c, *s; - c= malloc(length); - if( !c ) error(5); - for(s=c;s0) return(1); - if( v<0) return(-1); - return(0); + if (v > 0) + return (1); + if (v < 0) + return (-1); + return (0); } int _forsgn(double v) { - if (v >= 0) return 1; + if (v >= 0) + return 1; return -1; } diff --git a/lang/basic/lib/sin.c b/lang/basic/lib/sin.c index 6503d92e6..559736c54 100644 --- a/lang/basic/lib/sin.c +++ b/lang/basic/lib/sin.c @@ -13,4 +13,3 @@ double _sin(double x) { return sin(x); } double _cos(double x) { return cos(x); } double _tan(double x) { return tan(x); } - diff --git a/lang/basic/lib/sqt.c b/lang/basic/lib/sqt.c index b71483ef7..d0fe07f18 100644 --- a/lang/basic/lib/sqt.c +++ b/lang/basic/lib/sqt.c @@ -11,4 +11,3 @@ #include double _sqt(double x) { return sqrt(x); } - diff --git a/lang/basic/lib/string.c b/lang/basic/lib/string.c index 10dfe9e80..4c3d7a390 100644 --- a/lang/basic/lib/string.c +++ b/lang/basic/lib/string.c @@ -4,26 +4,30 @@ /* $Id$ */ -#define ok(X) if( X ==0) return; -#define okr(X) if( X ==0) return(0); +#define ok(X) \ + if (X == 0) \ + return; +#define okr(X) \ + if (X == 0) \ + return (0); -extern char *salloc() ; +extern char* salloc(); int _length(String* str) { okr(str); - return(str->strlength); + return (str->strlength); } -String *_newstr(char* str) +String* _newstr(char* str) { - String *s; + String* s; okr(str); - s= (String *) salloc(sizeof(String)); - s->strcount=1; - s->strlength= strlen(str); - s->strval= salloc(s->strlength+1); - strcpy(s->strval,str); - return(s); + s = (String*)salloc(sizeof(String)); + s->strcount = 1; + s->strlength = strlen(str); + s->strval = salloc(s->strlength + 1); + strcpy(s->strval, str); + return (s); } void _incstr(String* src) { @@ -35,9 +39,11 @@ void _decstr(String* str) { ok(str); /* Strings in ROM are initialized with this count */ - if ( str->strcount==9999 ) return ; + if (str->strcount == 9999) + return; str->strcount--; - if(str->strcount<=0) _delstr(str); + if (str->strcount <= 0) + _delstr(str); } void _strcpy(String* dst, String* src) { @@ -51,116 +57,130 @@ void _delstr(String* src) { ok(src); sfree(src->strval); - sfree((char *)src); + sfree((char*)src); } -String *_concat(String* s1,String* s2) +String* _concat(String* s1, String* s2) { - String *s; + String* s; int length; - okr(s1); okr(s2); - s= (String *) salloc(sizeof(String)); - s->strlength= _length(s1)+_length(s2); - s->strval= salloc(s->strlength+1); + okr(s1); + okr(s2); + s = (String*)salloc(sizeof(String)); + s->strlength = _length(s1) + _length(s2); + s->strval = salloc(s->strlength + 1); s->strcount = 1; - strcpy(s->strval,s2->strval); - strcat(s->strval,s1->strval); - return(s); + strcpy(s->strval, s2->strval); + strcat(s->strval, s1->strval); + return (s); } -int _strcomp(String* s1,String* s2) +int _strcomp(String* s1, String* s2) { - okr(s1);okr(s2); - return(strcmp(s2->strval,s1->strval)); + okr(s1); + okr(s2); + return (strcmp(s2->strval, s1->strval)); } -String *_left(int size, String* s) +String* _left(int size, String* s) { - String *ns; + String* ns; int i; okr(s); - if( size <0 || size >s->strlength) error(3); - ns= (String *) salloc(sizeof(String)); - ns->strval= salloc(size+1); - ns->strcount=1; - for(i=0; istrval[i];i++) - ns->strval[i]= s->strval[i]; - ns->strval[i]=0; - ns->strlength= i; - return(ns); + if (size < 0 || size > s->strlength) + error(3); + ns = (String*)salloc(sizeof(String)); + ns->strval = salloc(size + 1); + ns->strcount = 1; + for (i = 0; i < size && s->strval[i]; i++) + ns->strval[i] = s->strval[i]; + ns->strval[i] = 0; + ns->strlength = i; + return (ns); } -String *_space(int d) +String* _space(int d) { - String *s; - int i,len; + String* s; + int i, len; - len= d; - s= (String *) salloc(sizeof(String)); - s->strlength= len; - s->strcount=1; - s->strval= salloc(len+1); - for(i=0;istrval[i]= ' '; - s->strval[i]=0; - return(s); + len = d; + s = (String*)salloc(sizeof(String)); + s->strlength = len; + s->strcount = 1; + s->strval = salloc(len + 1); + for (i = 0; i < len; i++) + s->strval[i] = ' '; + s->strval[i] = 0; + return (s); } -String *_strascii(void) +String* _strascii(void) { } -String *_string(double f, double d) +String* _string(double f, double d) { - int i,j; - String *s; + int i, j; + String* s; - i=d;j=f; - if( i<0 || i>MAXSTRING) error(3); - s= (String *) salloc(sizeof(String)); - s->strlength= i; - s->strcount=1; - s->strval= salloc(i+1); - s->strval[i--]=0; - for(; i>=0;i--) - s->strval[i]= j; - return(s); + i = d; + j = f; + if (i < 0 || i > MAXSTRING) + error(3); + s = (String*)salloc(sizeof(String)); + s->strlength = i; + s->strcount = 1; + s->strval = salloc(i + 1); + s->strval[i--] = 0; + for (; i >= 0; i--) + s->strval[i] = j; + return (s); } void _midstmt(String* s2, int i1, int i2, String* s) { int l; /*printf("mid called %d %d %s %s\n",i1,i2,s->strval, s2->strval);*/ - if (i2 < 0 || i1 < -1) error(3); - if( s->strlengthstrlength < i1) error(3); /* source string too short */ - if( i1== -1) i1= s2->strlength; - l= s->strlength - i2+1; - if( i1>l ) i1=l; - strncpy(s->strval+i2-1,s2->strval,i1); + if (i2 < 0 || i1 < -1) + error(3); + if (s->strlength < i2 || s2->strlength < i1) + error(3); /* source string too short */ + if (i1 == -1) + i1 = s2->strlength; + l = s->strlength - i2 + 1; + if (i1 > l) + i1 = l; + strncpy(s->strval + i2 - 1, s2->strval, i1); } -String *_mid(int i1, int i2, String* s) +String* _mid(int i1, int i2, String* s) { int l; - String *s2; + String* s2; -/* printf("mid fcn called %d %d %s\n",i1,i2,s->strval);*/ - if (i2 < 0 || i1 < -1) return(s2); /* or error? */ - if( i1 == -1) i1= s->strlength; - s2= _newstr(s->strval); - s2->strval[0]=0; - if( s->strlengthstrlength - i2+1; - if( i1>l ) i1=l; - strncpy(s2->strval,s->strval+i2-1,i1); - s2->strval[i1]=0; - return(s2); + /* printf("mid fcn called %d %d %s\n",i1,i2,s->strval);*/ + if (i2 < 0 || i1 < -1) + return (s2); /* or error? */ + if (i1 == -1) + i1 = s->strlength; + s2 = _newstr(s->strval); + s2->strval[0] = 0; + if (s->strlength < i2) + return (s2); /* source string too short */ + l = s->strlength - i2 + 1; + if (i1 > l) + i1 = l; + strncpy(s2->strval, s->strval + i2 - 1, i1); + s2->strval[i1] = 0; + return (s2); } -String *_right(int length, String* str) +String* _right(int length, String* str) { - String *s; + String* s; int i; - i= _length(str)-length; - if(i<0) i=0; - s= _newstr(str->strval+i); - return(s); + i = _length(str) - length; + if (i < 0) + i = 0; + s = _newstr(str->strval + i); + return (s); } diff --git a/lang/basic/lib/swap.c b/lang/basic/lib/swap.c index 17ec21b4b..af74894cb 100644 --- a/lang/basic/lib/swap.c +++ b/lang/basic/lib/swap.c @@ -5,23 +5,23 @@ void _intswap(int* i1, int* i2) { int i3; - i3= *i1; - *i1= *i2; - *i2=i3; + i3 = *i1; + *i1 = *i2; + *i2 = i3; } void _fltswap(double* i1, double* i2) { double i3; - i3= *i1; - *i1= *i2; - *i2=i3; + i3 = *i1; + *i1 = *i2; + *i2 = i3; } void _strswap(String** s1, String** s2) { - String *s; - s= *s1; - *s1= *s2; + String* s; + s = *s1; + *s1 = *s2; *s2 = s; } diff --git a/lang/basic/lib/trace.c b/lang/basic/lib/trace.c index 5a28c6b75..a84c14129 100644 --- a/lang/basic/lib/trace.c +++ b/lang/basic/lib/trace.c @@ -1,6 +1,6 @@ /* $Id$ */ void _trace(int i) -{ -printf("[%d]",i); +{ + printf("[%d]", i); } diff --git a/lang/basic/lib/trap.c b/lang/basic/lib/trap.c index 43c74d6d2..9d4085a69 100644 --- a/lang/basic/lib/trap.c +++ b/lang/basic/lib/trap.c @@ -10,24 +10,24 @@ /* $Id$ */ /* Trap handling */ -int _trpline; /* BASIC return label */ -jmp_buf trpbuf; +int _trpline; /* BASIC return label */ +jmp_buf trpbuf; void _trpset(int nr) { /*debug printf("trap set to %d\n",nr);*/ - _trpline=nr; + _trpline = nr; } void _trpfatal(int i) { - extern int _errsym,_erlsym; + extern int _errsym, _erlsym; - _errsym= i; + _errsym = i; _setline(); - if( _trpline == 0) - printf("LINE %d: FATAL ERROR: trap %d\n",_erlsym,i); + if (_trpline == 0) + printf("LINE %d: FATAL ERROR: trap %d\n", _erlsym, i); #ifdef DEBUG - printf("trap occurred %d return %d\n",i,_trpline); + printf("trap occurred %d return %d\n", i, _trpline); #endif _trap(); } @@ -37,22 +37,22 @@ void _ini_trp(void) /* initialize trap routines */ int i; - for(i=0;i0) - if( fputc(' ',_chanwr)==EOF) error(29); - fprintf(_chanwr,"%d",i); - if( ferror(_chanwr) ) error(29); + if (i > 0) + if (fputc(' ', _chanwr) == EOF) + error(29); + fprintf(_chanwr, "%d", i); + if (ferror(_chanwr)) + error(29); } void _wrflt(double f) { - fprintf(_chanwr,"%f",f); - if( ferror(_chanwr) ) error(29); + fprintf(_chanwr, "%f", f); + if (ferror(_chanwr)) + error(29); } void _wrstr(String* s) { - fprintf(_chanwr,"\"%s\"",s->strval); - if( ferror(_chanwr) ) error(29); + fprintf(_chanwr, "\"%s\"", s->strval); + if (ferror(_chanwr)) + error(29); } From 0e020132f8a81be70f6ba8841a183caec44d29e5 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 12 Dec 2016 21:17:01 +0100 Subject: [PATCH 3/3] Fix a warning. --- modules/src/idf/idf_pkg.body | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/src/idf/idf_pkg.body b/modules/src/idf/idf_pkg.body index 8f970aef7..5d1260d75 100644 --- a/modules/src/idf/idf_pkg.body +++ b/modules/src/idf/idf_pkg.body @@ -123,7 +123,7 @@ struct idf* str2idf(char tg[], int cpy) int size; IDF_STARTHASH(hash); - while (c = *cp++) + while ((c = *cp++)) { IDF_ENHASH(hash, c); }