support for long strings
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user