date and time created 83/08/05 13:34:37 by sam
[unix-history] / usr / src / old / as.vax / asscan2.c
index eea306b..11fe47e 100644 (file)
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
  *     Copyright (c) 1982 Regents of the University of California
  */
 #ifndef lint
-static char sccsid[] = "@(#)asscan2.c 4.7 %G%";
+static char sccsid[] = "@(#)asscan2.c 4.14 %G%";
 #endif not lint
 
 #include "asscanl.h"
 #endif not lint
 
 #include "asscanl.h"
-static inttoktype      oval = NL;
-
-#define ASINBUFSIZ 4096
-#define        NINBUFFERS      2
-#define        INBUFLG         NINBUFFERS*ASINBUFSIZ + 2
-       /*
-        *      We have NINBUFFERS input buffers; the first one is reserved
-        *      for catching the tail of a line split across a buffer
-        *      boundary; the other ones are used for snarfing a buffer
-        *      worth of assembly language source.
-        */
-static char    inbuffer[INBUFLG];
-static char    *InBufPtr = 0;
-
-/*
- *     fill the inbuffer from the standard input.
- *     Assert: there are always n COMPLETE! lines in the buffer area.
- *     Assert: there is always a \n terminating the last line
- *             in the buffer area.
- *     Assert: after the \n, there is an EOFCHAR (hard end of file)
- *             or a NEEDCHAR (end of buffer)
- *     Assert: fgets always null pads the string it reads.
- *     Assert: no ungetc's are done at the end of a line or at the
- *             beginning of a line.
- *     
- *     We read a complete buffer of characters in one single read.
- *     We then back scan within this buffer to find the end of the
- *     last complete line, and force the assertions, and save a pointer
- *     to the incomplete line.
- *     The next call to fillinbuffer will move the unread characters
- *     to the end of the first buffer, and then read another two buffers,
- *     completing the cycle.
- */
-
-static char    p_swapped = '\0';                       
-static char    *p_start = &inbuffer[NINBUFFERS * ASINBUFSIZ];
-static char    *p_stop = &inbuffer[NINBUFFERS * ASINBUFSIZ];
 
 
-#define        MIDDLE  &inbuffer[ASINBUFSIZ]
-
-char *fillinbuffer()
+static inttoktype      oval = NL;
+#define        ASINBUFSIZ      4096
+char   inbufunget[8];
+char   inbuffer[ASINBUFSIZ];
+char   *Ginbufptr = inbuffer;
+int    Ginbufcnt = 0;
+int    scannerhadeof;
+
+fillinbuffer()
 {
 {
-       register        char    *from;
-                       char    *inbufptr;
-       int             nread;
-       static          int     hadeof;
-       int             goal;
-       int             got;
+               int     nread;
+               int     goal;
+               int     got;
 
 
-       *p_start = p_swapped;
-       inbufptr = MIDDLE - (p_stop - p_start);
-       movestr(inbufptr, p_start, p_stop - p_start);
+       nread = 0;
+       if (scannerhadeof == 0){
+               goal = sizeof(inbuffer);
+               do {
+                       got = read(stdin->_file, inbuffer + nread, goal);
+                       if (got == 0)
+                               scannerhadeof = 1;
+                       if (got <= 0)
+                               break;
+                       nread += got;
+                       goal -= got;
+               } while (goal);
+       } else {
+               scannerhadeof = 0;
+       }
        /*
        /*
-        *      Now, go read up to NINBUFFERS - 1 full buffers
+        *      getchar assumes that Ginbufcnt and Ginbufptr
+        *      are adjusted as if one character has been removed
+        *      from the input.
         */
         */
-       if (hadeof){
-               hadeof = 0;
-               return (0);
+       if (nread == 0){
+               inbuffer[0] = EOFCHAR;
+               nread = 1;
        }
        }
-       goal = (NINBUFFERS - 1)*ASINBUFSIZ;
-       nread = 0;
-       do {
-               got = read(stdin->_file, MIDDLE + nread, goal);
-               if (got == 0)
-                       hadeof = 1;
-               if (got <= 0)
-                       break;
-               nread += got;
-               goal -= got;
-       } while (goal);
-
-       if (nread == 0)
-               return(0);
-       from = MIDDLE + nread;
-       p_stop = from;
-       *from = '\0';
-       while (*--from != '\n'){
-               /*
-                *      back over the partial line
-                */
-               if (from == MIDDLE) {
-                       from = p_stop;
-                       *p_stop++ = '\n';
-                       break;
-               } else {
-                       continue;
-               }
-       }
-
-       from++;                         /* first char of partial line */
-       p_start = from;
-       p_swapped = *p_start;
-       *p_start = NEEDCHAR;            /* force assertion */
-       return(inbufptr);
+       Ginbufcnt = nread - 1;
+       Ginbufptr = inbuffer + 1;
 }
 
 scan_dot_s(bufferbox)
        struct tokbufdesc *bufferbox;
 {
 }
 
 scan_dot_s(bufferbox)
        struct tokbufdesc *bufferbox;
 {
+       reg     char    *inbufptr;
+       reg     int     inbufcnt;
        reg     int     ryylval;        /* local copy of lexical value */
        extern  int     yylval;         /* global copy of lexical value */
        reg     int     val;            /* the value returned */
                int     i;              /* simple counter */
        reg     char    *rcp;   
        reg     int     ryylval;        /* local copy of lexical value */
        extern  int     yylval;         /* global copy of lexical value */
        reg     int     val;            /* the value returned */
                int     i;              /* simple counter */
        reg     char    *rcp;   
-               char    *cp;            /* can have address taken */
-       reg     int     ch;             /* treated as a character */
+               int     ch;             /* treated as a character */
                int     ch1;            /* shadow value */
                int     ch1;            /* shadow value */
-       reg     char    *inbufptr;
                struct  symtab  *op;
                struct  symtab  *op;
-
-       reg     ptrall  bufptr;         /* where to stuff tokens */
                ptrall  lgbackpatch;    /* where to stuff a string length */
                ptrall  lgbackpatch;    /* where to stuff a string length */
+       reg     ptrall  bufptr;         /* where to stuff tokens */
                ptrall  bufub;          /* where not to stuff tokens */
                ptrall  bufub;          /* where not to stuff tokens */
-       reg     int     maxstrlg;       /* how long a string can be */
                long    intval;         /* value of int */
                int     linescrossed;   /* when doing strings and comments */
                struct  Opcode          opstruct;
                long    intval;         /* value of int */
                int     linescrossed;   /* when doing strings and comments */
                struct  Opcode          opstruct;
+       reg     int     strlg;          /* the length of a string */
 
        (bytetoktype *)bufptr = (bytetoktype *) & (bufferbox->toks[0]); 
        (bytetoktype *)bufub = &(bufferbox->toks[AVAILTOKS]);
 
 
        (bytetoktype *)bufptr = (bytetoktype *) & (bufferbox->toks[0]); 
        (bytetoktype *)bufub = &(bufferbox->toks[AVAILTOKS]);
 
-       inbufptr = InBufPtr;
-       if (inbufptr == 0){
-               inbufptr = fillinbuffer();
-               if (inbufptr == 0){     /*end of file*/
-                 endoffile:
-                       inbufptr = 0;
-                       ptoken(bufptr, PARSEEOF);
-                       goto done;
-               }
-       }
-
+       MEMTOREGBUF;
        if (newfflag){
                newfflag = 0;
        if (newfflag){
                newfflag = 0;
-               ryylval = (int)savestr(newfname, strlen(newfname) + 1);
+               ryylval = (int)savestr(newfname, strlen(newfname)+1, STR_BOTH);
 
                ptoken(bufptr, IFILE);
                ptoken(bufptr, STRING);
 
                ptoken(bufptr, IFILE);
                ptoken(bufptr, STRING);
@@ -153,16 +89,12 @@ scan_dot_s(bufferbox)
 
        while (bufptr < bufub){
    loop:
 
        while (bufptr < bufub){
    loop:
-        switch(ryylval = (type+2)[ch = getchar()]) {
+        switch(ryylval = (type+1)[ch = getchar()]) {
        case SCANEOF:
        case SCANEOF:
+       endoffile: ;
                inbufptr = 0;
                inbufptr = 0;
-               goto endoffile;
-
-       case NEEDSBUF:
-               inbufptr = fillinbuffer();
-               if (inbufptr == 0)
-                       goto endoffile;
-               goto loop;
+               ptoken(bufptr, PARSEEOF);
+               goto done;
 
        case DIV:               /*process C style comments*/
                if ( (ch = getchar()) == '*') {  /*comment prelude*/
 
        case DIV:               /*process C style comments*/
                if ( (ch = getchar()) == '*') {  /*comment prelude*/
@@ -183,13 +115,6 @@ scan_dot_s(bufferbox)
                                        break;
                                case EOFCHAR:
                                        goto endoffile;
                                        break;
                                case EOFCHAR:
                                        goto endoffile;
-                               case NEEDCHAR:
-                                       inbufptr = fillinbuffer();
-                                       if (inbufptr == 0)
-                                               goto endoffile;
-                                       lineno++;
-                                       ch = getchar();
-                                       break;
                                default:
                                        ch = getchar();
                                        break;
                                default:
                                        ch = getchar();
                                        break;
@@ -308,7 +233,7 @@ scan_dot_s(bufferbox)
                }
                rcp = yytext;
                do {
                }
                rcp = yytext;
                do {
-                       if (rcp < &yytext[NCPS])
+                       if (rcp < &yytext[NCPName])
                                *rcp++ = ch;
                } while (INCHARSET ( (ch = getchar()), ALPHA | DIGIT));
                *rcp = '\0';
                                *rcp++ = ch;
                } while (INCHARSET ( (ch = getchar()), ALPHA | DIGIT));
                *rcp = '\0';
@@ -320,7 +245,7 @@ scan_dot_s(bufferbox)
                case 0:
                case LABELID:
                        /*
                case 0:
                case LABELID:
                        /*
-                        *      Its a name... (Labels are subsets ofname)
+                        *      Its a name... (Labels are subsets of name)
                         */
                        ryylval = (int)op;
                        val = NAME;
                         */
                        ryylval = (int)op;
                        val = NAME;
@@ -341,17 +266,17 @@ scan_dot_s(bufferbox)
 
        case DIG:
                /*
 
        case DIG:
                /*
-                *      Implement call by reference on a reg variable
+                *      restore local inbufptr and inbufcnt
                 */
                 */
-               cp = inbufptr;
-               val = number(ch, &cp);
+               REGTOMEMBUF;
+               val = number(ch);
+               MEMTOREGBUF;
                /*
                 *      yylval or yybignum has been stuffed as a side
                 *      effect to number(); get the global yylval
                 *      into our fast local copy in case it was an INT.
                 */
                ryylval = yylval;
                /*
                 *      yylval or yybignum has been stuffed as a side
                 *      effect to number(); get the global yylval
                 *      into our fast local copy in case it was an INT.
                 */
                ryylval = yylval;
-               inbufptr = cp;
                goto ret;
 
        case LSH:
                goto ret;
 
        case LSH:
@@ -383,13 +308,13 @@ scan_dot_s(bufferbox)
        case DQ:
           eatstr:
                linescrossed = 0;
        case DQ:
           eatstr:
                linescrossed = 0;
-               for(rcp = yytext, maxstrlg = NCPS; maxstrlg > 0; --maxstrlg){
+               for (strlg = 0; /*VOID*/; strlg++){
                    switch(ch = getchar()){
                    case '"':
                        goto tailDQ;
                    default:
                    stuff:
                    switch(ch = getchar()){
                    case '"':
                        goto tailDQ;
                    default:
                    stuff:
-                       pchar(rcp, ch);
+                       putc(ch, strfile);
                        break;
                    case '\n':
                        yywarning("New line in a string constant");
                        break;
                    case '\n':
                        yywarning("New line in a string constant");
@@ -397,14 +322,8 @@ scan_dot_s(bufferbox)
                        linescrossed++;
                        ch = getchar();
                        switch(ch){
                        linescrossed++;
                        ch = getchar();
                        switch(ch){
-                       case NEEDCHAR:
-                               if ( (inbufptr = fillinbuffer()) != 0){
-                                       ch = '\n';
-                                       goto stuff;
-                               }
-                               /*FALLTHROUGH*/
                        case EOFCHAR:
                        case EOFCHAR:
-                               pchar(rcp, '\n');
+                               putc('\n', strfile);
                                ungetc(EOFCHAR);
                                goto tailDQ;
                        default:
                                ungetc(EOFCHAR);
                                goto tailDQ;
                        default:
@@ -449,20 +368,15 @@ scan_dot_s(bufferbox)
                        pint(bufptr, linescrossed);
                }
                /*
                        pint(bufptr, linescrossed);
                }
                /*
-                *      put the string in yytext into the string pool
-                *
-                *      The value in ryylval points to the string;
-                *      the previous 2 bytes is the length of the string
-                *
                 *      Cheat: append a trailing null to the string
                 *      and then adjust the string length to ignore
                 *      the trailing null.  If any STRING client requires
                 *      the trailing null, the client can just change STRLEN
                 */
                 *      Cheat: append a trailing null to the string
                 *      and then adjust the string length to ignore
                 *      the trailing null.  If any STRING client requires
                 *      the trailing null, the client can just change STRLEN
                 */
+               putc(0, strfile);
+               ryylval = (int)savestr((char *)0, strlg + 1, STR_FILE);
                val = STRING;
                val = STRING;
-               *rcp++ = 0;
-               ryylval = (int)savestr(yytext, rcp - yytext);
-               STRLEN(((char *)ryylval)) -= 1;
+               ((struct strdesc *)ryylval)->sd_strlen -= 1;
                goto ret;
 
        case BADCHAR:
                goto ret;
 
        case BADCHAR:
@@ -526,7 +440,6 @@ scan_dot_s(bufferbox)
    }                   /*end of the while to stuff the buffer*/
    done:
        bufferbox->tok_count = (bytetoktype *)bufptr - &(bufferbox->toks[0]);
    }                   /*end of the while to stuff the buffer*/
    done:
        bufferbox->tok_count = (bytetoktype *)bufptr - &(bufferbox->toks[0]);
-
        /*
         *      This is a real kludge:
         *
        /*
         *      This is a real kludge:
         *
@@ -545,5 +458,5 @@ scan_dot_s(bufferbox)
         *      fail.
         */
        ptoken(bufptr, MINUS);
         *      fail.
         */
        ptoken(bufptr, MINUS);
-       InBufPtr = inbufptr;            /*copy this back*/
+       REGTOMEMBUF;
 }
 }