6 typedef struct RethreadQ RethreadQ;
14 rregexec(Reprog *prog, Rune *str, Resub *sem, int msize)
16 RethreadQ lists[2], *clist, *nlist, *tmp;
17 Rethread *t, *next, *pooltop, *avail;
19 Rune *rsp, *rep, endr, last;
20 int match, first, gen, pri, matchpri;
25 if(prog->startinst->gen != 0) {
26 for(curinst = prog->startinst; curinst < prog->startinst + prog->len; curinst++)
32 clist->tail = &clist->head;
35 nlist->tail = &nlist->head;
37 pooltop = prog->threads + prog->nthr;
40 pri = matchpri = gen = match = 0;
44 if(sem != nil && msize > 0) {
47 if(sem->rep != nil && *sem->rep != L'\0') {
54 for(; last != L'\0'; rsp++) {
63 if(curinst->gen == gen)
68 if(*rsp != curinst->r)
70 case OANY: /* fallthrough */
75 nlist->tail = &t->next;
85 if(*rsp > curinst->r1) {
93 nlist->tail = &t->next;
106 if(rsp == str || rsp[-1] == L'\n') {
112 if(*rsp == '\n' || *rsp == L'\0' && rep == nil) {
118 curinst = curinst->a;
127 next->pc = curinst->b;
129 memcpy(next->sem, t->sem, sizeof(Resub)*msize);
131 next->next = t->next;
133 curinst = curinst->a;
136 if(curinst->sub < msize)
137 t->sem[curinst->sub].rsp = rsp;
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].rep = rsp;
168 /* Start again once if we haven't found anything. */
169 if(first == 1 && match == 0) {
178 memset(t->sem, 0, sizeof(Resub)*msize);
179 /* "Lower" priority thread */
180 t->pri = matchpri = pri++;
182 curinst = prog->startinst;
185 /* If we have a match and no extant threads, we are done. */
186 if(match == 1 && nlist->head == nil)
192 nlist->tail = &nlist->head;