Lines Matching refs:env

248 _matchpush(Env_t* env, Rex_t* rex)  in _matchpush()  argument
260 env->error = REG_ESPACE; in _matchpush()
264 f->match = m = env->match + rex->re.group.number; in _matchpush()
280 pospush(Env_t* env, Rex_t* rex, unsigned char* p, int be) in pospush() argument
284 if (!(pos = vector(Pos_t, env->pos, env->pos->cur))) in pospush()
286 env->error = REG_ESPACE; in pospush()
292 env->pos->cur++; in pospush()
305 better(Env_t* env, Pos_t* os, Pos_t* ns, Pos_t* oend, Pos_t* nend, int level) in better() argument
312 if (env->error) in better()
316env->beg, oe->serial, oe->be);sfprintf(sfstdout, "\n %-*.*snew ", (level + 3) * 4, (level + 3) *… in better()
326 env->error = REG_PANIC; in better()
357 if (k = better(env, os + 1, ns + 1, oe, ne, level + 1)) in better()
383 _better(Env_t* env, Pos_t* os, Pos_t* ns, Pos_t* oend, Pos_t* nend, int level) in _better() argument
387 …(i = 0; i <= env->nsub; i++)showmatch(&env->best[i]);sfprintf(sfstdout, "\n new ");for (… in _better()
388 i = better(env, os, ns, oend, nend, 0); in _better()
402 parserep(Env_t* env, Rex_t* rex, Rex_t* cont, unsigned char* s, int n) in parserep() argument
408 …rexname(rex->re.group.expr.rex), rex->re.group.number, rex->lo, n, rex->hi, env->end - s, s)),(0)); in parserep()
411 if (env->stack && pospush(env, rex, s, END_ANY)) in parserep()
413 i = follow(env, rex, cont, s); in parserep()
414 if (env->stack) in parserep()
415 pospop(env); in parserep()
438 if (env->stack) in parserep()
440 if (matchpush(env, rex)) in parserep()
442 if (pospush(env, rex, s, BEG_ONE)) in parserep()
444env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so… in parserep()
446 r = parse(env, rex->re.group.expr.rex, &catcher, s); in parserep()
447 …erep parse %d %d `%-.*s'\n", __LINE__, debug_flag, rex->re.group.number, r, env->end - s, s)),(0)); in parserep()
448 if (env->stack) in parserep()
450 pospop(env); in parserep()
451 matchpop(env, rex); in parserep()
452env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so… in parserep()
474 if (env->stack && pospush(env, rex, s, END_ANY)) in parserep()
476 i = follow(env, rex, cont, s); in parserep()
477 if (env->stack) in parserep()
478 pospop(env); in parserep()
499 parsetrie(Env_t* env, Trie_node_t* x, Rex_t* rex, Rex_t* cont, unsigned char* s) in parsetrie() argument
508 if (s >= env->end) in parsetrie()
523 if (s >= env->end) in parsetrie()
536 switch (follow(env, rex, cont, s)) in parsetrie()
547 switch (parsetrie(env, x->son, rex, cont, s)) in parsetrie()
567 switch (follow(env, rex, cont, s)) in parsetrie()
797 parse(Env_t* env, Rex_t* rex, Rex_t* cont, unsigned char* s) in parse() argument
819 …, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LINE__, debug_flag, rexname(rex), env->end - s, s)),(0)); in parse()
823 if (env->stack) in parse()
825 if (matchpush(env, rex)) in parse()
827 if (pospush(env, rex, s, BEG_ALT)) in parse()
833 r = parse(env, rex->re.group.expr.binary.left, &catcher, s); in parse()
836 matchcopy(env, rex); in parse()
837 …((Pos_t*)env->pos->vec + env->pos->cur - 1)->serial = catcher.serial = rex->re.group.expr.binary.s… in parse()
838 n = parse(env, rex->re.group.expr.binary.right, &catcher, s); in parse()
842 pospop(env); in parse()
843 matchpop(env, rex); in parse()
847 if ((r = parse(env, rex->re.group.expr.binary.left, cont, s)) == NONE) in parse()
848 r = parse(env, rex->re.group.expr.binary.right, cont, s); in parse()
854 if (pospush(env, rex, s, END_ANY)) in parse()
856 r = follow(env, rex, rex->re.alt_catch.cont, s); in parse()
857 pospop(env); in parse()
860 o = &env->match[rex->lo]; in parse()
865 if (e > env->end) in parse()
867 t = env->beg + o->rm_so; in parse()
892 …if ((!(rex->flags & REG_NEWLINE) || s <= env->beg || *(s - 1) != '\n') && ((env->flags & REG_NOTBO… in parse()
896 if (LEADING(env, rex, s)) in parse()
899 if (n > env->end - s) in parse()
900 n = env->end - s; in parse()
914 switch (follow(env, rex, cont, s)) in parse()
935 switch (follow(env, rex, cont, s)) in parse()
952 if (LEADING(env, rex, s)) in parse()
955 if (n > env->end - s) in parse()
956 n = env->end - s; in parse()
961 e = env->end; in parse()
966 env->error = REG_ESPACE; in parse()
975 switch (follow(env, rex, cont, s)) in parse()
999 switch (follow(env, rex, cont, s)) in parse()
1023 return parse(env, rex->re.group.expr.binary.left, &catcher, s); in parse()
1036 if (!env->stack) in parse()
1038 n = s - env->beg; in parse()
1039 r = env->nsub; in parse()
1040env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so… in parse()
1041 if ((i = env->best[0].rm_eo) >= 0) in parse()
1053 if (n == i && better(env, in parse()
1054 (Pos_t*)env->bestpos->vec, in parse()
1055 (Pos_t*)env->pos->vec, in parse()
1056 (Pos_t*)env->bestpos->vec+env->bestpos->cur, in parse()
1057 (Pos_t*)env->pos->vec+env->pos->cur, in parse()
1061 env->best[0].rm_eo = n; in parse()
1062 memcpy(&env->best[1], &env->match[1], r * sizeof(regmatch_t)); in parse()
1063 n = env->pos->cur; in parse()
1064 if (!vector(Pos_t, env->bestpos, n)) in parse()
1066 env->error = REG_ESPACE; in parse()
1069 env->bestpos->cur = n; in parse()
1070 memcpy(env->bestpos->vec, env->pos->vec, n * sizeof(Pos_t)); in parse()
1071env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so… in parse()
1074 if (LEADING(env, rex, s)) in parse()
1077 if (n > env->end - s) in parse()
1078 n = env->end - s; in parse()
1095 switch (follow(env, rex, cont, s)) in parse()
1112 env->error = REG_ESPACE; in parse()
1115 e = env->end; in parse()
1119 switch (follow(env, rex, cont, s)) in parse()
1143 switch (follow(env, rex, cont, s)) in parse()
1156 e = env->end; in parse()
1161 switch (follow(env, rex, cont, s)) in parse()
1175 if ((!(rex->flags & REG_NEWLINE) || *s != '\n') && ((env->flags & REG_NOTEOL) || s < env->end)) in parse()
1179 …t,"AHA#%04d 0x%04x parse %s `%-.*s'\n", __LINE__, debug_flag, rexname(rex), env->end - s, s)),(0)); in parse()
1180 if (env->stack) in parse()
1183 env->match[rex->re.group.number].rm_so = s - env->beg; in parse()
1184 if (pospush(env, rex, s, BEG_SUB)) in parse()
1186 …catcher.re.group_catch.eo = rex->re.group.number ? &env->match[rex->re.group.number].rm_eo : (rego… in parse()
1192 r = parse(env, rex->re.group.expr.rex, &catcher, s); in parse()
1193 if (env->stack) in parse()
1195 pospop(env); in parse()
1197 env->match[rex->re.group.number].rm_so = -1; in parse()
1201 …\n", __LINE__, debug_flag, rexname(rex), rexname(rex->re.group_catch.cont), env->end - s, s)),(0)); in parse()
1202 if (env->stack) in parse()
1205 *rex->re.group_catch.eo = s - env->beg; in parse()
1206 if (pospush(env, rex, s, END_ANY)) in parse()
1209 r = follow(env, rex, rex->re.group_catch.cont, s); in parse()
1210 if (env->stack) in parse()
1212 pospop(env); in parse()
1224 return parse(env, rex->re.group.expr.rex, &catcher, s); in parse()
1226 return follow(env, rex, rex->re.rep_catch.cont, rex->re.rep_catch.beg); in parse()
1228 r = parse(env, rex->re.group.expr.rex, NiL, s); in parse()
1230 r = follow(env, rex, cont, s); in parse()
1235 if ((s - env->beg) < rex->re.group.size) in parse()
1241 catcher.re.behind_catch.end = e = env->end; in parse()
1244 for (t = s - rex->re.group.size; t >= env->beg; t--) in parse()
1246 env->end = s; in parse()
1247 r = parse(env, rex->re.group.expr.rex, &catcher, t); in parse()
1248 env->end = e; in parse()
1256 env->end = rex->re.behind_catch.end; in parse()
1257 return follow(env, rex, rex->re.behind_catch.cont, rex->re.behind_catch.beg); in parse()
1259 if ((s - env->beg) < rex->re.group.size) in parse()
1266 e = env->end; in parse()
1267 env->end = s; in parse()
1268 for (t = s - rex->re.group.size; t >= env->beg; t--) in parse()
1270 r = parse(env, rex->re.group.expr.rex, &catcher, t); in parse()
1274 env->end = e; in parse()
1277 r = follow(env, rex, cont, s); in parse()
1300 r = parse(env, q, &catcher, s); in parse()
1304 …else if (!rex->re.group.size || rex->re.group.size > 0 && env->match[rex->re.group.size].rm_so >= … in parse()
1315 return parse(env, q, &catcher, s); in parse()
1317 return follow(env, rex, cont, s); in parse()
1325 return parse(env, rex->re.cond_catch.next[1], &catcher, rex->re.cond_catch.beg); in parse()
1327 return follow(env, rex, rex->re.group_catch.cont, s); in parse()
1334 return parse(env, rex->re.group.expr.rex, &catcher, s); in parse()
1336 switch (r = follow(env, rex, rex->re.group_catch.cont, s)) in parse()
1351 e = env->end; in parse()
1365 if (env->stack) in parse()
1366 env->best[0].rm_so = t - s - n; in parse()
1367 switch (follow(env, rex, cont, t)) in parse()
1396 if (env->stack) in parse()
1397 env->best[0].rm_so = t - s - n; in parse()
1398 switch (follow(env, rex, cont, t)) in parse()
1416 if (LEADING(env, rex, s)) in parse()
1418 i = env->end - s; in parse()
1426 if (parse(env, rex->re.group.expr.rex, &catcher, s) == BAD) in parse()
1434 switch (follow(env, rex, cont, s + i)) in parse()
1460 if (s >= env->end) in parse()
1466 if (s >= env->end || !(s = nestmatch(s, env->end, rex->re.nest.type, c))) in parse()
1474 if (!(s = nestmatch(s, env->end, rex->re.nest.type, c))) in parse()
1476 …} while (s < env->end && !(rex->re.nest.type[*(s-1)] & (REX_NEST_delimiter|REX_NEST_separator|REX_… in parse()
1482 if (n > env->end - s) in parse()
1483 n = env->end - s; in parse()
1506 switch (follow(env, rex, cont, s)) in parse()
1523 env->error = REG_ESPACE; in parse()
1526 e = env->end; in parse()
1548 switch (follow(env, rex, cont, s)) in parse()
1579 switch (follow(env, rex, cont, s)) in parse()
1601 switch (follow(env, rex, cont, s)) in parse()
1618 e = env->end; in parse()
1629 switch (follow(env, rex, cont, s)) in parse()
1653 switch (follow(env, rex, cont, s)) in parse()
1671 if (env->stack && pospush(env, rex, s, BEG_REP)) in parse()
1673 r = parserep(env, rex, cont, s, 0); in parse()
1674 if (env->stack) in parse()
1675 pospop(env); in parse()
1678 …, debug_flag, rexname(rex), rex->re.rep_catch.n, s - rex->re.rep_catch.beg, env->end - s, s)),(0)); in parse()
1679 if (env->stack && pospush(env, rex, s, END_ANY)) in parse()
1688 …if (!env->stack || s != rex->re.rep_catch.ref->re.rep_catch.beg && !rex->re.rep_catch.ref->re.grou… in parse()
1690 else if (pospush(env, rex, s, END_ANY)) in parse()
1694 r = follow(env, rex, rex->re.rep_catch.cont, s); in parse()
1695 pospop(env); in parse()
1699 r = parserep(env, rex->re.rep_catch.ref, rex->re.rep_catch.cont, s, rex->re.rep_catch.n); in parse()
1700 if (env->stack) in parse()
1701 pospop(env); in parse()
1704 …LINE__, debug_flag, rexname(rex), rex->re.string.size, rex->re.string.base, env->end - s, s)),(0)); in parse()
1705 if (rex->re.string.size > (env->end - s)) in parse()
1733 … if (((s + rex->re.trie.min) > env->end) || !(x = rex->re.trie.root[rex->map ? rex->map[*s] : *s])) in parse()
1735 return parsetrie(env, x, rex, cont, s); in parse()
1738 …r = (*env->disc->re_execf)(env->regex, rex->re.exec.data, rex->re.exec.text, rex->re.exec.size, (c… in parse()
1740 if (e >= s && e <= env->end) in parse()
1749 env->error = r; in parse()
1754 if (!isword(*s) || s > env->beg && isword(*(s - 1))) in parse()
1758 if (isword(*s) || s > env->beg && !isword(*(s - 1))) in parse()
1762 if (s > env->beg && isword(*(s - 1)) == isword(*s)) in parse()
1766 if (s == env->beg || isword(*(s - 1)) != isword(*s)) in parse()
1770 if (s != env->beg) in parse()
1774 for (t = s; t < env->end && *t == '\n'; t++); in parse()
1775 if (t < env->end) in parse()
1779 if (s < env->end) in parse()
1830 list(Env_t* env, Rex_t* rex) in list() argument
1832 sfprintf(sfstderr, "AHA regex hard=%d stack=%p\n", env->hard, env->stack); in list()
1854 Env_t* env; in regnexec() local
1859 if (!p || !(env = p->env)) in regnexec()
1862 return fatal(env->disc, REG_BADPAT, NiL); in regnexec()
1863 if (len < env->min) in regnexec()
1865 …DEBUG_TEST(0x0080,(sfprintf(sfstdout, "AHA#%04d REG_NOMATCH %d %d\n", __LINE__, len, env->min)),(0… in regnexec()
1868 env->regex = p; in regnexec()
1869 env->beg = (unsigned char*)s; in regnexec()
1870 env->end = env->beg + len; in regnexec()
1871 stknew(stkstd, &env->stk); in regnexec()
1872 env->flags &= ~REG_EXEC; in regnexec()
1873 env->flags |= (flags & REG_EXEC); in regnexec()
1875 if (env->stack = env->hard || !(env->flags & REG_NOSUB) && nmatch) in regnexec()
1877 n = env->nsub; in regnexec()
1878 if (!(env->match = (regmatch_t*)stkpush(stkstd, 2 * (n + 1) * sizeof(regmatch_t))) || in regnexec()
1879 !env->pos && !(env->pos = vecopen(16, sizeof(Pos_t))) || in regnexec()
1880 !env->bestpos && !(env->bestpos = vecopen(16, sizeof(Pos_t)))) in regnexec()
1885 env->pos->cur = env->bestpos->cur = 0; in regnexec()
1886 env->best = &env->match[n + 1]; in regnexec()
1887 env->best[0].rm_so = 0; in regnexec()
1888 env->best[0].rm_eo = -1; in regnexec()
1890 env->match[i] = state.nomatch; in regnexec()
1894 DEBUG_TEST(0x1000,(list(env,env->rex)),(0)); in regnexec()
1896 if ((e = env->rex)->type == REX_BM) in regnexec()
1936 if (env->stack) in regnexec()
1937 env->best[0].rm_so += i; in regnexec()
1947 if ((i = parse(env, e->next, &env->done, buf + index)) != NONE) in regnexec()
1949 if (env->stack) in regnexec()
1950 env->best[0].rm_so = index; in regnexec()
1951 n = env->nsub; in regnexec()
1965 n = env->nsub; in regnexec()
1968 j = env->once || (flags & REG_LEFT); in regnexec()
1970 …while ((i = parse(env, e, &env->done, (unsigned char*)s)) == NONE || advance && !env->best[0].rm_e… in regnexec()
1976 if ((unsigned char*)s > env->end - env->min) in regnexec()
1978 if (env->stack) in regnexec()
1979 env->best[0].rm_so += i; in regnexec()
1981 if ((flags & REG_LEFT) && env->stack && env->best[0].rm_so) in regnexec()
1984 if (k = env->error) in regnexec()
1988 k = env->error = REG_NOMATCH; in regnexec()
1991 if (!(env->flags & REG_NOSUB)) in regnexec()
1993 k = (env->flags & (REG_SHELL|REG_AUGMENTED)) == (REG_SHELL|REG_AUGMENTED); in regnexec()
2000 match[m = j] = env->best[i]; in regnexec()
2012 stkold(stkstd, &env->stk); in regnexec()
2013 env->stk.base = 0; in regnexec()
2015 fatal(p->env->disc, k, NiL); in regnexec()
2022 Env_t* env; in regfree() local
2024 if (p && (env = p->env)) in regfree()
2027 if (env->sub) in regfree()
2033 p->env = 0; in regfree()
2034 if (--env->refs <= 0 && !(env->disc->re_flags & REG_NOFREE)) in regfree()
2036 drop(env->disc, env->rex); in regfree()
2037 if (env->pos) in regfree()
2038 vecclose(env->pos); in regfree()
2039 if (env->bestpos) in regfree()
2040 vecclose(env->bestpos); in regfree()
2041 if (env->stk.base) in regfree()
2042 stkold(stkstd, &env->stk); in regfree()
2043 alloc(env->disc, env, 0); in regfree()