8 * <0 if we ran out of _relist space
11 rregexec1(Reprog *progp, /* program to run */
12 Rune *bol, /* string to run machine on */
13 Resub *mp, /* subexpression elements */
14 int ms, /* number of elements at mp */
23 Relist* tl; /* This list, next list */
25 Relist* tle; /* ends of this and next list */
30 checkstart = j->startchar;
36 j->relist[0][0].inst = 0;
37 j->relist[1][0].inst = 0;
39 /* Execute machine once for each character, including terminal NUL */
43 /* fast check for first char */
45 switch(j->starttype) {
47 while(*s != j->startchar) {
48 if(*s == 0 || s == j->reol)
57 if(*s == 0 || s == j->reol)
67 /* switch run lists */
69 tle = j->reliste[flag];
70 nl = j->relist[flag^=1];
71 nle = j->reliste[flag];
74 /* Add first instruction to current list */
75 _rrenewemptythread(tl, progp->startinst, ms, s);
77 /* Execute machine until current list is empty */
78 for(tlp=tl; tlp->inst; tlp++){
79 for(inst=tlp->inst; ; inst = inst->u2.next){
81 case RUNE: /* regular character */
83 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
87 tlp->se.m[inst->u1.subid].s.rsp = s;
90 tlp->se.m[inst->u1.subid].e.rep = s;
94 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
98 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
102 if(s == bol || *(s-1) == '\n')
106 if(s == j->reol || r == 0 || r == '\n')
110 ep = inst->u1.cp->end;
111 for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
112 if(r >= rp[0] && r <= rp[1]){
113 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
119 ep = inst->u1.cp->end;
120 for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
121 if(r >= rp[0] && r <= rp[1])
124 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
128 /* evaluate right choice later */
129 if(_renewthread(tlp, inst->u1.right, ms, &tlp->se) == tle)
131 /* efficiency: advance and re-evaluate */
133 case END: /* Match! */
135 tlp->se.m[0].e.rep = s;
137 _renewmatch(mp, ms, &tlp->se);
145 checkstart = j->startchar && nl->inst==0;
152 rregexec2(Reprog *progp, /* program to run */
153 Rune *bol, /* string to run machine on */
154 Resub *mp, /* subexpression elements */
155 int ms, /* number of elements at mp */
159 Relist relist0[5*LISTSIZE], relist1[5*LISTSIZE];
162 j->relist[0] = relist0;
163 j->relist[1] = relist1;
164 j->reliste[0] = relist0 + nelem(relist0) - 2;
165 j->reliste[1] = relist1 + nelem(relist1) - 2;
167 return rregexec1(progp, bol, mp, ms, j);
171 rregexec(Reprog *progp, /* program to run */
172 Rune *bol, /* string to run machine on */
173 Resub *mp, /* subexpression elements */
174 int ms) /* number of elements at mp */
177 Relist relist0[LISTSIZE], relist1[LISTSIZE];
181 * use user-specified starting/ending location if specified
187 j.rstarts = mp->s.rsp;
193 if(progp->startinst->type == RUNE && progp->startinst->u1.r < Runeself) {
195 j.startchar = progp->startinst->u1.r;
197 if(progp->startinst->type == BOL)
201 j.relist[0] = relist0;
202 j.relist[1] = relist1;
203 j.reliste[0] = relist0 + nelem(relist0) - 2;
204 j.reliste[1] = relist1 + nelem(relist1) - 2;
206 rv = rregexec1(progp, bol, mp, ms, &j);
209 rv = rregexec2(progp, bol, mp, ms, &j);