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 */
76 nlist->tail = &t->next;
94 nlist->tail = &t->next;
107 if(sp == str || sp[-1] == '\n') {
113 if(r == L'\n' || r == L'\0' && ep == nil) {
119 curinst = curinst->a;
128 next->pc = curinst->b;
130 memcpy(next->sem, t->sem, sizeof(Resub)*msize);
132 next->next = t->next;
134 curinst = curinst->a;
137 if(curinst->sub < msize)
138 t->sem[curinst->sub].sp = sp;
142 if(curinst->sub == 0) {
143 /* "Highest" priority is the left-most longest. */
144 if (t->pri > matchpri)
148 if(sem != nil && msize > 0) {
149 memcpy(sem, t->sem, sizeof(Resub)*msize);
154 if(curinst->sub < msize)
155 t->sem[curinst->sub].ep = sp;
169 /* Start again once if we haven't found anything. */
170 if(first == 1 && match == 0) {
179 memset(t->sem, 0, sizeof(Resub)*msize);
180 /* "Lower" priority thread */
181 t->pri = matchpri = pri++;
183 curinst = prog->startinst;
186 /* If we have a match and no extant threads, we are done. */
187 if(match == 1 && nlist->head == nil)
193 nlist->tail = &nlist->head;