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 */
31 checkstart = j->startchar;
37 j->relist[0][0].inst = 0;
38 j->relist[1][0].inst = 0;
40 /* Execute machine once for each character, including terminal NUL */
43 /* fast check for first char */
45 switch(j->starttype) {
47 p = runestrchr(s, j->startchar);
48 if(p == 0 || s == j->reol)
55 p = runestrchr(s, '\n');
56 if(p == 0 || s == j->reol)
65 /* switch run lists */
67 tle = j->reliste[flag];
68 nl = j->relist[flag^=1];
69 nle = j->reliste[flag];
72 /* Add first instruction to current list */
73 _rrenewemptythread(tl, progp->startinst, ms, s);
75 /* Execute machine until current list is empty */
76 for(tlp=tl; tlp->inst; tlp++){
77 for(inst=tlp->inst; ; inst = inst->u2.next){
79 case RUNE: /* regular character */
81 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
85 tlp->se.m[inst->u1.subid].s.rsp = s;
88 tlp->se.m[inst->u1.subid].e.rep = s;
92 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
96 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
100 if(s == bol || *(s-1) == '\n')
104 if(s == j->reol || r == 0 || r == '\n')
108 ep = inst->u1.cp->end;
109 for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
110 if(r >= rp[0] && r <= rp[1]){
111 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
117 ep = inst->u1.cp->end;
118 for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
119 if(r >= rp[0] && r <= rp[1])
122 if(_renewthread(nl, inst->u2.next, ms, &tlp->se)==nle)
126 /* evaluate right choice later */
127 if(_renewthread(tlp, inst->u1.right, ms, &tlp->se) == tle)
129 /* efficiency: advance and re-evaluate */
131 case END: /* Match! */
133 tlp->se.m[0].e.rep = s;
135 _renewmatch(mp, ms, &tlp->se);
143 checkstart = j->startchar && nl->inst==0;
150 rregexec2(Reprog *progp, /* program to run */
151 Rune *bol, /* string to run machine on */
152 Resub *mp, /* subexpression elements */
153 int ms, /* number of elements at mp */
157 Relist relist0[5*LISTSIZE], relist1[5*LISTSIZE];
160 j->relist[0] = relist0;
161 j->relist[1] = relist1;
162 j->reliste[0] = relist0 + nelem(relist0) - 2;
163 j->reliste[1] = relist1 + nelem(relist1) - 2;
165 return rregexec1(progp, bol, mp, ms, j);
169 rregexec(Reprog *progp, /* program to run */
170 Rune *bol, /* string to run machine on */
171 Resub *mp, /* subexpression elements */
172 int ms) /* number of elements at mp */
175 Relist relist0[LISTSIZE], relist1[LISTSIZE];
179 * use user-specified starting/ending location if specified
185 j.rstarts = mp->s.rsp;
191 if(progp->startinst->type == RUNE && progp->startinst->u1.r < Runeself) {
193 j.startchar = progp->startinst->u1.r;
195 if(progp->startinst->type == BOL)
199 j.relist[0] = relist0;
200 j.relist[1] = relist1;
201 j.reliste[0] = relist0 + nelem(relist0) - 2;
202 j.reliste[1] = relist1 + nelem(relist1) - 2;
204 rv = rregexec1(progp, bol, mp, ms, &j);
207 rv = rregexec2(progp, bol, mp, ms, &j);