support for long strings
authorceriel <none@none>
Wed, 1 Aug 1990 14:30:45 +0000 (14:30 +0000)
committerceriel <none@none>
Wed, 1 Aug 1990 14:30:45 +0000 (14:30 +0000)
mach/proto/as/comm1.h
mach/proto/as/comm2.y
mach/proto/as/comm5.c
mach/proto/as/comm7.c
modules/src/read_em/read_em.c
modules/src/read_em/reade.c
modules/src/read_em/readk.c

index 9eaea90..065ac98 100644 (file)
@@ -58,8 +58,8 @@ extern char   temppath[50];
 extern FILE    *input;
 extern FILE    *tempfile;
 
-extern char    stringbuf[STRINGMAX];
-                               /* contains last string value */
+extern char    *stringbuf;     /* contains last string value */
+extern int     stringlen;      /* contains length of last string value */
 
 extern sect_t  sect[SECTMAX];
 
@@ -116,6 +116,7 @@ extern FILE *fftemp();
 extern long    atol();
 extern char    *mktemp();
 extern char    *malloc();
+extern char    *realloc();
 extern char    *calloc();
 extern char    *getenv();
 extern char    *strncpy();
index 2257298..6273617 100644 (file)
@@ -128,7 +128,7 @@ program     :       /* empty */
                        {       lineno++; LISTLINE(1); RELODONE;}
        |       program '#' NUMBER STRING '\n'
                        {       lineno = $3;
-                               if (modulename) strncpy(modulename, &stringbuf[1], STRINGMAX-1);
+                               if (modulename) strncpy(modulename, stringbuf, STRINGMAX-1);
                                LISTLINE(1); RELODONE;
                        }
        |       program error '\n'
@@ -196,7 +196,7 @@ operation
 #endif
                                            
                                        newsymb(
-                                               *(stringbuf+1) ? stringbuf+1 : (char *) 0,
+                                               *stringbuf ? stringbuf : (char *) 0,
                                                (short)(
                                                        ($4.typ & (S_EXT|S_TYP))
                                                        |
@@ -210,7 +210,7 @@ operation
        |       SYMD STRING ','  absexp ',' absexp
                        {       if ((sflag & SYM_SMB) && PASS_SYMB) {
                                        newsymb(
-                                               *(stringbuf+1) ? stringbuf+1 : (char *) 0,
+                                               *stringbuf ? stringbuf : (char *) 0,
                                                (short)(
                                                        (DOTTYP & (S_EXT|S_TYP))
                                                        |
@@ -239,7 +239,7 @@ operation
                        {       if ((sflag & SYM_LIN) && PASS_SYMB) {
                                        hllino = 0;
                                        newsymb(
-                                               stringbuf+1,
+                                               stringbuf,
                                                (short)(DOTTYP | S_FIL),
                                                (short)0,
                                                (valu_t)DOTVAL
@@ -295,9 +295,9 @@ expr        :       error
                                $$.typ = $1->i_type & ~S_EXT;
                        }
        |       STRING
-                       {       if (stringbuf[0] != 1)
+                       {       if (stringlen != 1)
                                        serror("too many chars");
-                               $$.val = stringbuf[1];
+                               $$.val = stringbuf[0];
                                $$.typ = S_ABS;
                        }
        |       ASC_LPAR expr ASC_RPAR
index 3fa991a..bcaf81a 100644 (file)
@@ -105,8 +105,23 @@ putval(c)
                p = (char *) &yylval.y_strp; break;
 #endif
        case STRING:
+               v = stringlen;
+               putc(c-128, tempfile);
+               for (n = 0; n < sizeof(v); n++) {
+                       if (v == 0)
+                               break;
+                       v >>= 8;
+               }
+               c = NUMBER0 + n;
+               putc(c-128, tempfile);
+               v = stringlen;
+               while (--n >= 0)
+                       putc((int) (v >> (n*8)), tempfile);
                p = stringbuf;
-               n = (*p & 0377) + 1; break;
+               n = stringlen;
+               while (--n >= 0)
+                       putc(*p++, tempfile);
+               return;
        case OP_EQ:
        case OP_NE:
        case OP_LE:
@@ -166,8 +181,10 @@ getval(c)
                p = (char *) &yylval.y_strp; break;
 #endif
        case STRING:
+               getval(getc(tempfile)+128);
+               stringlen = n = yylval.y_valu;
                p = stringbuf;
-               *p++ = n = getc(tempfile); p[n] = '\0'; break;
+               p[n] = '\0'; break;
        case OP_EQ:
        case OP_NE:
        case OP_LE:
@@ -346,8 +363,15 @@ instring(termc)
 {
        register char *p;
        register c;
+       static int maxstring = 0;
 
-       p = stringbuf+1;
+       if (! maxstring) {
+               maxstring = STRINGMAX;
+               if ((stringbuf = malloc(maxstring)) == 0) {
+                       fatal("out of memory");
+               }
+       }
+       p = stringbuf;
        for (;;) {
                c = nextchar();
                if (c == '\n' || c == '\0') {
@@ -359,11 +383,17 @@ instring(termc)
                        break;
                if (c == '\\')
                        c = inescape();
-               if (p >= &stringbuf[STRINGMAX - 1])
-                       fatal("string buffer overflow");
+               if (p >= &stringbuf[maxstring - 1]) {
+                       int cnt = p - stringbuf;
+
+                       if ((stringbuf = realloc(stringbuf, maxstring += 256)) == 0) {
+                               fatal("out of memory");
+                       }
+                       p = stringbuf + cnt;
+               }
                *p++ = c;
        }
-       stringbuf[0] = p - stringbuf - 1;
+       stringlen = p - stringbuf;
        *p = '\0';
        return(STRING);
 }
index da2ef29..3b347fb 100644 (file)
@@ -306,7 +306,7 @@ emitstr(zero)
        register char *p;
 
        p = stringbuf;
-       i = *p++ & 0377;
+       i = stringlen;
        while (--i >= 0)
                emit1(*p++);
        if (zero)
index f652459..f00cd29 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include <assert.h>
+#include <alloc.h>
 #include <system.h>
 #include <em_label.h>
 #include <em_arith.h>
@@ -60,29 +61,21 @@ _fill()
        }
 }
 
-#define STRSIZ 256             /* Maximum length of strings */
-
 static struct e_instr *emhead; /* Where we put the head */
 static struct e_instr aheads[3];
 static int ahead;
 
 static struct string {
        int length;
-       char str[STRSIZ + 1];
+       unsigned int maxlen;
+       char *str;
 } string;
 
-#ifdef COMPACT
-static arith strleft;          /* count # of chars left to read
-                                  in a string
-                               */
-#endif
-
 static int state;              /* What state are we in? */
 #define CON    01              /* Reading a CON */
 #define ROM    02              /* Reading a ROM */
 #define MES    03              /* Reading a MES */
 #define PSEUMASK 03
-#define INSTRING 010           /* Reading a string */
 
 static int EM_initialized;     /* EM_open called? */
 
@@ -399,35 +392,6 @@ EM_getinstr(p)
                return EM_error == 0;
        }
 
-       if (state & INSTRING) { /* We already delivered part of a string.
-                                  Deliver the next part
-                               */
-               register struct string *s;
-               
-               s = getstring(0);
-               p->em_argtype = str_ptyp;
-               p->em_string = s->str;
-               p->em_size = s->length;
-               switch(state & PSEUMASK) {
-               default:
-                       assert(0);
-               case MES:
-                       if (!EM_error)
-                               EM_error = "String too long in message";
-                       p->em_type = EM_MESARG;
-                       break;
-               case CON:
-                       p->em_type = EM_PSEU;
-                       p->em_opcode = ps_con;
-                       break;
-               case ROM:
-                       p->em_type = EM_PSEU;
-                       p->em_opcode = ps_rom;
-                       break;
-               }
-               return EM_error == 0;
-       }
-
        /* Here, we are in a state reading arguments */
        getarg(any_ptyp, &(p->em_arg));
        if (EM_error && p->em_type != EM_FATAL) {
index 300fdfd..46a278e 100644 (file)
@@ -3,7 +3,7 @@
  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  * See the copyright notice in the ACK home directory, in the file "Copyright".
  */
-/*     This file is ment to be included in the file read_emeV.c.
+/*     This file is ment to be included in the file read_em.c.
        It contains the part that takes care of the reading of human readable
        EM-code.
 */
@@ -171,6 +171,10 @@ getname()
 
        s = &string;
        p = s->str;
+       if (!p) {
+               s->maxlen = 256;
+               s->str = p = Malloc(256);
+       }
        c = getbyte();
 
        if (!(isalpha(c) || c == '_')) {
@@ -180,7 +184,12 @@ getname()
        }
 
        while (isalnum(c) || c == '_') {
-               if (p < &(s->str[STRSIZ])) *p++ = c;
+               if (p >= &(s->str[s->maxlen])) {
+                       int df = p - s->str;
+                       s->str = Realloc(s->str, (s->maxlen += 256));
+                       p = s->str + df;
+               }
+               *p++ = c;
                c = getbyte();
        }
 
@@ -202,16 +211,18 @@ getstring()
 
        s = &string;
        p = s->str;
-
-       if (!(state & INSTRING)) {      /* Not reading a string yet */
-               termc = getbyte();
-               /* assert(termc == '"' || termc == '\''); */
-               /* This assertion does not work. Compiler error messages.
-                  The trouble lies in the ", it terminates the string
-                  created in the assertion macro
-               */
+       if (!p) {
+               s->maxlen = 256;
+               s->str = p = Malloc(256);
        }
 
+       termc = getbyte();
+       /* assert(termc == '"' || termc == '\''); */
+       /* This assertion does not work. Compiler error messages.
+          The trouble lies in the ", it terminates the string
+          created in the assertion macro
+       */
+
        for (;;) {
                if ((c = getbyte()) == '\n' || c == EOF) {
                        ungetbyte(c);
@@ -221,16 +232,15 @@ getstring()
 
                if (c == termc) {
                        if (termc == '"') *p++ = '\0';
-                       state &= ~INSTRING;
                        break;
                }
 
                if (c == '\\') c = getescape();
 
-               if (p >= &(s->str[STRSIZ])) {
-                       state |= INSTRING;
-                       ungetbyte(c);
-                       break;
+               if (p >= &(s->str[s->maxlen])) {
+                       int df = p - s->str;
+                       s->str = Realloc(s->str, (s->maxlen += 256));
+                       p = s->str + df;
                }
 
                *p++ = c;       
@@ -268,7 +278,7 @@ getnumber(c, ap)
        register int c;
        register struct e_arg *ap;
 {
-       char str[STRSIZ + 1];
+       char str[256 + 1];
        register char *p = str;
        int n;
        int expsign;
@@ -291,7 +301,7 @@ getnumber(c, ap)
        n = sp_cst4;
 
        for (;;) {
-               if (p >= &(str[STRSIZ])) {
+               if (p >= &(str[256])) {
                        syntax("number too long");
                        return sp_cst4;
                }
@@ -580,7 +590,7 @@ getmnem(c, p)
 PRIVATE
 line_line()
 {
-       static char filebuf[STRSIZ + 1];
+       static char filebuf[256 + 1];
        char *btscpy();
        struct e_arg dummy;
 
index ab82b79..f3bcaef 100644 (file)
@@ -109,11 +109,6 @@ getarg(typset, ap)
                register struct string *p;
 
                p = getstring(1);
-#ifdef CHECKING
-               if (state & INSTRING) {
-                       xerror("Procedure name too long");
-               }
-#endif CHECKING
                ap->ema_pnam = p->str;
                ap->ema_argtype = pro_ptyp;
                break;
@@ -124,11 +119,6 @@ getarg(typset, ap)
                register struct string *p;
 
                p = getstring(1);
-#ifdef CHECKING
-               if (state & INSTRING) {
-                       xerror("Data label too long");
-               }
-#endif CHECKING
                ap->ema_dnam = p->str;
                ap->ema_szoroff = 0;
                ap->ema_argtype = sof_ptyp;
@@ -154,11 +144,6 @@ getarg(typset, ap)
                getarg(cst_ptyp, ap);
                ap->ema_szoroff = ap->ema_cst;
                p = getstring(0);
-#ifdef CHECKING
-               if (state & INSTRING) {
-                       xerror("Numeric constant too long");
-               }
-#endif CHECKING
                ap->ema_argtype = ptyp(i);
                ap->ema_string = p->str;
                break;
@@ -226,8 +211,7 @@ checkident(s)
 }
 #endif CHECKING
 
-/* getstring: read a string from the input, but at most STRSIZ characters
-       of it. The next characters will be read another time around
+/* getstring: read a string from the input
 */
 /*ARGSUSED*/
 PRIVATE struct string *
@@ -236,32 +220,24 @@ getstring(isident)
        register char *p;
        register int n;
        register struct string *s = &string;
+       struct e_arg dummy;
 
-       if (!(state & INSTRING)) {      /* Not reading a string yet */
-               struct e_arg dummy;
-
-               getarg(cst_ptyp, &dummy);
+       getarg(cst_ptyp, &dummy);
                                        /* Read length of string */
-               strleft = dummy.ema_cst;
+       n = dummy.ema_cst;
 #ifdef CHECKING
-               if (strleft < 0) {
-                       xerror("Negative length in string");
-                       s->length = 0;
-                       return s;
-               }
-#endif CHECKING
+       if (n < 0) {
+               xerror("Negative length in string");
+               s->length = 0;
+               return s;
        }
+#endif CHECKING
 
-       if (strleft <= STRSIZ) {        /* Handle the whole string */
-               n = strleft;
-               state &= ~INSTRING;
-       }
-       else {                          /* Handle STRSIZ characters of it, and
-                                          indicate that there is more
-                                       */
-               n = STRSIZ;
-               strleft -= STRSIZ;
-               state |= INSTRING;
+       if (n > s->maxlen) {
+               if (! s->maxlen) {
+                       s->str = Malloc(s->maxlen = 256);
+               }
+               else    s->str = Realloc(s->str, (s->maxlen = (n+255)&~255));
        }
 
        s->length = n;