diff --git a/lang/basic/lib/hlt.c b/lang/basic/lib/hlt.c index 8a87b202d..718504200 100644 --- a/lang/basic/lib/hlt.c +++ b/lang/basic/lib/hlt.c @@ -5,3 +5,8 @@ int nr; { exit(nr); } + +_goto_err() +{ + error(3); +} diff --git a/lang/basic/lib/oct.c b/lang/basic/lib/oct.c index 067a5de3b..1f56339fd 100644 --- a/lang/basic/lib/oct.c +++ b/lang/basic/lib/oct.c @@ -14,6 +14,11 @@ String *_hex(i) int i; { char buffer[30]; + register char *p = buffer; sprintf(buffer,"%x",i); + while (*p) { + if (*p >= 'a' && *p <= 'f') *p += 'A'-'a'; + p++; + } return( (String *)_newstr(buffer)); } diff --git a/lang/basic/lib/random.c b/lang/basic/lib/random.c index 41ea4f358..e5fd1787b 100644 --- a/lang/basic/lib/random.c +++ b/lang/basic/lib/random.c @@ -3,23 +3,25 @@ _randomi() { int i; - double f; _setchan(-1); printf("Random number seed (-32768 to 32767) ? "); _readint(&i); - f=i; - _setrand(f); + _setrand(i); } -_setrand(f) -double f; -{ +_setrand(i) int i; - i=f; +{ srand(i); } double _rnd(d) double d; { double f; f= (int) rand(); - return(f/32767.0); + return(f/ +#if EM_WSIZE == 4 + 2147483647.0 +#else + 32767.0 +#endif + ); } diff --git a/lang/basic/lib/sgn.c b/lang/basic/lib/sgn.c index 814a8d862..46d838ab4 100644 --- a/lang/basic/lib/sgn.c +++ b/lang/basic/lib/sgn.c @@ -7,3 +7,10 @@ double v; if( v<0) return(-1); return(0); } + +_forsgn(v) +double v; +{ + if (v >= 0) return 1; + return -1; +} diff --git a/lang/basic/lib/string.c b/lang/basic/lib/string.c index 5aa9906dc..c037a6ed4 100644 --- a/lang/basic/lib/string.c +++ b/lang/basic/lib/string.c @@ -64,8 +64,9 @@ String *s1,*s2; int length; okr(s1); okr(s2); s= (String *) salloc(sizeof(String)); - length= _len(s1)+_len(s2)+1; - s->strval= salloc(length); + s->strlength= _len(s1)+_len(s2); + s->strval= salloc(s->strlength+1); + s->strcount = 1; strcpy(s->strval,s2->strval); strcat(s->strval,s1->strval); return(s); @@ -116,7 +117,7 @@ int d; String *_strascii() { } -String *_string(d,f) +String *_string(f, d) double d,f; { int i,j; @@ -139,9 +140,10 @@ String *s, *s2; { 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( s->strlengthstrlength < i1+i2) error(3); /* source string too short */ if( i1== -1) i1= s2->strlength; - if( s->strlengthstrlength - i2+1; if( i1>l ) i1=l; strncpy(s->strval+i2-1,s2->strval,i1); @@ -154,6 +156,7 @@ String *s; 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;