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 */
76 nlist->tail = &t->next;
86 if(*rsp > curinst->r1) {
94 nlist->tail = &t->next;
107 if(rsp == str || rsp[-1] == L'\n') {
113 if(*rsp == L'\0' && rep == nil) {
121 curinst = curinst->a;
130 next->pc = curinst->b;
132 memcpy(next->sem, t->sem, sizeof(Resub)*msize);
134 next->next = t->next;
136 curinst = curinst->a;
139 if(curinst->sub < msize)
140 t->sem[curinst->sub].rsp = rsp;
144 if(curinst->sub == 0) {
145 /* "Highest" priority is the left-most longest. */
146 if (t->pri > matchpri)
150 if(sem != nil && msize > 0) {
151 memcpy(sem, t->sem, sizeof(Resub)*msize);
156 if(curinst->sub < msize)
157 t->sem[curinst->sub].rep = rsp;
171 /* Start again once if we haven't found anything. */
172 if(first == 1 && match == 0) {
181 memset(t->sem, 0, sizeof(Resub)*msize);
182 /* "Lower" priority thread */
183 t->pri = matchpri = pri++;
185 curinst = prog->startinst;
188 /* If we have a match and no extant threads, we are done. */
189 if(match == 1 && nlist->head == nil)
195 nlist->tail = &nlist->head;