support for long strings
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ emitstr(zero)
|
||||
register char *p;
|
||||
|
||||
p = stringbuf;
|
||||
i = *p++ & 0377;
|
||||
i = stringlen;
|
||||
while (--i >= 0)
|
||||
emit1(*p++);
|
||||
if (zero)
|
||||
|
||||
Reference in New Issue
Block a user