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