9 * <0 if we ran out of _relist space
12 regexec1(Reprog *progp, /* program to run */
13 char *bol, /* string to run machine on */
14 Resub *mp, /* subexpression elements */
15 int ms, /* number of elements at mp */
26 Relist* tl; /* This list, next list */
28 Relist* tle; /* ends of this and next list */
34 checkstart = j->starttype;
40 j->relist[0][0].inst = 0;
41 j->relist[1][0].inst = 0;
43 /* Execute machine once for each character, including terminal NUL */
46 /* fast check for first char */
48 switch(j->starttype) {
50 p = utfrune(s, j->startchar);
66 if(r < (Rune)Runeself)
69 n = chartorune(&r, s);
71 /* switch run lists */
73 tle = j->reliste[flag];
74 nl = j->relist[flag^=1];
75 nle = j->reliste[flag];
78 /* Add first instruction to current list */
80 _renewemptythread(tl, progp->startinst, s);
82 /* Execute machine until current list is empty */
83 for(tlp=tl; tlp->inst; tlp++){ /* assignment = */
84 for(inst = tlp->inst; ; inst = inst->u2.next){
86 case RUNE: /* regular character */
88 if(_renewthread(nl, inst->u2.next, &tlp->se)==nle)
93 tlp->se.m[inst->u1.subid].s.sp = s;
96 tlp->se.m[inst->u1.subid].e.ep = s;
100 if(_renewthread(nl, inst->u2.next, &tlp->se)==nle)
104 if(_renewthread(nl, inst->u2.next, &tlp->se)==nle)
108 if(s == bol || *(s-1) == '\n')
112 if(s == j->eol || r == 0 || r == '\n')
116 ep = inst->u1.cp->end;
117 for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
118 if(r >= rp[0] && r <= rp[1]){
119 if(_renewthread(nl, inst->u2.next, &tlp->se)==nle)
125 ep = inst->u1.cp->end;
126 for(rp = inst->u1.cp->spans; rp < ep; rp += 2)
127 if(r >= rp[0] && r <= rp[1])
130 if(_renewthread(nl, inst->u2.next, &tlp->se)==nle)
134 /* evaluate right choice later */
135 if(_renewthread(tlp, inst->u1.right, &tlp->se) == tle)
137 /* efficiency: advance and re-evaluate */
139 case END: /* Match! */
141 tlp->se.m[0].e.ep = s;
143 _renewmatch(mp, ms, &tlp->se);
151 checkstart = j->starttype && nl->inst==0;
158 regexec2(Reprog *progp, /* program to run */
159 char *bol, /* string to run machine on */
160 Resub *mp, /* subexpression elements */
161 int ms, /* number of elements at mp */
165 Relist relist0[BIGLISTSIZE], relist1[BIGLISTSIZE];
168 j->relist[0] = relist0;
169 j->relist[1] = relist1;
170 j->reliste[0] = relist0 + nelem(relist0) - 2;
171 j->reliste[1] = relist1 + nelem(relist1) - 2;
173 return regexec1(progp, bol, mp, ms, j);
177 regexec(Reprog *progp, /* program to run */
178 char *bol, /* string to run machine on */
179 Resub *mp, /* subexpression elements */
180 int ms) /* number of elements at mp */
183 Relist relist0[LISTSIZE], relist1[LISTSIZE];
187 * use user-specified starting/ending location if specified
199 if(progp->startinst->type == RUNE && progp->startinst->u1.r < (Rune)Runeself) {
201 j.startchar = progp->startinst->u1.r;
203 if(progp->startinst->type == BOL)
207 j.relist[0] = relist0;
208 j.relist[1] = relist1;
209 j.reliste[0] = relist0 + nelem(relist0) - 2;
210 j.reliste[1] = relist1 + nelem(relist1) - 2;
212 rv = regexec1(progp, bol, mp, ms, &j);
215 rv = regexec2(progp, bol, mp, ms, &j);