Merge pull request #66 from davidgiven/dtrg-warnings

lang/basic/lib: fewer warnings
This commit is contained in:
David Given 2017-11-19 11:39:45 +01:00 committed by GitHub
commit fb90b7b8d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 605 additions and 577 deletions

View file

@ -5,11 +5,11 @@
* See the copyright notice in the ACK home directory, in the file "Copyright". * 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); return (i >= 0 ? i : -i);
} }
double _abr(f) double f; double _abr(double f)
{ {
return( f>=0.0?f: -f); return (f >= 0.0 ? f : -f);
} }

View file

@ -2,10 +2,9 @@
/* $Id$ */ /* $Id$ */
int _asc(str) int _asc(String* str)
String *str;
{ {
if(str==0 || str->strval==0) if (str == 0 || str->strval == 0)
error(3); error(3);
return( *str->strval); return (*str->strval);
} }

View file

@ -1,8 +1,10 @@
/* $Id$ */ #include <stdio.h>
#include <stdlib.h>
asrt(b) void asrt(int b)
{ {
if(!b){ if (!b)
{
printf("ASSERTION ERROR\n"); printf("ASSERTION ERROR\n");
abort(); abort();
} }

View file

@ -10,4 +10,3 @@
#include <math.h> #include <math.h>
double _atn(double x) { return atan(x); } double _atn(double x) { return atan(x); }

View file

@ -2,16 +2,15 @@
/* $Id$ */ /* $Id$ */
String *_chr(i) String* _chr(int i)
int i;
{ {
String *s; String* s;
char buf[2]; char buf[2];
if( i<0 || i>127) if (i < 0 || i > 127)
error(3); error(3);
buf[0]=i; buf[0] = i;
buf[1]=0; buf[1] = 0;
s= _newstr(buf); s = _newstr(buf);
return(s); return (s);
} }

View file

@ -1,40 +1,44 @@
/* $Id$ */ /* $Id$ */
int _cint(f) double f; int _cint(double f)
{ {
int r; int r;
if( f<-32768 || f>32767) error(4); if (f < -32768 || f > 32767)
if(f<0) error(4);
r= f-0.5; if (f < 0)
else r= f+0.5; r = f - 0.5;
return(r); else
r = f + 0.5;
return (r);
} }
double _trunc(f) double _trunc(double f)
double f;
{ {
long d; long d;
d=f; d = f;
f=d; f = d;
return( f ); return (f);
} }
double _fcint(f) double f; double _fcint(double f)
{ {
long r; long r;
if(f<0){ if (f < 0)
r= -f; {
r= -r -1; r = -f;
}else r= f; r = -r - 1;
f=r; }
return(f); else
r = f;
f = r;
return (f);
} }
int _fix(f) int _fix(double f)
double f;
{ {
int r; int r;
if( f<-32768.0 || f>32767.0) error(4); if (f < -32768.0 || f > 32767.0)
r= _sgn(f) * _fcint((f>0.0? f : -f)); error(4);
return(r); r = _sgn(f) * _fcint((f > 0.0 ? f : -f));
return (r);
} }

View file

@ -7,58 +7,58 @@ int _erlsym;
/* error takes an error value in the range of 0-255 */ /* error takes an error value in the range of 0-255 */
/* and generates a trap */ /* and generates a trap */
char *errortable[255]={ char* errortable[255] = {
/* 0 */ "", /* 0 */ "",
/* 1 */ "RETURN without GOSUB", /* 1 */ "RETURN without GOSUB",
/* 2 */ "Out of data", /* 2 */ "Out of data",
/* 3 */ "Illegal function call", /* 3 */ "Illegal function call",
/* 4 */ "Overflow", /* 4 */ "Overflow",
/* 5 */ "Out of memory", /* 5 */ "Out of memory",
/* 6 */ "Undefined line ", /* 6 */ "Undefined line ",
/* 7 */ "Subscript out of range", /* 7 */ "Subscript out of range",
/* 8 */ "Redimensioned array", /* 8 */ "Redimensioned array",
/* 9 */ "Division by zero", /* 9 */ "Division by zero",
/* 10 */ "Illegal indirect", /* 10 */ "Illegal indirect",
/* 11 */ "Type mismatch", /* 11 */ "Type mismatch",
/* 12 */ "Out of string space", /* 12 */ "Out of string space",
/* 13 */ "String too long", /* 13 */ "String too long",
/* 14 */ "String formula too complex", /* 14 */ "String formula too complex",
/* 15 */ "Can't continue", /* 15 */ "Can't continue",
/* 16 */ "Undefined user function", /* 16 */ "Undefined user function",
/* 17 */ "No resume", /* 17 */ "No resume",
/* 18 */ "Resume without error", /* 18 */ "Resume without error",
/* 19 */ "Unprintable error", /* 19 */ "Unprintable error",
/* 20 */ "Missing operand", /* 20 */ "Missing operand",
/* 21 */ "Line buffer overflow", /* 21 */ "Line buffer overflow",
/* 22 */ "FOR without NEXT", /* 22 */ "FOR without NEXT",
/* 23 */ "WHILE without WEND", /* 23 */ "WHILE without WEND",
/* 24 */ "WEND without WHILE", /* 24 */ "WEND without WHILE",
/* 25 */ "Field overflow", /* 25 */ "Field overflow",
/* 26 */ "Internal error", /* 26 */ "Internal error",
/* 27 */ "Bad file number", /* 27 */ "Bad file number",
/* 28 */ "File not found", /* 28 */ "File not found",
/* 29 */ "Bad file mode", /* 29 */ "Bad file mode",
/* 30 */ "File already open", /* 30 */ "File already open",
/* 31 */ "Disk IO error", /* 31 */ "Disk IO error",
/* 32 */ "File already exists", /* 32 */ "File already exists",
/* 33 */ "Disk full", /* 33 */ "Disk full",
/* 34 */ "Input past end", /* 34 */ "Input past end",
/* 35 */ "Bad record number", /* 35 */ "Bad record number",
/* 36 */ "Bad file name", /* 36 */ "Bad file name",
/* 37 */ "Direct statement in file", /* 37 */ "Direct statement in file",
/* 38 */ "Too many files", /* 38 */ "Too many files",
/* 39 */ "File not open", /* 39 */ "File not open",
/* 40 */ "Syntax error in data", /* 40 */ "Syntax error in data",
0 0
}; };
error(index) void error(int index)
int index;
{ {
_setline(); _setline();
if( index<0 || index >40 ) if (index < 0 || index > 40)
printf("LINE %d:ERROR %d: Unprintable error\n",_erlsym,index); printf("LINE %d:ERROR %d: Unprintable error\n", _erlsym, index);
else printf("LINE %d:ERROR %d: %s\n",_erlsym,index,errortable[index]); else
_errsym= index; printf("LINE %d:ERROR %d: %s\n", _erlsym, index, errortable[index]);
_errsym = index;
_trap(); _trap();
} }

View file

@ -4,7 +4,7 @@
/* $Id$ */ /* $Id$ */
Filedesc _fdtable[16]; Filedesc _fdtable[16];
/* BASIC file descriptor table */ /* BASIC file descriptor table */
/* Channel assignment: /* Channel assignment:
-1 terminal IO -1 terminal IO
@ -12,124 +12,122 @@ Filedesc _fdtable[16];
1-15 user files 1-15 user files
*/ */
int _chann = -1;
FILE* _chanrd = stdin;
FILE* _chanwr = stdout;
void _setchan(int index)
int _chann = -1;
FILE *_chanrd = stdin;
FILE *_chanwr = stdout;
_setchan(index)
int index;
{ {
#ifdef DEBUG #ifdef DEBUG
printf("setchannel %d\n",index); printf("setchannel %d\n", index);
#endif #endif
fflush(_chanwr); fflush(_chanwr);
if( index == -1) if (index == -1)
{ {
_chann= -1; _chann = -1;
_chanrd= stdin; _chanrd = stdin;
_chanwr= stdout; _chanwr = stdout;
return; return;
} }
if( index<0 || index>15) if (index < 0 || index > 15)
error(27); error(27);
_chann=index; _chann = index;
_chanrd= _chanwr= _fdtable[index].fd; _chanrd = _chanwr = _fdtable[index].fd;
} }
_asschn() void _asschn(void)
{ {
#ifdef DEBUG #ifdef DEBUG
printf("_asschn %d\n",_chann); printf("_asschn %d\n", _chann);
#endif #endif
if( _chann == -1) return; if (_chann == -1)
return;
#ifdef DEBUG #ifdef DEBUG
printf(" file %d\n", _fdtable[_chann].fd); printf(" file %d\n", _fdtable[_chann].fd);
#endif #endif
if( _chann<0 || _chann>15) if (_chann < 0 || _chann > 15)
error(27); error(27);
if( _fdtable[_chann].fd== 0) if (_fdtable[_chann].fd == 0)
error(39); error(39);
if( feof( _fdtable[_chann].fd)) if (feof(_fdtable[_chann].fd))
error(2); error(2);
} }
_clochn(nr) void _clochn(int nr)
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); fclose(_fdtable[nr].fd);
_fdtable[nr].fd=0; _fdtable[nr].fname=0; _fdtable[nr].fd = 0;
_fdtable[nr].fname = 0;
} }
_opnchn(reclen,fname,mode) void _opnchn(int reclen, String* fname, String* mode)
String *mode,*fname;
int reclen;
{ {
/* channel has been set */ /* channel has been set */
FILE *f; FILE* f;
int m; int m;
#ifdef DEBUG #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 #endif
/* check for opened/closed file */ /* check for opened/closed file */
if(_fdtable[_chann].fd) if (_fdtable[_chann].fd)
error(30); error(30);
switch(*mode->strval) switch (*mode->strval)
{ {
case 'O': case 'O':
case 'o': case 'o':
if( (f=fopen(fname->strval,"w")) == NULL) if ((f = fopen(fname->strval, "w")) == NULL)
error(28); error(28);
m= OMODE; m = OMODE;
break; break;
case 'I': case 'I':
case 'i': case 'i':
if( (f=fopen(fname->strval,"r")) == NULL) if ((f = fopen(fname->strval, "r")) == NULL)
error(28); error(28);
m= IMODE; m = IMODE;
break; break;
case 'r': case 'r':
case 'R': case 'R':
if( (f=fopen(fname->strval,"a")) == NULL) if ((f = fopen(fname->strval, "a")) == NULL)
error(28); error(28);
m= RMODE; m = RMODE;
break; break;
default: default:
printf("file mode %s\n",mode->strval); printf("file mode %s\n", mode->strval);
error(29); error(29);
} }
_chanwr= _chanrd= _fdtable[_chann].fd= f; _chanwr = _chanrd = _fdtable[_chann].fd = f;
_fdtable[_chann].fname= fname->strval; _fdtable[_chann].fname = fname->strval;
_fdtable[_chann].reclength= reclen; _fdtable[_chann].reclength = reclen;
_fdtable[_chann].mode= m; _fdtable[_chann].mode = m;
#ifdef DEBUG #ifdef DEBUG
printf("file descr %d\n",f); printf("file descr %d\n", f);
#endif #endif
} }
_ioeof(channel) int _ioeof(int channel)
int channel;
{ {
FILE *fd; FILE* fd;
char c; char c;
if( channel<0 || channel >15) error(3); if (channel < 0 || channel > 15)
fd= _fdtable[channel].fd;
if( fd==0)
error(3); error(3);
c=fgetc(fd); fd = _fdtable[channel].fd;
if( feof(_fdtable[channel].fd) ) return(-1); if (fd == 0)
ungetc(c,fd); error(3);
return(0); c = fgetc(fd);
if (feof(_fdtable[channel].fd))
return (-1);
ungetc(c, fd);
return (0);
} }
_close() void _close(void)
{ {
/* close all open files */ /* close all open files */
int i; int i;
for(i=1;i<16;i++) for (i = 1; i < 16; i++)
if( _fdtable[i].fd) if (_fdtable[i].fd)
_clochn(i); _clochn(i);
} }

View file

@ -1,12 +1,11 @@
#include <stdlib.h> #include <stdlib.h>
_hlt(nr) void _hlt(int nr)
int nr;
{ {
exit(nr); exit(nr);
} }
_goto_err() void _goto_err(void)
{ {
error(3); error(3);
} }

View file

@ -8,84 +8,102 @@
#define MAXWIDTH 255 #define MAXWIDTH 255
int _width = 75, _pos=0, _zonewidth=15; int _width = 75, _pos = 0, _zonewidth = 15;
_out(str) void _out(char* str)
char *str;
{ {
int pos; int pos;
if( _chann== -1) pos= _pos; if (_chann == -1)
else pos= _fdtable[_chann].pos; pos = _pos;
while( *str) else
pos = _fdtable[_chann].pos;
while (*str)
{ {
if( pos>= _width){ _outnl(); pos=0;} if (pos >= _width)
{
_outnl();
pos = 0;
}
fputc(*str++, _chanwr); fputc(*str++, _chanwr);
pos++; pos++;
} }
if( _chann== -1) _pos=pos; if (_chann == -1)
else _fdtable[_chann].pos= pos; _pos = pos;
else
_fdtable[_chann].pos = pos;
} }
_outnl() void _outnl(void)
{ {
fputc('\n',_chanwr); fputc('\n', _chanwr);
if( _chann == -1) if (_chann == -1)
_pos=0; _pos = 0;
else else
_fdtable[_chann].pos=0; _fdtable[_chann].pos = 0;
} }
_zone() void _zone(void)
{ {
/* go to next zone */ /* go to next zone */
int pos; int pos;
if( _chann == -1) if (_chann == -1)
pos= _pos; pos = _pos;
else pos= _fdtable[_chann].pos; else
do{ pos = _fdtable[_chann].pos;
fputc(' ',_chanwr); do
{
fputc(' ', _chanwr);
pos++; pos++;
if( pos==_width) if (pos == _width)
{ {
_outnl(); _outnl();
pos=0; pos = 0;
break; break;
} }
} while( pos % _zonewidth != 0); } while (pos % _zonewidth != 0);
if( _chann== -1) _pos=pos; if (_chann == -1)
else _fdtable[_chann].pos= pos; _pos = pos;
else
_fdtable[_chann].pos = pos;
} }
_in(buf) void _in(char* buf)
char *buf;
{ {
register int holder ; register int holder;
char *c; char* c;
int pos; int pos;
if( _chann == -1) if (_chann == -1)
{ {
pos= _pos; 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++;
} }
*c= 0; else
if( _chann== -1) pos = _fdtable[_chann].pos;
c = buf;
while ((holder = fgetc(_chanrd)) != EOF && holder != '\n')
{ {
_pos=pos; *c = holder;
} else _fdtable[_chann].pos= pos; if (_chann == -1)
putchar(holder);
c++;
pos++;
}
*c = 0;
if (_chann == -1)
{
_pos = pos;
}
else
_fdtable[_chann].pos = pos;
} }
_tab(x) void _tab(int x)
int x;
{ {
if( x> _width) error(3); if (x > _width)
if( x< _pos) _outnl(); error(3);
_spc(x-_pos); if (x < _pos)
_outnl();
_spc(x - _pos);
} }
_spc(x) void _spc(int x)
int x;
{ {
while(x-->0) _out(" "); while (x-- > 0)
_out(" ");
} }

View file

@ -2,33 +2,29 @@
/* $Id$ */ /* $Id$ */
String *_mki(i) String* _mki(long i)
long i;
{ {
char *buffer =" "; char* buffer = " ";
String *s; String* s;
s= _newstr(buffer); s = _newstr(buffer);
* ( (long *)s->strval ) = i ; *((long*)s->strval) = i;
return(s); return (s);
} }
String *_mkd(d) String* _mkd(double d)
double d;
{ {
char *buffer =" "; char* buffer = " ";
String *s; String* s;
s= _newstr(buffer); s = _newstr(buffer);
* ( (double *)s->strval ) = d ; *((double*)s->strval) = d;
return(s); return (s);
} }
long _cvi(s) long _cvi(String* s)
String *s;
{ {
return *( (long *) s->strval) ; return *((long*)s->strval);
} }
double _cvd(s) double _cvd(String* s)
String *s;
{ {
return *( (double *) s->strval) ; return *((double*)s->strval);
} }

View file

@ -4,28 +4,25 @@
/* $Id$ */ /* $Id$ */
String *_oct(i) String* _oct(int i)
int i;
{ {
char buffer[30]; char buffer[30];
sprintf(buffer,"%o",i); sprintf(buffer, "%o", i);
return( (String *)_newstr(buffer)); return ((String*)_newstr(buffer));
} }
String *_hex(i) String* _hex(int i)
int i;
{ {
char buffer[30]; char buffer[30];
sprintf(buffer,"%x",i); sprintf(buffer, "%x", i);
return( (String *)_newstr(buffer)); return ((String*)_newstr(buffer));
} }
String *_nstr(f) String* _nstr(double f)
double f;
{ {
char buffer[80]; char buffer[80];
_str(f, buffer); _str(f, buffer);
return (String *) _newstr(buffer); return (String*)_newstr(buffer);
} }

View file

@ -1,26 +1,24 @@
/* $Id$ */ /* $Id$ */
int peek(addr) int peek(int addr)
int addr;
{ {
/* this can not work properly for machines in which the /* this can not work properly for machines in which the
POINTERSIZE differs from the integer size POINTERSIZE differs from the integer size
*/ */
char *p; char* p;
int i; int i;
p= (char *)addr; p = (char*)addr;
i= *p; i = *p;
#ifdef DEBUG #ifdef DEBUG
printf("peek %d = %d\n",addr,i); printf("peek %d = %d\n", addr, i);
#endif #endif
return(i); return (i);
} }
_poke(i,j) void _poke(int i, int j)
int i,j;
{ {
char *p; char* p;
p= (char *) i; p = (char*)i;
*p=j; *p = j;
} }

View file

@ -1,4 +1,3 @@
#include <math.h> #include <math.h>
double _power(double x, double y) { return pow(x, y); } double _power(double x, double y) { return pow(x, y); }

View file

@ -7,75 +7,84 @@
/* Here all routine to generate terminal oriented output is located */ /* Here all routine to generate terminal oriented output is located */
_qstmark() void _qstmark(void)
{ {
/* prompt for terminal input */ /* prompt for terminal input */
putchar('?'); putchar('?');
} }
_nl() void _nl(void)
{ {
_asschn(); _asschn();
_outnl(); _outnl();
} }
_prinum(i) void _prinum(int i)
int i;
{ {
char buffer[40]; char buffer[40];
_asschn(); _asschn();
if(i>=0) if (i >= 0)
sprintf(buffer," %d ",i); sprintf(buffer, " %d ", i);
else sprintf(buffer,"-%d ",-i); else
sprintf(buffer, "-%d ", -i);
_out(buffer); _out(buffer);
} }
_str(f,buffer) void _str(double f, char* buffer)
double f;
char *buffer;
{ {
register char *c = buffer; register char* c = buffer;
int eformat = 0; int eformat = 0;
if( f>=0){ if (f >= 0)
if( f> 1.0e8) { {
eformat = 1; if (f > 1.0e8)
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')
{ {
*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;
} }
} }
_prfnum(f) void _prfnum(double f)
double f;
{ {
/* BASIC strings trailing zeroes */ /* BASIC strings trailing zeroes */
char buffer[100]; char buffer[100];
char *c; char* c;
_asschn(); _asschn();
c= buffer; c = buffer;
_str(f,c); _str(f, c);
strcat(buffer," "); strcat(buffer, " ");
_out(buffer); _out(buffer);
} }
_prstr(str) void _prstr(String* str)
String *str;
{ {
_asschn(); _asschn();
if( str==0) _out("<null>"); if (str == 0)
else _out(str->strval); _out("<null>");
else
_out(str->strval);
} }

View file

@ -5,7 +5,7 @@
#define EM_WSIZE _EM_WSIZE #define EM_WSIZE _EM_WSIZE
#endif #endif
_randomi() void _randomi(void)
{ {
int i; int i;
_setchan(-1); _setchan(-1);
@ -14,19 +14,19 @@ _randomi()
_setrand(i); _setrand(i);
} }
_setrand(i) void _setrand(int i)
int i;
{ {
srand(i); srand(i);
} }
double _rnd(d) double d; double _rnd(double d)
{ {
double f; f= (int) rand(); double f;
return(f/ f = (int)rand();
return (f /
#if EM_WSIZE == 4 #if EM_WSIZE == 4
2147483647.0 2147483647.0
#else #else
32767.0 32767.0
#endif #endif
); );
} }

View file

@ -4,115 +4,130 @@
/* $Id$ */ /* $Id$ */
_readln() void _readln(void)
{ {
register int c; register int c;
while( (c=fgetc(_chanrd)) != EOF && c!= '\n') while ((c = fgetc(_chanrd)) != EOF && c != '\n')
; ;
} }
readskip() void readskip(void)
{ {
register int c; register int c;
#ifdef DEBUG #ifdef DEBUG
printf("readskip\n"); printf("readskip\n");
#endif #endif
while( (c=fgetc(_chanrd)) != EOF && c!= ',' && c!= '\n') while ((c = fgetc(_chanrd)) != EOF && c != ',' && c != '\n')
; ;
} }
_readint(addr) void _readint(int* addr)
int *addr;
{ {
int i; int i;
char buf[1024]; char buf[1024];
#ifdef DEBUG #ifdef DEBUG
printf("read int from %d\n",_chann); printf("read int from %d\n", _chann);
#endif #endif
_asschn(); _asschn();
if( fscanf(_chanrd,"%d",&i) != 1) if (fscanf(_chanrd, "%d", &i) != 1)
{ {
if( ferror(_chanrd)) error(29); if (ferror(_chanrd))
if( feof(_chanrd)) error(2); error(29);
if( _chann == -1) if (feof(_chanrd))
error(2);
if (_chann == -1)
{ {
_asschn(); /* may be closed by now */ _asschn(); /* may be closed by now */
fgets(buf,1024,_chanrd); fgets(buf, 1024, _chanrd);
printf("?Redo "); printf("?Redo ");
_readint(addr); _readint(addr);
return; return;
} }
error(40); error(40);
}else { readskip(); *addr=i;} }
else
{
readskip();
*addr = i;
}
} }
_readflt(addr) void _readflt(double* addr)
double *addr;
{ {
double f; double f;
char buf[1024]; char buf[1024];
#ifdef DEBUG #ifdef DEBUG
printf("read flt from %d\n",_chann); printf("read flt from %d\n", _chann);
#endif #endif
_asschn(); _asschn();
if( fscanf(_chanrd,"%lf",&f) != 1) if (fscanf(_chanrd, "%lf", &f) != 1)
{ {
if( ferror(_chanrd)) error(29); if (ferror(_chanrd))
if( feof(_chanrd)) error(2); error(29);
if( _chann == -1) if (feof(_chanrd))
error(2);
if (_chann == -1)
{ {
fgets(buf,1024,_chanrd); fgets(buf, 1024, _chanrd);
printf("?Redo "); printf("?Redo ");
_readflt(addr); _readflt(addr);
return; return;
} }
error(40); error(40);
}else { readskip(); *addr=f;} }
else
{
readskip();
*addr = f;
}
} }
_readstr(s) void _readstr(String** s)
String **s;
{ {
char buffer[1024]; char buffer[1024];
register int kar ; register int kar;
char *c; char* c;
#ifdef DEBUG #ifdef DEBUG
printf("read str from %d\n",_chann); printf("read str from %d\n", _chann);
#endif #endif
_asschn(); _asschn();
c= buffer; c = buffer;
kar= fgetc(_chanrd); kar = fgetc(_chanrd);
while(isspace(kar) && kar!= EOF) while (isspace(kar) && kar != EOF)
kar= fgetc(_chanrd); kar = fgetc(_chanrd);
*c=kar ; *c = kar;
if( kar== '"') if (kar == '"')
{ {
/* read quoted string */ /* read quoted string */
#ifdef DEBUG #ifdef DEBUG
printf("qouted string\n"); printf("qouted string\n");
#endif #endif
while ( (kar= fgetc(_chanrd)) != EOF && kar!='"' ) *c++ = kar ; while ((kar = fgetc(_chanrd)) != EOF && kar != '"')
ungetc(kar,_chanrd); *c++ = kar;
*c=0; ungetc(kar, _chanrd);
}else *c = 0;
if( isalpha(*c)) }
else if (isalpha(*c))
{ {
/* read normal string */ /* read normal string */
c++; c++;
#ifdef DEBUG #ifdef DEBUG
printf("non-qouted string\n"); printf("non-qouted string\n");
#endif #endif
while( (kar= fgetc(_chanrd)) != ',' && kar!= EOF && while ((kar = fgetc(_chanrd)) != ',' && kar != EOF && !isspace(kar) && kar != '\n')
!isspace(kar) && kar!='\n') *c++ = kar;
*c++= kar ; ungetc(kar, _chanrd);
ungetc(kar,_chanrd); *c = 0;
*c=0; }
}else{ else
if( ferror(_chanrd)) error(29); {
if( feof(_chanrd)) error(2); if (ferror(_chanrd))
if( _chann == -1) error(29);
if (feof(_chanrd))
error(2);
if (_chann == -1)
{ {
fgets(buffer,1024,_chanrd); fgets(buffer, 1024, _chanrd);
printf("?Redo "); printf("?Redo ");
_rdline(s); _rdline(s);
return; return;
@ -120,48 +135,47 @@ String **s;
error(40); error(40);
} }
#ifdef DEBUG #ifdef DEBUG
printf("string read: %s\n",buffer); printf("string read: %s\n", buffer);
#endif #endif
readskip(); readskip();
/* save value read */ /* save value read */
_decstr(*s); _decstr(*s);
*s= (String *) _newstr(buffer); *s = (String*)_newstr(buffer);
} }
extern int _seektab[]; extern int _seektab[];
_restore(line) void _restore(int line)
int line;
{ {
int nr; int nr;
char buffer[1024]; char buffer[1024];
#ifdef DEBUG #ifdef DEBUG
printf("seek to %d",line); printf("seek to %d", line);
#endif #endif
fseek(_chanrd,0l,0); fseek(_chanrd, 0l, 0);
if( line) if (line)
{ {
/* search number of lines to skip */ /* 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 #ifdef DEBUG
printf("test %d %d\n",_seektab[nr], _seektab[nr+1]); printf("test %d %d\n", _seektab[nr], _seektab[nr + 1]);
#endif #endif
; ;
nr /= 2; nr /= 2;
#ifdef DEBUG #ifdef DEBUG
printf(" %d lines to skip\n",nr); printf(" %d lines to skip\n", nr);
#endif #endif
while(nr-- >0 ) fgets(buffer,1024,_chanrd); while (nr-- > 0)
fgets(buffer, 1024, _chanrd);
} }
} }
_rdline(s) void _rdline(String** s)
String **s;
{ {
char buffer[1024]; char buffer[1024];
if( fgets(buffer,1024,_chanrd) == 0) if (fgets(buffer, 1024, _chanrd) == 0)
{ {
if( _chann == -1) if (_chann == -1)
{ {
printf("?Redo "); printf("?Redo ");
_rdline(s); _rdline(s);
@ -170,5 +184,5 @@ String **s;
error(40); error(40);
} }
_decstr(*s); _decstr(*s);
*s= (String *) _newstr(buffer); *s = (String*)_newstr(buffer);
} }

View file

@ -1,29 +1,29 @@
/* $Id$ */ /* $Id$ */
#define MAXNESTING 1000 #define MAXNESTING 1000
int _gotable[MAXNESTING]; int _gotable[MAXNESTING];
int topstk=0; int topstk = 0;
_gosub(x) void _gosub(int x)
int x;
{ {
/* administer gosub */ /* administer gosub */
#ifdef DEBUG #ifdef DEBUG
printf("store %d in %d\n",x,topstk); printf("store %d in %d\n", x, topstk);
#endif #endif
if( topstk== MAXNESTING) error(26); if (topstk == MAXNESTING)
_gotable[topstk]= x; error(26);
_gotable[topstk] = x;
topstk++; topstk++;
} }
_retstmt() 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 */ of the stack */
#ifdef DEBUG #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 #endif
if( topstk==0 || topstk==MAXNESTING) if (topstk == 0 || topstk == MAXNESTING)
error(1); error(1);
return( _gotable[--topstk]); return (_gotable[--topstk]);
} }

View file

@ -1,18 +1,19 @@
#include <stdlib.h> #include <stdlib.h>
char * salloc(length) char* salloc(unsigned length)
unsigned length;
{ {
char *c, *s; char* c, *s;
c= malloc(length); c = malloc(length);
if( !c ) error(5); if (!c)
for(s=c;s<c+length;s++) *s = 0; error(5);
return(c); for (s = c; s < c + length; s++)
*s = 0;
return (c);
} }
sfree(c) void sfree(char* c)
char *c;
{ {
if( !c ) return; if (!c)
return;
free(c); free(c);
} }

View file

@ -1,16 +1,17 @@
/* $Id$ */ /* $Id$ */
_sgn(v) int _sgn(double v)
double v;
{ {
if( v>0) return(1); if (v > 0)
if( v<0) return(-1); return (1);
return(0); if (v < 0)
return (-1);
return (0);
} }
_forsgn(v) int _forsgn(double v)
double v;
{ {
if (v >= 0) return 1; if (v >= 0)
return 1;
return -1; return -1;
} }

View file

@ -13,4 +13,3 @@
double _sin(double x) { return sin(x); } double _sin(double x) { return sin(x); }
double _cos(double x) { return cos(x); } double _cos(double x) { return cos(x); }
double _tan(double x) { return tan(x); } double _tan(double x) { return tan(x); }

View file

@ -11,4 +11,3 @@
#include <math.h> #include <math.h>
double _sqt(double x) { return sqrt(x); } double _sqt(double x) { return sqrt(x); }

View file

@ -4,47 +4,48 @@
/* $Id$ */ /* $Id$ */
#define ok(X) if( X ==0) return; #define ok(X) \
#define okr(X) if( X ==0) return(0); if (X == 0) \
return;
#define okr(X) \
if (X == 0) \
return (0);
extern char *salloc() ; extern char* salloc();
_length(str) int _length(String* str)
String *str;
{ {
okr(str); okr(str);
return(str->strlength); return (str->strlength);
} }
String *_newstr(str) String* _newstr(char* str)
char *str;
{ {
String *s; String* s;
okr(str); okr(str);
s= (String *) salloc(sizeof(String)); s = (String*)salloc(sizeof(String));
s->strcount=1; s->strcount = 1;
s->strlength= strlen(str); s->strlength = strlen(str);
s->strval= salloc(s->strlength+1); s->strval = salloc(s->strlength + 1);
strcpy(s->strval,str); strcpy(s->strval, str);
return(s); return (s);
} }
_incstr(src) void _incstr(String* src)
String *src;
{ {
/* one more variable uses the string */ /* one more variable uses the string */
ok(src); ok(src);
src->strcount++; src->strcount++;
} }
_decstr(str) void _decstr(String* str)
String *str;
{ {
ok(str); ok(str);
/* Strings in ROM are initialized with this count */ /* Strings in ROM are initialized with this count */
if ( str->strcount==9999 ) return ; if (str->strcount == 9999)
return;
str->strcount--; str->strcount--;
if(str->strcount<=0) _delstr(str); if (str->strcount <= 0)
_delstr(str);
} }
_strcpy(dst,src) void _strcpy(String* dst, String* src)
String *src,*dst;
{ {
ok(src); ok(src);
ok(dst); ok(dst);
@ -52,133 +53,134 @@ String *src,*dst;
*dst = *src; *dst = *src;
_incstr(src); _incstr(src);
} }
_delstr(src) void _delstr(String* src)
String *src;
{ {
ok(src); ok(src);
sfree(src->strval); sfree(src->strval);
sfree((char *)src); sfree((char*)src);
} }
String *_concat(s1,s2) String* _concat(String* s1, String* s2)
String *s1,*s2;
{ {
String *s; String* s;
int length; int length;
okr(s1); okr(s2); okr(s1);
s= (String *) salloc(sizeof(String)); okr(s2);
s->strlength= _length(s1)+_length(s2); s = (String*)salloc(sizeof(String));
s->strval= salloc(s->strlength+1); s->strlength = _length(s1) + _length(s2);
s->strval = salloc(s->strlength + 1);
s->strcount = 1; s->strcount = 1;
strcpy(s->strval,s2->strval); strcpy(s->strval, s2->strval);
strcat(s->strval,s1->strval); strcat(s->strval, s1->strval);
return(s); return (s);
} }
_strcomp(s1,s2) int _strcomp(String* s1, String* s2)
String *s1,*s2;
{ {
okr(s1);okr(s2); okr(s1);
return(strcmp(s2->strval,s1->strval)); okr(s2);
return (strcmp(s2->strval, s1->strval));
} }
String *_left(size,s) String* _left(int size, String* s)
String *s;
int size;
{ {
String *ns; String* ns;
int i; int i;
okr(s); okr(s);
if( size <0 || size >s->strlength) error(3); if (size < 0 || size > s->strlength)
ns= (String *) salloc(sizeof(String)); error(3);
ns->strval= salloc(size+1); ns = (String*)salloc(sizeof(String));
ns->strcount=1; ns->strval = salloc(size + 1);
for(i=0; i<size && s->strval[i];i++) ns->strcount = 1;
ns->strval[i]= s->strval[i]; for (i = 0; i < size && s->strval[i]; i++)
ns->strval[i]=0; ns->strval[i] = s->strval[i];
ns->strlength= i; ns->strval[i] = 0;
return(ns); ns->strlength = i;
return (ns);
} }
String *_space(d) String* _space(int d)
int d;
{ {
String *s; String* s;
int i,len; int i, len;
len= d; len = d;
s= (String *) salloc(sizeof(String)); s = (String*)salloc(sizeof(String));
s->strlength= len; s->strlength = len;
s->strcount=1; s->strcount = 1;
s->strval= salloc(len+1); s->strval = salloc(len + 1);
for(i=0;i<len;i++) for (i = 0; i < len; i++)
s->strval[i]= ' '; s->strval[i] = ' ';
s->strval[i]=0; s->strval[i] = 0;
return(s); return (s);
} }
String *_strascii() String* _strascii(void)
{ {
} }
String *_string(f, d) String* _string(double f, double d)
double d,f;
{ {
int i,j; int i, j;
String *s; String* s;
i=d;j=f; i = d;
if( i<0 || i>MAXSTRING) error(3); j = f;
s= (String *) salloc(sizeof(String)); if (i < 0 || i > MAXSTRING)
s->strlength= i; error(3);
s->strcount=1; s = (String*)salloc(sizeof(String));
s->strval= salloc(i+1); s->strlength = i;
s->strval[i--]=0; s->strcount = 1;
for(; i>=0;i--) s->strval = salloc(i + 1);
s->strval[i]= j; s->strval[i--] = 0;
return(s); for (; i >= 0; i--)
s->strval[i] = j;
return (s);
} }
_midstmt(s2,i1,i2,s) void _midstmt(String* s2, int i1, int i2, String* s)
int i1,i2;
String *s, *s2;
{ {
int l; int l;
/*printf("mid called %d %d %s %s\n",i1,i2,s->strval, s2->strval);*/ /*printf("mid called %d %d %s %s\n",i1,i2,s->strval, s2->strval);*/
if (i2 < 0 || i1 < -1) error(3); if (i2 < 0 || i1 < -1)
if( s->strlength<i2 || s2->strlength < i1) error(3); /* source string too short */ error(3);
if( i1== -1) i1= s2->strlength; if (s->strlength < i2 || s2->strlength < i1)
l= s->strlength - i2+1; error(3); /* source string too short */
if( i1>l ) i1=l; if (i1 == -1)
strncpy(s->strval+i2-1,s2->strval,i1); i1 = s2->strlength;
l = s->strlength - i2 + 1;
if (i1 > l)
i1 = l;
strncpy(s->strval + i2 - 1, s2->strval, i1);
} }
String *_mid(i1,i2,s) String* _mid(int i1, int i2, String* s)
int i1,i2;
String *s;
{ {
int l; int l;
String *s2; String* s2;
/* printf("mid fcn called %d %d %s\n",i1,i2,s->strval);*/ /* printf("mid fcn called %d %d %s\n",i1,i2,s->strval);*/
if (i2 < 0 || i1 < -1) return(s2); /* or error? */ if (i2 < 0 || i1 < -1)
if( i1 == -1) i1= s->strlength; return (s2); /* or error? */
s2= _newstr(s->strval); if (i1 == -1)
s2->strval[0]=0; i1 = s->strlength;
if( s->strlength<i2) return(s2); /* source string too short */ s2 = _newstr(s->strval);
l= s->strlength - i2+1; s2->strval[0] = 0;
if( i1>l ) i1=l; if (s->strlength < i2)
strncpy(s2->strval,s->strval+i2-1,i1); return (s2); /* source string too short */
s2->strval[i1]=0; l = s->strlength - i2 + 1;
return(s2); if (i1 > l)
i1 = l;
strncpy(s2->strval, s->strval + i2 - 1, i1);
s2->strval[i1] = 0;
return (s2);
} }
String *_right(length,str) String* _right(int length, String* str)
String *str;
int length;
{ {
String *s; String* s;
int i; int i;
i= _length(str)-length; i = _length(str) - length;
if(i<0) i=0; if (i < 0)
s= _newstr(str->strval+i); i = 0;
return(s); s = _newstr(str->strval + i);
return (s);
} }

View file

@ -2,29 +2,26 @@
/* $Id$ */ /* $Id$ */
_intswap(i1,i2) void _intswap(int* i1, int* i2)
int *i1,*i2;
{ {
int i3; int i3;
i3= *i1; i3 = *i1;
*i1= *i2; *i1 = *i2;
*i2=i3; *i2 = i3;
} }
_fltswap(i1,i2) void _fltswap(double* i1, double* i2)
double *i1,*i2;
{ {
double i3; double i3;
i3= *i1; i3 = *i1;
*i1= *i2; *i1 = *i2;
*i2=i3; *i2 = i3;
} }
_strswap(s1,s2) void _strswap(String** s1, String** s2)
String **s1,**s2;
{ {
String *s; String* s;
s= *s1; s = *s1;
*s1= *s2; *s1 = *s2;
*s2 = s; *s2 = s;
} }

View file

@ -1,7 +1,6 @@
/* $Id$ */ /* $Id$ */
_trace(i) void _trace(int i)
int i; {
{ printf("[%d]", i);
printf("[%d]",i);
} }

View file

@ -10,53 +10,49 @@
/* $Id$ */ /* $Id$ */
/* Trap handling */ /* Trap handling */
int _trpline; /* BASIC return label */ int _trpline; /* BASIC return label */
jmp_buf trpbuf; jmp_buf trpbuf;
_trpset(nr) void _trpset(int nr)
int nr;
{ {
/*debug printf("trap set to %d\n",nr);*/ /*debug printf("trap set to %d\n",nr);*/
_trpline=nr; _trpline = nr;
} }
void void _trpfatal(int i)
_trpfatal(i)
int i;
{ {
extern int _errsym,_erlsym; extern int _errsym, _erlsym;
_errsym= i; _errsym = i;
_setline(); _setline();
if( _trpline == 0) if (_trpline == 0)
printf("LINE %d: FATAL ERROR: trap %d\n",_erlsym,i); printf("LINE %d: FATAL ERROR: trap %d\n", _erlsym, i);
#ifdef DEBUG #ifdef DEBUG
printf("trap occurred %d return %d\n",i,_trpline); printf("trap occurred %d return %d\n", i, _trpline);
#endif #endif
_trap(); _trap();
} }
_ini_trp() void _ini_trp(void)
{ {
/* initialize trap routines */ /* initialize trap routines */
int i; int i;
for(i=0;i<NSIG;i++) for (i = 0; i < NSIG; i++)
signal(i,_trpfatal); signal(i, _trpfatal);
} }
void _settrap(int nr)
_settrap(nr)
int nr;
{ {
_trpline=nr; _trpline = nr;
} }
_trap() void _trap(void)
{ {
int line; int line;
if( _trpline==0) exit(-1); if (_trpline == 0)
line=_trpline; exit(-1);
_trpline=0; /* should be reset by user */ line = _trpline;
_trpline = 0; /* should be reset by user */
_ini_trp(); _ini_trp();
longjmp(trpbuf,line); longjmp(trpbuf, line);
} }

View file

@ -5,31 +5,34 @@
/* assume that the channel has been set */ /* assume that the channel has been set */
_wrnl() void _wrnl(void)
{ {
if( fputc('\n',_chanwr) == EOF) error(29); if (fputc('\n', _chanwr) == EOF)
error(29);
} }
_wrcomma() void _wrcomma(void)
{ {
if( fputc(',',_chanwr) == EOF) error(29); if (fputc(',', _chanwr) == EOF)
error(29);
} }
_wrint(i) void _wrint(int i)
int i;
{ {
if(i>0) if (i > 0)
if( fputc(' ',_chanwr)==EOF) error(29); if (fputc(' ', _chanwr) == EOF)
fprintf(_chanwr,"%d",i); error(29);
if( ferror(_chanwr) ) error(29); fprintf(_chanwr, "%d", i);
if (ferror(_chanwr))
error(29);
} }
_wrflt(f) void _wrflt(double f)
double f;
{ {
fprintf(_chanwr,"%f",f); fprintf(_chanwr, "%f", f);
if( ferror(_chanwr) ) error(29); if (ferror(_chanwr))
error(29);
} }
_wrstr(s) void _wrstr(String* s)
String *s;
{ {
fprintf(_chanwr,"\"%s\"",s->strval); fprintf(_chanwr, "\"%s\"", s->strval);
if( ferror(_chanwr) ) error(29); if (ferror(_chanwr))
error(29);
} }

View file

@ -123,7 +123,7 @@ struct idf* str2idf(char tg[], int cpy)
int size; int size;
IDF_STARTHASH(hash); IDF_STARTHASH(hash);
while (c = *cp++) while ((c = *cp++))
{ {
IDF_ENHASH(hash, c); IDF_ENHASH(hash, c);
} }