home *** CD-ROM | disk | FTP | other *** search
- /* bslib.c -- subroutine library, routines useful anywhere.
- */
-
- #include "bsdefs.h"
-
- FILE *bsin = stdin;
-
- /* blcpy -- copies a block of memory (l bytes) from s to d.
- */
- blcpy(d,s,l)
- char *d,*s;
- int l;
- {
- for(; l >= 0; (l--)) *(d++) = *(s++);
- }
-
- /* Input routines. These routines buffer input a line at a time into
- * ibuf. Unputted input goes to pbbuf, and gets read before things in
- * ibuf, if anything in pbbuf.
- */
-
- char pbbuf[CSTKSIZ],ibuf[BFSIZ];
-
- int iptr = -1;
- int pbptr = -1;
-
- char input()
- {
- if(pbptr > -1)
- return(pbbuf[pbptr--]);
- else {
- if(ibuf[iptr] == '\0') rdlin(bsin);
- if(ibuf[iptr]!='\0' && !feof(bsin))
- return(ibuf[iptr++]);
- else
- return(0);
- }
- }
-
- rdlin(f) FILE *f;
- {
- char c;
-
- iptr = 0;
- for(c=fgetc(f); c!='\n' && c!=EOF; c=fgetc(f)) ibuf[iptr++] = c;
- ibuf[iptr++] = c;
- ibuf[iptr++] = '\0';
- iptr = 0;
- }
-
- unput(c) char c;
- { pbbuf[++pbptr] = c; }
-
- /* myalloc() -- allocate, checking for out of memory.
- */
- char *myalloc(nb)
- int nb;
- {
- char *rval;
- rval = malloc(nb);
- /*
- printf("myalloc:tos:%o,rv:%o,nb:%d,e:%o\n",&rval,rval,nb,sbrk(0));
- */
- if(rval == 0) {
- fprintf(stderr,"myalloc: out of memory\n");
- exit(1);
- }
- return(rval);
- }
-
-
-
- /* Stack routines. Very simple. */
-
- union value stack[STKSIZ];
- int stackp = -1;
-
- push(i) union value i;
- {
- stack[++stackp] = i;
- }
-
- union value pop()
- {
- return(stack[stackp--]);
- }
-
- /* Mark stack. Also very simple. */
- int mstack[5];
- int mstkp = -1;
- mpush()
- { mstack[++mstkp] = stackp; }
- mpop()
- { stackp = mstack[mstkp--]; }
-