6 static Resublist sempty; /* empty set of matches */
11 * <0 if we ran out of _relist space
14 regexec1(Reprog *progp, /* program to run */
15 char *bol, /* string to run machine on */
16 Resub *mp, /* subexpression elements */
17 int ms, /* number of elements at mp */
29 Relist* tl; /* This list, next list */
31 Relist* tle; /* ends of this and next list */
36 checkstart = startchar;
40 mp[i].s.sp = mp[i].e.ep = 0;
41 _relist[0][0].inst = _relist[1][0].inst = 0;
43 /* Execute machine once for each character, including terminal NUL */
46 /* fast check for first char */
47 r = *(unsigned char*)s;
48 if(checkstart && r != startchar){
56 n = mbtowc(&r, s, MB_CUR_MAX);
61 /* switch run lists */
64 nl = _relist[flag^=1];
68 /* Add first instruction to current list */
71 _renewthread(tl, progp->startinst, &sempty);
74 /* Execute machine until current list is empty */
75 for(tlp=tl; tlp->inst; tlp++){ /* assignment = */
79 for(inst = tlp->inst; ; inst = inst->l.next){
81 case RUNE: /* regular character */
83 if(_renewthread(nl, inst->l.next, &tlp->se)==nle)
87 tlp->se.m[inst->r.subid].s.sp = s;
90 tlp->se.m[inst->r.subid].e.ep = s;
94 if(_renewthread(nl, inst->l.next, &tlp->se)==nle)
98 if(_renewthread(nl, inst->l.next, &tlp->se)==nle)
102 if(s == bol || *(s-1) == '\n')
106 if(r == 0 || r == '\n')
110 ep = inst->r.cp->end;
111 for(rp = inst->r.cp->spans; rp < ep; rp += 2)
112 if(r >= rp[0] && r <= rp[1]){
113 if(_renewthread(nl, inst->l.next, &tlp->se)==nle)
119 ep = inst->r.cp->end;
120 for(rp = inst->r.cp->spans; rp < ep; rp += 2)
121 if(r >= rp[0] && r <= rp[1])
124 if(_renewthread(nl, inst->l.next, &tlp->se)==nle)
128 /* evaluate right choice later */
129 if(_renewthread(tlp, inst->r.right, &tlp->se) == tle)
131 /* efficiency: advance and re-evaluate */
133 case END: /* Match! */
135 tlp->se.m[0].e.ep = s;
137 _renewmatch(mp, ms, &tlp->se);
143 checkstart = startchar && nl->inst==0;
150 regexec(Reprog *progp, /* program to run */
151 char *bol, /* string to run machine on */
152 Resub *mp, /* subexpression elements */
153 int ms) /* number of elements at mp */
155 char *starts; /* where to start match */
156 char *eol; /* where to end match */
161 * use user-specified starting/ending location if specified
171 startchar = (progp->startinst->type == RUNE && progp->startinst->r.r < Runeself)
172 ? progp->startinst->r.r : 0;
174 /* keep trying till we have enough list space to terminate */
177 _relist[0] = malloc(2*_relistsize*sizeof(Relist));
178 _relist[1] = _relist[0] + _relistsize;
179 _reliste[0] = _relist[0] + _relistsize - 1;
180 _reliste[1] = _relist[1] + _relistsize - 1;
182 regerror("_relist overflow");
184 rv = regexec1(progp, bol, mp, ms, starts, eol, startchar);
189 _relistsize += LISTINCREMENT;