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];
extern long atol();
extern char *mktemp();
extern char *malloc();
+extern char *realloc();
extern char *calloc();
extern char *getenv();
extern char *strncpy();
{ 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'
#endif
newsymb(
- *(stringbuf+1) ? stringbuf+1 : (char *) 0,
+ *stringbuf ? stringbuf : (char *) 0,
(short)(
($4.typ & (S_EXT|S_TYP))
|
| 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))
|
{ if ((sflag & SYM_LIN) && PASS_SYMB) {
hllino = 0;
newsymb(
- stringbuf+1,
+ stringbuf,
(short)(DOTTYP | S_FIL),
(short)0,
(valu_t)DOTVAL
$$.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
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:
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:
{
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') {
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);
}
register char *p;
p = stringbuf;
- i = *p++ & 0377;
+ i = stringlen;
while (--i >= 0)
emit1(*p++);
if (zero)
*/
#include <assert.h>
+#include <alloc.h>
#include <system.h>
#include <em_label.h>
#include <em_arith.h>
}
}
-#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? */
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) {
* (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.
*/
s = &string;
p = s->str;
+ if (!p) {
+ s->maxlen = 256;
+ s->str = p = Malloc(256);
+ }
c = getbyte();
if (!(isalpha(c) || c == '_')) {
}
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();
}
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);
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;
register int c;
register struct e_arg *ap;
{
- char str[STRSIZ + 1];
+ char str[256 + 1];
register char *p = str;
int n;
int expsign;
n = sp_cst4;
for (;;) {
- if (p >= &(str[STRSIZ])) {
+ if (p >= &(str[256])) {
syntax("number too long");
return sp_cst4;
}
PRIVATE
line_line()
{
- static char filebuf[STRSIZ + 1];
+ static char filebuf[256 + 1];
char *btscpy();
struct e_arg dummy;
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;
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;
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;
}
#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 *
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;