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, *nextthr, **availthr;
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 for(i = 0; i < prog->nthr; i++)
39 prog->thrpool[i] = prog->threads + i;
40 availthr = prog->thrpool + prog->nthr;
42 pri = matchpri = gen = match = 0;
46 if(sem != nil && msize > 0) {
49 if(sem->ep != nil && *sem->ep != '\0') {
56 for(; r != L'\0'; sp += i) {
58 i = chartorune(&r, sp);
65 if(curinst->gen == gen)
72 case OANY: /* fallthrough */
78 nlist->tail = &t->next;
96 nlist->tail = &t->next;
109 if(sp == str || sp[-1] == '\n') {
115 if(r == L'\0' && ep == nil) {
123 curinst = curinst->a;
126 nextthr = *--availthr;
127 nextthr->pc = curinst->b;
129 memcpy(nextthr->sem, t->sem, sizeof(Resub)*msize);
130 nextthr->pri = t->pri;
131 nextthr->next = t->next;
133 curinst = curinst->a;
136 if(curinst->sub < msize)
137 t->sem[curinst->sub].sp = sp;
141 if(curinst->sub == 0) {
142 /* "Highest" priority is the left-most longest. */
143 if (t->pri > matchpri)
147 if(sem != nil && msize > 0) {
148 memcpy(sem, t->sem, sizeof(Resub)*msize);
153 if(curinst->sub < msize)
154 t->sem[curinst->sub].ep = sp;
166 /* Start again once if we haven't found anything. */
167 if(first == 1 && match == 0) {
171 memset(t->sem, 0, sizeof(Resub)*msize);
172 /* "Lower" priority thread */
173 t->pri = matchpri = pri++;
175 curinst = prog->startinst;
178 /* If we have a match and no extant threads, we are done. */
179 if(match == 1 && nlist->head == nil)
185 nlist->tail = &nlist->head;