aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/sam/regexp.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2007-06-09 05:17:47 +0000
committerrsc <devnull@localhost>2007-06-09 05:17:47 +0000
commitc99ef336aaa39a0c7aa2d0c62e93680764790605 (patch)
tree8c0ddd5516e301b421faa636667bb4f238b980e8 /src/cmd/sam/regexp.c
parent1d550471f117b3215fb2b2fd0b873ee6cb77f913 (diff)
downloadplan9port-c99ef336aaa39a0c7aa2d0c62e93680764790605.tar.gz
plan9port-c99ef336aaa39a0c7aa2d0c62e93680764790605.tar.bz2
plan9port-c99ef336aaa39a0c7aa2d0c62e93680764790605.zip
better fix
Diffstat (limited to 'src/cmd/sam/regexp.c')
-rw-r--r--src/cmd/sam/regexp.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/cmd/sam/regexp.c b/src/cmd/sam/regexp.c
index 937fb4fe..8beaa036 100644
--- a/src/cmd/sam/regexp.c
+++ b/src/cmd/sam/regexp.c
@@ -44,10 +44,10 @@ struct Ilist
Posn startp; /* first char of match */
};
-#define NLIST 128
+#define NLIST 127
Ilist *tl, *nl; /* This list, next list */
-Ilist list[2][NLIST];
+Ilist list[2][NLIST+1]; /* +1 for trailing null */
static Rangeset sempty;
/*
@@ -104,7 +104,7 @@ int Nclass; /* high water mark */
Rune **class;
int negateclass;
-void addinst(Ilist *l, Inst *inst, Rangeset *sep);
+int addinst(Ilist *l, Inst *inst, Rangeset *sep);
void newmatch(Rangeset*);
void bnewmatch(Rangeset*);
void pushand(Inst*, Inst*);
@@ -531,7 +531,7 @@ classmatch(int classno, int c, int negate)
* *l must be pending when addinst called; if *l has been looked
* at already, the optimization is a bug.
*/
-void
+int
addinst(Ilist *l, Inst *inst, Rangeset *sep)
{
Ilist *p;
@@ -540,12 +540,13 @@ addinst(Ilist *l, Inst *inst, Rangeset *sep)
if(p->inst==inst){
if((sep)->p[0].p1 < p->se.p[0].p1)
p->se= *sep; /* this would be bug */
- return; /* It's already there */
+ return 0; /* It's already there */
}
}
p->inst = inst;
p->se= *sep;
(p+1)->inst = 0;
+ return 1;
}
int
@@ -592,11 +593,11 @@ execute(File *f, Posn startp, Posn eof)
nnl = 0;
if(sel.p[0].p1<0 && (!wrapped || p<startp || startp==eof)){
/* Add first instruction to this list */
+ sempty.p[0].p1 = p;
+ if(addinst(tl, startinst, &sempty))
if(++ntl >= NLIST)
Overflow:
error(Eoverflow);
- sempty.p[0].p1 = p;
- addinst(tl, startinst, &sempty);
}
/* Execute machine until this list is empty */
for(tlp = tl; inst = tlp->inst; tlp++){ /* assignment = */
@@ -605,9 +606,9 @@ execute(File *f, Posn startp, Posn eof)
default: /* regular character */
if(inst->type==c){
Addinst:
+ if(addinst(nl, inst->next, &tlp->se))
if(++nnl >= NLIST)
goto Overflow;
- addinst(nl, inst->next, &tlp->se);
}
break;
case LBRA:
@@ -645,9 +646,9 @@ execute(File *f, Posn startp, Posn eof)
break;
case OR:
/* evaluate right choice later */
+ if(addinst(tl, inst->right, &tlp->se))
if(++ntl >= NLIST)
goto Overflow;
- addinst(tl, inst->right, &tlp->se);
/* efficiency: advance and re-evaluate */
inst = inst->left;
goto Switchstmt;
@@ -717,12 +718,12 @@ bexecute(File *f, Posn startp)
nnl = 0;
if(sel.p[0].p1<0 && (!wrapped || p>startp)){
/* Add first instruction to this list */
+ /* the minus is so the optimizations in addinst work */
+ sempty.p[0].p1 = -p;
+ if(addinst(tl, bstartinst, &sempty))
if(++ntl >= NLIST)
Overflow:
error(Eoverflow);
- /* the minus is so the optimizations in addinst work */
- sempty.p[0].p1 = -p;
- addinst(tl, bstartinst, &sempty);
}
/* Execute machine until this list is empty */
for(tlp = tl; inst = tlp->inst; tlp++){ /* assignment = */
@@ -731,9 +732,9 @@ bexecute(File *f, Posn startp)
default: /* regular character */
if(inst->type == c){
Addinst:
+ if(addinst(nl, inst->next, &tlp->se))
if(++nnl >= NLIST)
goto Overflow;
- addinst(nl, inst->next, &tlp->se);
}
break;
case LBRA:
@@ -771,9 +772,9 @@ bexecute(File *f, Posn startp)
break;
case OR:
/* evaluate right choice later */
+ if(addinst(tl, inst->right, &tlp->se))
if(++ntl >= NLIST)
goto Overflow;
- addinst(tlp, inst->right, &tlp->se);
/* efficiency: advance and re-evaluate */
inst = inst->left;
goto Switchstmt;