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);
51 if(p == 0 || s == j->eol)
59 if(p == 0 || s == j->eol)
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, ms, 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, ms, &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, ms, &tlp->se)==nle)
104 if(_renewthread(nl, inst->u2.next, ms, &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, ms, &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, ms, &tlp->se)==nle)
134 /* evaluate right choice later */
135 if(_renewthread(tlp, inst->u1.right, ms, &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 */
166 Relist *relist0, *relist1;
169 relist0 = malloc(BIGLISTSIZE*sizeof(Relist));
172 relist1 = malloc(BIGLISTSIZE*sizeof(Relist));
177 j->relist[0] = relist0;
178 j->relist[1] = relist1;
179 j->reliste[0] = relist0 + BIGLISTSIZE - 2;
180 j->reliste[1] = relist1 + BIGLISTSIZE - 2;
182 rv = regexec1(progp, bol, mp, ms, j);
189 regexec(Reprog *progp, /* program to run */
190 char *bol, /* string to run machine on */
191 Resub *mp, /* subexpression elements */
192 int ms) /* number of elements at mp */
195 Relist relist0[LISTSIZE], relist1[LISTSIZE];
199 * use user-specified starting/ending location if specified
211 if(progp->startinst->type == RUNE && progp->startinst->u1.r < Runeself) {
213 j.startchar = progp->startinst->u1.r;
215 if(progp->startinst->type == BOL)
219 j.relist[0] = relist0;
220 j.relist[1] = relist1;
221 j.reliste[0] = relist0 + nelem(relist0) - 2;
222 j.reliste[1] = relist1 + nelem(relist1) - 2;
224 rv = regexec1(progp, bol, mp, ms, &j);
227 rv = regexec2(progp, bol, mp, ms, &j);