9 * <0 if we ran out of _relist space
12 rregexec1(Reprog *progp, /* program to run */
13 Rune *bol, /* string to run machine on */
14 Resub *mp, /* subexpression elements */
15 int ms, /* number of elements at mp */
24 Relist* tl; /* This list, next list */
26 Relist* tle; /* ends of this and next list */
32 checkstart = j->startchar;
38 j->relist[0][0].inst = 0;
39 j->relist[1][0].inst = 0;
41 /* Execute machine once for each character, including terminal NUL */
44 /* fast check for first char */
46 switch(j->starttype) {
48 p = runestrchr(s, j->startchar);
49 if(p == 0 || s == j->reol)
56 p = runestrchr(s, '\n');
57 if(p == 0 || s == j->reol)
66 /* switch run lists */
68 tle = j->reliste[flag];
69 nl = j->relist[flag^=1];
70 nle = j->reliste[flag];
73 /* Add first instruction to current list */
74 _rrenewemptythread(tl, progp->startinst, ms, s);
76 /* Execute machine until current list is empty */
77 for(tlp=tl; tlp->inst; tlp++){
78 for(inst=tlp->inst; ; inst = inst->next){
80 case RUNE: /* regular character */
82 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
86 tlp->se.m[inst->subid].rsp = s;
89 tlp->se.m[inst->subid].rep = s;
93 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
97 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
101 if(s == bol || *(s-1) == '\n')
105 if(s == j->reol || r == 0 || r == '\n')
110 for(rp = inst->cp->spans; rp < ep; rp += 2)
111 if(r >= rp[0] && r <= rp[1]){
112 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
119 for(rp = inst->cp->spans; rp < ep; rp += 2)
120 if(r >= rp[0] && r <= rp[1])
123 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
127 /* evaluate right choice later */
128 if(_renewthread(tlp, inst->right, ms, &tlp->se) == tle)
130 /* efficiency: advance and re-evaluate */
132 case END: /* Match! */
134 tlp->se.m[0].rep = s;
136 _renewmatch(mp, ms, &tlp->se);
144 checkstart = j->startchar && nl->inst==0;
151 rregexec2(Reprog *progp, /* program to run */
152 Rune *bol, /* string to run machine on */
153 Resub *mp, /* subexpression elements */
154 int ms, /* number of elements at mp */
158 Relist relist0[5*LISTSIZE], relist1[5*LISTSIZE];
161 j->relist[0] = relist0;
162 j->relist[1] = relist1;
163 j->reliste[0] = relist0 + nelem(relist0) - 2;
164 j->reliste[1] = relist1 + nelem(relist1) - 2;
166 return rregexec1(progp, bol, mp, ms, j);
170 rregexec(Reprog *progp, /* program to run */
171 Rune *bol, /* string to run machine on */
172 Resub *mp, /* subexpression elements */
173 int ms) /* number of elements at mp */
176 Relist relist0[LISTSIZE], relist1[LISTSIZE];
180 * use user-specified starting/ending location if specified
192 if(progp->startinst->type == RUNE && progp->startinst->r < Runeself) {
194 j.startchar = progp->startinst->r;
196 if(progp->startinst->type == BOL)
200 j.relist[0] = relist0;
201 j.relist[1] = relist1;
202 j.reliste[0] = relist0 + nelem(relist0) - 2;
203 j.reliste[1] = relist1 + nelem(relist1) - 2;
205 rv = rregexec1(progp, bol, mp, ms, &j);
208 rv = rregexec2(progp, bol, mp, ms, &j);