10 * <0 if we ran out of _relist space
13 regexec1(Reprog *progp, /* program to run */
14 char *bol, /* string to run machine on */
15 Resub *mp, /* subexpression elements */
16 int ms, /* number of elements at mp */
27 Relist* tl; /* This list, next list */
29 Relist* tle; /* ends of this and next list */
35 checkstart = j->starttype;
41 j->relist[0][0].inst = 0;
42 j->relist[1][0].inst = 0;
44 /* Execute machine once for each character, including terminal NUL */
47 /* fast check for first char */
49 switch(j->starttype) {
51 p = utfrune(s, j->startchar);
52 if(p == 0 || s == j->eol)
60 if(p == 0 || s == j->eol)
70 n = chartorune(&r, s);
72 /* switch run lists */
74 tle = j->reliste[flag];
75 nl = j->relist[flag^=1];
76 nle = j->reliste[flag];
79 /* Add first instruction to current list */
81 _renewemptythread(tl, progp->startinst, ms, s);
83 /* Execute machine until current list is empty */
84 for(tlp=tl; tlp->inst; tlp++){ /* assignment = */
85 for(inst = tlp->inst; ; inst = inst->next){
87 case RUNE: /* regular character */
89 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
94 tlp->se.m[inst->subid].sp = s;
97 tlp->se.m[inst->subid].ep = s;
101 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
105 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
109 if(s == bol || *(s-1) == '\n')
113 if(s == j->eol || r == 0 || r == '\n')
118 for(rp = inst->cp->spans; rp < ep; rp += 2)
119 if(r >= rp[0] && r <= rp[1]){
120 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
127 for(rp = inst->cp->spans; rp < ep; rp += 2)
128 if(r >= rp[0] && r <= rp[1])
131 if(_renewthread(nl, inst->next, ms, &tlp->se)==nle)
135 /* evaluate right choice later */
136 if(_renewthread(tlp, inst->right, ms, &tlp->se) == tle)
138 /* efficiency: advance and re-evaluate */
140 case END: /* Match! */
144 _renewmatch(mp, ms, &tlp->se);
152 checkstart = j->starttype && nl->inst==0;
159 regexec2(Reprog *progp, /* program to run */
160 char *bol, /* string to run machine on */
161 Resub *mp, /* subexpression elements */
162 int ms, /* number of elements at mp */
167 Relist *relist0, *relist1;
170 relist0 = malloc(BIGLISTSIZE*sizeof(Relist));
173 relist1 = malloc(BIGLISTSIZE*sizeof(Relist));
178 j->relist[0] = relist0;
179 j->relist[1] = relist1;
180 j->reliste[0] = relist0 + BIGLISTSIZE - 2;
181 j->reliste[1] = relist1 + BIGLISTSIZE - 2;
183 rv = regexec1(progp, bol, mp, ms, j);
190 regexec(Reprog *progp, /* program to run */
191 char *bol, /* string to run machine on */
192 Resub *mp, /* subexpression elements */
193 int ms) /* number of elements at mp */
196 Relist relist0[LISTSIZE], relist1[LISTSIZE];
200 * use user-specified starting/ending location if specified
212 if(progp->startinst->type == RUNE && progp->startinst->r < Runeself) {
214 j.startchar = progp->startinst->r;
216 if(progp->startinst->type == BOL)
220 j.relist[0] = relist0;
221 j.relist[1] = relist1;
222 j.reliste[0] = relist0 + nelem(relist0) - 2;
223 j.reliste[1] = relist1 + nelem(relist1) - 2;
225 rv = regexec1(progp, bol, mp, ms, &j);
228 rv = regexec2(progp, bol, mp, ms, &j);