64-bit safe (from plan9)

This commit is contained in:
rsc 2006-04-20 20:24:00 +00:00
parent 4515de8f50
commit 0afb7989d3
5 changed files with 42 additions and 15 deletions

View file

@ -90,6 +90,7 @@ extern int *name;
extern int *left;
extern int *right;
extern int *parent;
extern uchar **ptr;
extern uchar *nullstr;
extern int tptr;
extern uchar pushc[TOKENSIZE];
@ -152,6 +153,7 @@ extern void lgate(void);
extern int lookup(uchar *, uchar **);
extern int member(int, uchar *);
extern void mkmatch(void);
extern int mnp(int, void*);
extern int mn0(int);
extern int mn1(int, int);
extern int mn2(int, int, int);

View file

@ -45,6 +45,7 @@ int *left;
int *right;
int *parent;
uchar *nullstr;
uchar **ptr;
int tptr;
uchar pushc[TOKENSIZE];
uchar slist[STARTSIZE];

View file

@ -120,13 +120,13 @@ r: CHAR
}
else
p = psave;
$$.i = mn1(RCCL,(int)p);
$$.i = mnp(RCCL,p);
cclinter(1);
}
| CCL
={ $$.i = mn1(RCCL,$1.i); }
={ $$.i = mnp(RCCL,$1.cp); }
| NCCL
={ $$.i = mn1(RNCCL,$1.i); }
={ $$.i = mnp(RNCCL,$1.cp); }
| r '*'
={ $$.i = mn1(STAR,$1.i); }
| r '+'
@ -253,7 +253,8 @@ yylex(void)
right = myalloc(treesize,sizeof(*right));
nullstr = myalloc(treesize,sizeof(*nullstr));
parent = myalloc(treesize,sizeof(*parent));
if(name == 0 || left == 0 || right == 0 || parent == 0 || nullstr == 0)
ptr = myalloc(treesize,sizeof(*ptr));
if(name == 0 || left == 0 || right == 0 || parent == 0 || nullstr == 0 || ptr == 0)
error("Too little core for parse tree");
return(freturn(DELIM));
case 'p': case 'P': /* has overridden number of positions */

View file

@ -287,6 +287,7 @@ gch(void){
if(c == Beof) {
eof = TRUE;
Bterm(fin);
fin = 0;
return(0);
}
if(c == '\n')yyline++;
@ -330,6 +331,28 @@ mn2(int a, int d, int c)
return(tptr++);
}
int
mnp(int a, void *p)
{
name[tptr] = a;
left[tptr] = 0;
parent[tptr] = 0;
nullstr[tptr] = 0;
ptr[tptr] = p;
switch(a){
case RCCL:
case RNCCL:
if(strlen(p) == 0) nullstr[tptr] = TRUE;
break;
default:
error("bad switch mnp %d %P", a, p);
break;
}
if(tptr > treesize)
error("Parse tree too big %s",(treesize == TREESIZE?"\nTry using %e num":""));
return(tptr++);
}
int
mn1(int a, int d)
{
@ -338,10 +361,6 @@ mn1(int a, int d)
parent[tptr] = 0;
nullstr[tptr] = 0;
switch(a){
case RCCL:
case RNCCL:
if(strlen((char *)d) == 0) nullstr[tptr] = TRUE;
break;
case STAR:
case QUEST:
nullstr[tptr] = TRUE;
@ -421,7 +440,9 @@ dupl(int n)
switch(i){
case RNULLS:
return(mn0(i));
case RCCL: case RNCCL: case FINAL: case S1FINAL: case S2FINAL:
case RCCL: case RNCCL:
return(mnp(i,ptr[n]));
case FINAL: case S1FINAL: case S2FINAL:
return(mn1(i,left[n]));
case STAR: case QUEST: case PLUS: case CARAT:
return(mn1(i,dupl(left[n])));
@ -441,6 +462,8 @@ dupl(int n)
void
allprint(int c)
{
if(c < 0)
c += 256; /* signed char */
switch(c){
case 014:
print("\\f");
@ -531,11 +554,11 @@ treedump(void)
break;
case RCCL:
print("ccl ");
strpt(left[t]);
allprint(ptr[t]);
break;
case RNCCL:
print("nccl ");
strpt(left[t]);
allprint(ptr[t]);
break;
case DIV:
print("/ %d %d",left[t],right[t]);

View file

@ -22,7 +22,7 @@ cfoll(int v)
else if(i == RCCL || i == RNCCL){ /* compress ccl list */
for(j=1; j<NCH;j++)
symbol[j] = (i==RNCCL);
p = (uchar *)left[v];
p = ptr[v];
while(*p)
symbol[*p++] = (i == RCCL);
p = pcptr;
@ -36,7 +36,7 @@ cfoll(int v)
*pcptr++ = 0;
if(pcptr > pchar + pchlen)
error("Too many packed character classes");
left[v] = (int)p;
ptr[v] = p;
name[v] = RCCL; /* RNCCL eliminated */
# ifdef DEBUG
if(debug && *p){
@ -238,7 +238,7 @@ cgoto(void)
else switch(name[curpos]){
case RCCL:
tryit = TRUE;
q = (uchar *)left[curpos];
q = ptr[curpos];
while(*q){
for(j=1;j<NCH;j++)
if(cindex[j] == *q)
@ -323,7 +323,7 @@ nextstate(int s, int c)
j = name[curpos];
if(j < NCH && j == c
|| j == RSTR && c == right[curpos]
|| j == RCCL && member(c, (uchar *)left[curpos])){
|| j == RCCL && member(c, ptr[curpos])){
f = foll[curpos];
number = *f;
newpos = f+1;