Lines Matching refs:m

91 static char *dissect(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
92 static char *backref(struct match *m, char *start, char *stop, sopno startst, sopno stopst, sopno l…
93 static char *fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
94 static char *slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst);
106 static void print(struct match *m, char *caption, states st, int ch, FILE *d);
109 static void at(struct match *m, char *title, char *start, char *stop, sopno startst, sopno stopst);
121 #define SP(t, s, c) print(m, t, s, c, stdout)
122 #define AT(t, p1, p2, s1, s2) at(m, t, p1, p2, s1, s2)
123 #define NOTE(str) { if (m->eflags&REG_TRACE) printf("=%s\n", (str)); }
145 struct match *m = &mv; in matcher() local
217 m->g = g; in matcher()
218 m->eflags = eflags; in matcher()
219 m->pmatch = NULL; in matcher()
220 m->lastpos = NULL; in matcher()
221 m->offp = string; in matcher()
222 m->beginp = start; in matcher()
223 m->endp = stop; in matcher()
224 STATESETUP(m, 4); in matcher()
225 SETUP(m->st); in matcher()
226 SETUP(m->fresh); in matcher()
227 SETUP(m->tmp); in matcher()
228 SETUP(m->empty); in matcher()
229 CLEAR(m->empty); in matcher()
237 endp = fast(m, start, stop, gf, gl); in matcher()
239 STATETEARDOWN(m); in matcher()
246 assert(m->coldp != NULL); in matcher()
249 endp = slow(m, m->coldp, stop, gf, gl); in matcher()
252 assert(m->coldp < m->endp); in matcher()
253 m->coldp++; in matcher()
259 if (m->pmatch == NULL) in matcher()
260 m->pmatch = (regmatch_t *)malloc((m->g->nsub + 1) * in matcher()
262 if (m->pmatch == NULL) { in matcher()
263 STATETEARDOWN(m); in matcher()
266 for (i = 1; i <= m->g->nsub; i++) in matcher()
267 m->pmatch[i].rm_so = m->pmatch[i].rm_eo = -1; in matcher()
268 if (!g->backrefs && !(m->eflags&REG_BACKR)) { in matcher()
270 dp = dissect(m, m->coldp, endp, gf, gl); in matcher()
272 if (g->nplus > 0 && m->lastpos == NULL) in matcher()
273 m->lastpos = (char **)malloc((g->nplus+1) * in matcher()
275 if (g->nplus > 0 && m->lastpos == NULL) { in matcher()
276 free(m->pmatch); in matcher()
277 STATETEARDOWN(m); in matcher()
281 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); in matcher()
288 assert(g->nplus == 0 || m->lastpos != NULL); in matcher()
290 if (dp != NULL || endp <= m->coldp) in matcher()
293 endp = slow(m, m->coldp, endp-1, gf, gl); in matcher()
298 for (i = 1; i <= m->g->nsub; i++) { in matcher()
299 assert(m->pmatch[i].rm_so == -1); in matcher()
300 assert(m->pmatch[i].rm_eo == -1); in matcher()
304 dp = backref(m, m->coldp, endp, gf, gl, (sopno)0); in matcher()
312 start = m->coldp + 1; /* recycle starting later */ in matcher()
318 pmatch[0].rm_so = m->coldp - m->offp; in matcher()
319 pmatch[0].rm_eo = endp - m->offp; in matcher()
322 assert(m->pmatch != NULL); in matcher()
324 if (i <= m->g->nsub) in matcher()
325 pmatch[i] = m->pmatch[i]; in matcher()
332 if (m->pmatch != NULL) in matcher()
333 free((char *)m->pmatch); in matcher()
334 if (m->lastpos != NULL) in matcher()
335 free((char *)m->lastpos); in matcher()
336 STATETEARDOWN(m); in matcher()
346 dissect(struct match *m, in dissect() argument
371 switch (OP(m->g->strip[es])) { in dissect()
374 es += OPND(m->g->strip[es]); in dissect()
377 while (OP(m->g->strip[es]) != O_CH) in dissect()
378 es += OPND(m->g->strip[es]); in dissect()
384 switch (OP(m->g->strip[ss])) { in dissect()
409 rest = slow(m, sp, stp, ss, es); in dissect()
412 tail = slow(m, rest, stop, es, stopst); in dissect()
422 if (slow(m, sp, rest, ssub, esub) != NULL) { in dissect()
423 dp = dissect(m, sp, rest, ssub, esub); in dissect()
434 rest = slow(m, sp, stp, ss, es); in dissect()
437 tail = slow(m, rest, stop, es, stopst); in dissect()
449 sep = slow(m, ssp, rest, ssub, esub); in dissect()
461 assert(slow(m, ssp, sep, ssub, esub) == rest); in dissect()
462 dp = dissect(m, ssp, sep, ssub, esub); in dissect()
471 rest = slow(m, sp, stp, ss, es); in dissect()
474 tail = slow(m, rest, stop, es, stopst); in dissect()
482 esub = ss + OPND(m->g->strip[ss]) - 1; in dissect()
483 assert(OP(m->g->strip[esub]) == OOR1); in dissect()
485 if (slow(m, sp, rest, ssub, esub) == rest) in dissect()
488 assert(OP(m->g->strip[esub]) == OOR1); in dissect()
490 assert(OP(m->g->strip[esub]) == OOR2); in dissect()
492 esub += OPND(m->g->strip[esub]); in dissect()
493 if (OP(m->g->strip[esub]) == OOR2) in dissect()
496 assert(OP(m->g->strip[esub]) == O_CH); in dissect()
498 dp = dissect(m, sp, rest, ssub, esub); in dissect()
511 i = OPND(m->g->strip[ss]); in dissect()
512 assert(0 < i && i <= m->g->nsub); in dissect()
513 m->pmatch[i].rm_so = sp - m->offp; in dissect()
516 i = OPND(m->g->strip[ss]); in dissect()
517 assert(0 < i && i <= m->g->nsub); in dissect()
518 m->pmatch[i].rm_eo = sp - m->offp; in dissect()
536 backref(struct match *m, in backref() argument
562 switch (OP(s = m->g->strip[ss])) { in backref()
573 cs = &m->g->sets[OPND(s)]; in backref()
578 if ( (sp == m->beginp && !(m->eflags&REG_NOTBOL)) || in backref()
579 (sp < m->endp && *(sp-1) == '\n' && in backref()
580 (m->g->cflags&REG_NEWLINE)) ) in backref()
586 if ( (sp == m->endp && !(m->eflags&REG_NOTEOL)) || in backref()
587 (sp < m->endp && *sp == '\n' && in backref()
588 (m->g->cflags&REG_NEWLINE)) ) in backref()
594 if (( (sp == m->beginp && !(m->eflags&REG_NOTBOL)) || in backref()
595 (sp < m->endp && *(sp-1) == '\n' && in backref()
596 (m->g->cflags&REG_NEWLINE)) || in backref()
597 (sp > m->beginp && in backref()
599 (sp < m->endp && ISWORD(*sp)) ) in backref()
605 if (( (sp == m->endp && !(m->eflags&REG_NOTEOL)) || in backref()
606 (sp < m->endp && *sp == '\n' && in backref()
607 (m->g->cflags&REG_NEWLINE)) || in backref()
608 (sp < m->endp && !ISWORD(*sp)) ) && in backref()
609 (sp > m->beginp && ISWORD(*(sp-1))) ) in backref()
618 s = m->g->strip[ss]; in backref()
622 } while (OP(s = m->g->strip[ss]) != O_CH); in backref()
638 s = m->g->strip[ss]; in backref()
642 assert(0 < i && i <= m->g->nsub); in backref()
643 if (m->pmatch[i].rm_eo == -1) in backref()
645 assert(m->pmatch[i].rm_so != -1); in backref()
646 len = m->pmatch[i].rm_eo - m->pmatch[i].rm_so; in backref()
647 assert(stop - m->beginp >= len); in backref()
650 ssp = m->offp + m->pmatch[i].rm_so; in backref()
653 while (m->g->strip[ss] != (sop) SOP(O_BACK, i)) in backref()
655 return(backref(m, sp+len, stop, ss+1, stopst, lev)); in backref()
658 dp = backref(m, sp, stop, ss+1, stopst, lev); in backref()
661 return(backref(m, sp, stop, ss+OPND(s)+1, stopst, lev)); in backref()
664 assert(m->lastpos != NULL); in backref()
665 assert(lev+1 <= m->g->nplus); in backref()
666 m->lastpos[lev+1] = sp; in backref()
667 return(backref(m, sp, stop, ss+1, stopst, lev+1)); in backref()
670 if (sp == m->lastpos[lev]) /* last pass matched null */ in backref()
671 return(backref(m, sp, stop, ss+1, stopst, lev-1)); in backref()
673 m->lastpos[lev] = sp; in backref()
674 dp = backref(m, sp, stop, ss-OPND(s)+1, stopst, lev); in backref()
676 return(backref(m, sp, stop, ss+1, stopst, lev-1)); in backref()
683 assert(OP(m->g->strip[esub]) == OOR1); in backref()
685 dp = backref(m, sp, stop, ssub, esub, lev); in backref()
689 if (OP(m->g->strip[esub]) == O_CH) in backref()
692 assert(OP(m->g->strip[esub]) == OOR2); in backref()
694 esub += OPND(m->g->strip[esub]); in backref()
695 if (OP(m->g->strip[esub]) == OOR2) in backref()
698 assert(OP(m->g->strip[esub]) == O_CH); in backref()
703 assert(0 < i && i <= m->g->nsub); in backref()
704 offsave = m->pmatch[i].rm_so; in backref()
705 m->pmatch[i].rm_so = sp - m->offp; in backref()
706 dp = backref(m, sp, stop, ss+1, stopst, lev); in backref()
709 m->pmatch[i].rm_so = offsave; in backref()
714 assert(0 < i && i <= m->g->nsub); in backref()
715 offsave = m->pmatch[i].rm_eo; in backref()
716 m->pmatch[i].rm_eo = sp - m->offp; in backref()
717 dp = backref(m, sp, stop, ss+1, stopst, lev); in backref()
720 m->pmatch[i].rm_eo = offsave; in backref()
740 fast(struct match *m, in fast() argument
746 states st = m->st; in fast()
747 states fresh = m->fresh; in fast()
748 states tmp = m->tmp; in fast()
750 int c = (start == m->beginp) ? OUT : *(start-1); in fast()
758 st = step(m->g, startst, stopst, st, NOTHING, st); in fast()
765 c = (p == m->endp) ? OUT : *p; in fast()
772 if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) || in fast()
773 (lastc == OUT && !(m->eflags&REG_NOTBOL)) ) { in fast()
775 i = m->g->nbol; in fast()
777 if ( (c == '\n' && m->g->cflags&REG_NEWLINE) || in fast()
778 (c == OUT && !(m->eflags&REG_NOTEOL)) ) { in fast()
780 i += m->g->neol; in fast()
784 st = step(m->g, startst, stopst, st, flagch, st); in fast()
798 st = step(m->g, startst, stopst, st, flagch, st); in fast()
810 st = step(m->g, startst, stopst, tmp, c, st); in fast()
812 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); in fast()
817 m->coldp = coldp; in fast()
830 slow(struct match *m, in slow() argument
836 states st = m->st; in slow()
837 states empty = m->empty; in slow()
838 states tmp = m->tmp; in slow()
840 int c = (start == m->beginp) ? OUT : *(start-1); in slow()
850 st = step(m->g, startst, stopst, st, NOTHING, st); in slow()
855 c = (p == m->endp) ? OUT : *p; in slow()
860 if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) || in slow()
861 (lastc == OUT && !(m->eflags&REG_NOTBOL)) ) { in slow()
863 i = m->g->nbol; in slow()
865 if ( (c == '\n' && m->g->cflags&REG_NEWLINE) || in slow()
866 (c == OUT && !(m->eflags&REG_NOTEOL)) ) { in slow()
868 i += m->g->neol; in slow()
872 st = step(m->g, startst, stopst, st, flagch, st); in slow()
886 st = step(m->g, startst, stopst, st, flagch, st); in slow()
900 st = step(m->g, startst, stopst, tmp, c, st); in slow()
902 assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st)); in slow()
1046 print(struct match *m, in print() argument
1052 struct re_guts *g = m->g; in print()
1056 if (!(m->eflags&REG_TRACE)) in print()
1078 at(struct match *m, in at() argument
1085 if (!(m->eflags&REG_TRACE)) in at()