6 typedef struct RethreadQ RethreadQ;
14 regexec(Reprog *prog, char *str, Resub *sem, int msize)
16 RethreadQ lists[2], *clist, *nlist, *tmp;
17 Rethread *t, *next, *pooltop, *avail;
21 int i, match, first, gen, matchpri, pri;
26 if(prog->startinst->gen != 0) {
27 for(curinst = prog->startinst; curinst < prog->startinst + prog->len; curinst++)
33 clist->tail = &clist->head;
36 nlist->tail = &nlist->head;
38 pooltop = prog->threads + prog->nthr;
41 pri = matchpri = gen = match = 0;
45 if(sem != nil && msize > 0) {
48 if(sem->ep != nil && *sem->ep != '\0') {
55 for(; r != L'\0'; sp += i) {
57 i = chartorune(&r, sp);
64 if(curinst->gen == gen)
71 case OANY: /* fallthrough */
77 nlist->tail = &t->next;
95 nlist->tail = &t->next;
108 if(sp == str || sp[-1] == '\n') {
114 if(r == L'\0' && ep == nil) {
122 curinst = curinst->a;
131 next->pc = curinst->b;
133 memcpy(next->sem, t->sem, sizeof(Resub)*msize);
135 next->next = t->next;
137 curinst = curinst->a;
140 if(curinst->sub < msize)
141 t->sem[curinst->sub].sp = sp;
145 if(curinst->sub == 0) {
146 /* "Highest" priority is the left-most longest. */
147 if (t->pri > matchpri)
151 if(sem != nil && msize > 0) {
152 memcpy(sem, t->sem, sizeof(Resub)*msize);
157 if(curinst->sub < msize)
158 t->sem[curinst->sub].ep = sp;
172 /* Start again once if we haven't found anything. */
173 if(first == 1 && match == 0) {
182 memset(t->sem, 0, sizeof(Resub)*msize);
183 /* "Lower" priority thread */
184 t->pri = matchpri = pri++;
186 curinst = prog->startinst;
189 /* If we have a match and no extant threads, we are done. */
190 if(match == 1 && nlist->head == nil)
196 nlist->tail = &nlist->head;