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, *nextthr, **availthr;
19 Rune *rsp, *rep, endr, last;
20 int i, 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 for(i = 0; i < prog->nthr; i++)
38 prog->thrpool[i] = prog->threads + i;
39 availthr = prog->thrpool + prog->nthr;
41 pri = matchpri = gen = match = 0;
45 if(sem != nil && msize > 0) {
48 if(sem->rep != nil && *sem->rep != L'\0') {
55 for(; last != L'\0'; rsp++) {
64 if(curinst->gen == gen)
69 if(*rsp != curinst->r)
71 case OANY: /* fallthrough */
77 nlist->tail = &t->next;
87 if(*rsp > curinst->r1) {
95 nlist->tail = &t->next;
108 if(rsp == str || rsp[-1] == L'\n') {
114 if(*rsp == L'\0' && rep == nil) {
122 curinst = curinst->a;
125 nextthr = *--availthr;
126 nextthr->pc = curinst->b;
128 memcpy(nextthr->sem, t->sem, sizeof(Resub)*msize);
129 nextthr->pri = t->pri;
130 nextthr->next = t->next;
132 curinst = curinst->a;
135 if(curinst->sub < msize)
136 t->sem[curinst->sub].rsp = rsp;
140 if(curinst->sub == 0) {
141 /* "Highest" priority is the left-most longest. */
142 if (t->pri > matchpri)
146 if(sem != nil && msize > 0) {
147 memcpy(sem, t->sem, sizeof(Resub)*msize);
152 if(curinst->sub < msize)
153 t->sem[curinst->sub].rep = rsp;
165 /* Start again once if we haven't found anything. */
166 if(first == 1 && match == 0) {
170 memset(t->sem, 0, sizeof(Resub)*msize);
171 /* "Lower" priority thread */
172 t->pri = matchpri = pri++;
174 curinst = prog->startinst;
177 /* If we have a match and no extant threads, we are done. */
178 if(match == 1 && nlist->head == nil)
184 nlist->tail = &nlist->head;