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