Lines Matching refs:env

145 node(Cenv_t* env, int type, int lo, int hi, size_t extra)  in node()  argument
150 if (e = (Rex_t*)alloc(env->disc, 0, sizeof(Rex_t) + extra)) in node()
157 e->flags = env->flags; in node()
158 e->map = (e->flags & REG_ICASE) ? env->MAP : env->map; in node()
159 e->explicit = env->explicit; in node()
271 serialize(Cenv_t* env, Rex_t* e, int n) in serialize() argument
281 n = serialize(env, e->re.group.expr.binary.left, n); in serialize()
284 n = serialize(env, e->re.group.expr.binary.right, n); in serialize()
287 n = serialize(env, e->re.group.expr.binary.left, n); in serialize()
288 n = serialize(env, e->re.group.expr.binary.right, n); in serialize()
298 n = serialize(env, e->re.group.expr.rex, n); in serialize()
310 cat(Cenv_t* env, Rex_t* e, Rex_t* f) in cat() argument
316 drop(env->disc, e); in cat()
321 drop(env->disc, e); in cat()
328 drop(env->disc, f); in cat()
350 drop(env->disc, f); in cat()
364 stats(register Cenv_t* env, register Rex_t* e) in stats() argument
386 x = env->stats.x; in stats()
387 l = env->stats.l; in stats()
388 y = env->stats.y; in stats()
389 k = env->stats.k; in stats()
390 t = env->stats.t; in stats()
391 if (++env->stats.a <= 0) in stats()
393 cm = env->stats.m; in stats()
394 env->stats.m = 0; in stats()
395 cn = env->stats.n; in stats()
396 env->stats.n = 0; in stats()
397 if (stats(env, e->re.group.expr.binary.left)) in stats()
399 m = env->stats.m; in stats()
400 env->stats.m = 0; in stats()
401 n = env->stats.n; in stats()
402 env->stats.n = 0; in stats()
403 if (e->re.group.expr.binary.right && stats(env, e->re.group.expr.binary.right)) in stats()
405 if (env->stats.m > m) in stats()
406 env->stats.m = m; in stats()
408 m = env->stats.m; in stats()
409 if ((env->stats.m += cm) < m) in stats()
411 if (env->stats.n < n) in stats()
412 env->stats.n = n; in stats()
414 n = env->stats.n; in stats()
415 if ((env->stats.n += cn) < n) in stats()
417 env->stats.x = x; in stats()
418 env->stats.l = l; in stats()
419 env->stats.y = y; in stats()
420 env->stats.k = k; in stats()
421 env->stats.t = t; in stats()
424 if (++env->stats.b <= 0) in stats()
431 n = env->stats.m; in stats()
432 if ((env->stats.m += e->lo) < n) in stats()
436 n = env->stats.n; in stats()
437 if ((env->stats.n += e->hi) < n) in stats()
442 if (++env->stats.c <= 0) in stats()
444 if (++env->stats.s <= 0) in stats()
449 cm = env->stats.m; in stats()
450 env->stats.m = 0; in stats()
451 cn = env->stats.n; in stats()
452 env->stats.n = 0; in stats()
453 if (stats(env, e->re.group.expr.binary.left)) in stats()
455 nm = env->stats.m; in stats()
456 env->stats.m = 0; in stats()
457 nn = env->stats.n; in stats()
458 env->stats.n = 0; in stats()
459 if (stats(env, e->re.group.expr.binary.right)) in stats()
461 if (env->stats.m < nm) in stats()
462 env->stats.m = nm; in stats()
464 nm = env->stats.m; in stats()
465 if ((env->stats.m += cm) < nm) in stats()
467 if (env->stats.n < nn) in stats()
468 env->stats.n = nn; in stats()
470 nn = env->stats.n; in stats()
471 if ((env->stats.n += cn) < nn) in stats()
475 env->stats.e = 1; in stats()
478 if (e->re.group.number && ++env->stats.p <= 0 || !e->re.group.number && ++env->stats.u <= 0) in stats()
480 if (stats(env, e->re.group.expr.rex)) in stats()
487 m = env->stats.m; in stats()
488 n = env->stats.n; in stats()
489 x = env->stats.x; in stats()
490 y = env->stats.y; in stats()
491 if (stats(env, e->re.group.expr.rex)) in stats()
493 env->stats.m = m; in stats()
494 env->stats.n = n; in stats()
495 env->stats.x = x; in stats()
496 env->stats.y = y; in stats()
501 if (++env->stats.u <= 0) in stats()
507 if (++env->stats.u <= 0) in stats()
509 m = env->stats.m; in stats()
510 n = env->stats.n; in stats()
511 x = env->stats.x; in stats()
512 y = env->stats.y; in stats()
513 if (e->re.group.size > 0 && ++env->stats.b <= 0) in stats()
515 if (e->re.group.expr.binary.left && stats(env, e->re.group.expr.binary.left)) in stats()
519 if (q->re.group.expr.binary.left && stats(env, q->re.group.expr.binary.left)) in stats()
521 if (q->re.group.expr.binary.right && stats(env, q->re.group.expr.binary.right)) in stats()
524 env->stats.m = m; in stats()
525 env->stats.n = n; in stats()
526 env->stats.x = x; in stats()
527 env->stats.y = y; in stats()
530 if (++env->stats.u <= 0) in stats()
532 m = env->stats.m; in stats()
533 n = env->stats.n; in stats()
534 x = env->stats.x; in stats()
535 y = env->stats.y; in stats()
536 if (stats(env, e->re.group.expr.rex)) in stats()
538 env->stats.m = m; in stats()
539 env->stats.n = n; in stats()
540 env->stats.x = x; in stats()
541 env->stats.y = y; in stats()
544 env->stats.i++; in stats()
545 x = env->stats.x; in stats()
546 l = env->stats.l; in stats()
547 y = env->stats.y; in stats()
548 k = env->stats.k; in stats()
549 t = env->stats.t; in stats()
550 cm = env->stats.m; in stats()
551 env->stats.m = 0; in stats()
552 if (stats(env, e->re.group.expr.rex)) in stats()
554 env->stats.m = !env->stats.m; in stats()
555 if ((env->stats.m += cm) < cm) in stats()
557 env->stats.x = x; in stats()
558 env->stats.l = l; in stats()
559 env->stats.y = y; in stats()
560 env->stats.k = k; in stats()
561 env->stats.t = t; in stats()
564 x = env->stats.x; in stats()
565 l = env->stats.l; in stats()
566 y = env->stats.y; in stats()
567 k = env->stats.k; in stats()
568 t = env->stats.t; in stats()
569 if (++env->stats.c <= 0) in stats()
571 b = env->stats.b; in stats()
572 c = env->stats.c; in stats()
573 cm = env->stats.m; in stats()
574 env->stats.m = 0; in stats()
575 if (stats(env, e->re.group.expr.rex)) in stats()
577 if (env->stats.m == 1 && b == env->stats.b && c == env->stats.c && ++env->stats.s <= 0) in stats()
581 env->stats.x = x; in stats()
582 env->stats.l = l; in stats()
583 env->stats.y = y; in stats()
584 env->stats.k = k; in stats()
585 env->stats.t = t; in stats()
586 env->stats.m = cm; in stats()
590 m = env->stats.m; in stats()
591 if ((env->stats.m *= e->lo) > 0 && env->stats.m < m) in stats()
593 m = env->stats.m; in stats()
594 if ((env->stats.m += cm) < m) in stats()
596 if (env->stats.x != x) in stats()
597 env->stats.l = cm; in stats()
598 if (env->stats.y != y) in stats()
599 env->stats.k = cm; in stats()
605 cm = env->stats.m; in stats()
606 if ((env->stats.m += e->re.string.size) < cm) in stats()
608 cn = env->stats.n; in stats()
609 if ((env->stats.n += e->re.string.size) < cn) in stats()
611 if (!env->stats.x || env->stats.x->re.string.size < e->re.string.size) in stats()
613 env->stats.x = e; in stats()
614 env->stats.l = cm; in stats()
619 if (++env->stats.s <= 0) in stats()
621 cm = env->stats.m; in stats()
622 if ((env->stats.m += e->re.trie.min) < cm) in stats()
624 cn = env->stats.n; in stats()
625 if ((env->stats.n += e->re.trie.max) < cn) in stats()
627 env->stats.t++; in stats()
628 if (!env->stats.y || env->stats.y->re.trie.min < e->re.trie.min) in stats()
630 env->stats.y = e; in stats()
631 env->stats.k = cm; in stats()
642 magic(register Cenv_t* env, register int c, int escaped) in magic() argument
647 int e = env->error; in magic()
648 int l = env->token.len; in magic()
654 c = mp[env->type+escaped]; in magic()
657 sp = (char*)env->cursor + env->token.len; in magic()
667 env->error = REG_BADBR; in magic()
674 if (env->type < SRE || *sp != ',') in magic()
676 env->error = *sp ? REG_BADBR : REG_EBRACE; in magic()
682 env->error = REG_BADBR; in magic()
685 env->token.min = n; in magic()
694 env->error = REG_BADBR; in magic()
701 else if (n < env->token.min) in magic()
703 env->error = REG_BADBR; in magic()
707 env->token.max = n; in magic()
711 env->error = REG_EBRACE; in magic()
716 env->error = REG_BADBR; in magic()
724 env->error = REG_BADBR; in magic()
732 env->error = REG_EBRACE; in magic()
737 env->error = REG_BADBR; in magic()
740 env->token.len = sp - (char*)env->cursor; in magic()
743 env->error = REG_EBRACE; in magic()
746 if (env->type < SRE && *sp == '?') in magic()
748 env->token.len++; in magic()
749 env->token.lex = 0; in magic()
757 env->token.len += ep - sp; in magic()
760 env->token.lex = c; in magic()
775 env->token.len += ep - sp; in magic()
781 if (env->type == SRE || c == T_BACK && !(env->flags & (REG_LENIENT|REG_REGEXP))) in magic()
783 env->error = REG_BADESC; in magic()
786 if ((env->flags & REG_MULTIREF) && isdigit(*sp)) in magic()
789 if (c > 0 && c <= env->parno && env->paren[c]) in magic()
793 env->token.len++; in magic()
799 …if (escaped == 1 && (env->flags & (REG_LENIENT|REG_REGEXP)) && (c = mp[env->type+escaped+2]) >= T_… in magic()
803 if (env->type >= SRE) in magic()
809 …if (env->type == KRE && *(env->cursor + env->token.len) == '-' && *(env->cursor + env->token.len +… in magic()
811 env->token.len++; in magic()
812 env->token.att = 1; in magic()
814 if (env->type == KRE && *(env->cursor + env->token.len) == '(') in magic()
816 env->token.len++; in magic()
822 env->token.lex = c; in magic()
825 env->token.lex = 0; in magic()
828 env->token.lex = c; in magic()
840 env->token.len = l; in magic()
846 c = (c > env->parno || !env->paren[c]) ? o : T_BACK + c; in magic()
848 else if (env->type == KRE && !env->parnest && (env->flags & REG_SHELL_GROUP)) in magic()
862 … (env->type >= SRE && !(env->flags & REG_SHELL_ESCAPED) || (env->flags & REG_ESCAPE) && (c == '[' … in magic()
866 env->error = REG_BADESC; in magic()
870 else if (escaped && !(env->flags & (REG_LENIENT|REG_REGEXP)) && c != ']') in magic()
872 env->error = REG_BADESC; in magic()
877 sp = (char*)env->cursor + env->token.len; in magic()
888 env->error = REG_EPAREN; in magic()
901 env->cursor = (unsigned char*)sp; in magic()
902 return token(env); in magic()
905 env->error = e; in magic()
906 else if (env->flags & (REG_LENIENT|REG_REGEXP)) in magic()
908 else if (escaped == 1 && !env->error) in magic()
912 env->error = REG_BADESC; in magic()
918 token(register Cenv_t* env) in token() argument
923 if (env->token.push) in token()
924 return env->token.lex; in token()
925 env->token.att = env->token.esc = 0; in token()
926 if ((env->token.len = MBSIZE(env->cursor)) > 1) in token()
927 return env->token.lex = C_MB; in token()
928 env->token.lex = 0; in token()
931 c = *env->cursor; in token()
932 if (c == 0 || c == env->delimiter || c == env->terminator) in token()
934 if (!(env->flags & REG_COMMENT)) in token()
940 c = *++env->cursor; in token()
941 if (c == 0 || c == env->delimiter) in token()
947 env->cursor++; in token()
949 if (c == '\n' && (env->flags & REG_MULTIPLE) && !env->delimiter) in token()
951 if (env->parnest) in token()
953 env->error = REG_EPAREN; in token()
956 env->parno = 0; in token()
957 env->pattern = env->cursor + 1; in token()
960 if (env->flags & REG_LITERAL) in token()
962 if (posixkludge = env->posixkludge) in token()
964 env->posixkludge = 0; in token()
970 if (env->flags & REG_SHELL_ESCAPED) in token()
972 if (!(c = *(env->cursor + 1)) || c == env->terminator) in token()
974 if (env->flags & (REG_LENIENT|REG_REGEXP)) in token()
978 env->token.esc = env->token.len; in token()
979 env->token.len += MBSIZE(env->cursor + 1); in token()
984 env->error = REG_EESCAPE; in token()
987 env->token.esc = env->token.len; in token()
988 env->token.len += MBSIZE(env->cursor + 1); in token()
989 if (env->delimiter && c == 'n') in token()
991 else if (c == env->delimiter) in token()
992 return magic(env, c, 0); in token()
993 else if (c == '(' && env->type == BRE) in token()
994 env->posixkludge = 1; in token()
995 else if (c == ')' && env->type == BRE && env->parnest <= 0) in token()
997 env->error = REG_EPAREN; in token()
1000 else if (isspace(c) && (env->flags & REG_COMMENT)) in token()
1002 return magic(env, c, 1); in token()
1006env->type == BRE && (*(env->cursor + 1) == 0 || *(env->cursor + 1) == env->delimiter || *(env->cur… in token()
1011 if (env->type == BRE && (env->cursor == env->pattern || posixkludge == 1)) in token()
1013 env->posixkludge = 2; in token()
1019 if (env->type != BRE && env->parnest <= 0) in token()
1022 else if (c == '/' && env->explicit == env->mappedslash) in token()
1024 while (*(env->cursor + env->token.len) == c) in token()
1025 env->token.len++; in token()
1028 return magic(env, c, 0); in token()
1169 bra(Cenv_t* env) in bra() argument
1192 if (!(e = node(env, REX_CLASS, 1, 1, sizeof(Set_t)))) in bra()
1195 if (*env->cursor == '^' || env->type >= SRE && *env->cursor == '!') in bra()
1197 env->cursor++; in bra()
1202 first = env->cursor; in bra()
1204env->cursor == 0 || *(env->cursor + 1) == 0 || *env->cursor == env->terminator || *(env->cursor + … in bra()
1206 begin = env->cursor + MBSIZE(env->cursor); in bra()
1215 …if (!(c = *env->cursor) || c == env->terminator || c == env->delimiter && (env->flags & REG_ESCAPE… in bra()
1217 env->cursor += (w = MBSIZE(env->cursor)); in bra()
1218 …if (c == '\\' && ((env->flags & REG_CLASS_ESCAPE) || *env->cursor == env->delimiter && (env->flags… in bra()
1220 if (*env->cursor) in bra()
1222 if (*env->cursor == 'n') in bra()
1224 env->cursor++; in bra()
1227 else if (env->type < SRE || !(env->flags & REG_SHELL_ESCAPED)) in bra()
1229 env->token.len = 1; in bra()
1230 w = magic(env, *env->cursor, 2); in bra()
1231 if (env->token.len > 1 || w != T_BAD) in bra()
1233 if (env->token.len == 1 && (f = classfun(w))) in bra()
1237 if (env->type < SRE && !(env->flags & (REG_LENIENT|REG_REGEXP))) in bra()
1241 env->cursor++; in bra()
1249 if (env->token.len > 1 || w >= 0 && w < T_META) in bra()
1254 if (env->type < SRE && !(env->flags & (REG_LENIENT|REG_REGEXP)) && !mbwide()) in bra()
1258 env->cursor += env->token.len; in bra()
1266 if (env->cursor == begin) in bra()
1286 if (!inrange && env->cursor != begin && *env->cursor != ']') in bra()
1288 if (env->type < SRE && !(env->flags & (REG_LENIENT|REG_REGEXP))) in bra()
1301 switch (*env->cursor) in bra()
1306 if (env->flags & REG_REGEXP) in bra()
1313 if (!(f = regclass((char*)env->cursor, (char**)&env->cursor))) in bra()
1315 if (env->cursor == start && (c = *(env->cursor + 1))) in bra()
1317 s = start = env->cursor + 1; in bra()
1337 env->cursor = s + 3; in bra()
1338 drop(env->disc, e); in bra()
1339 return node(env, i, 0, 0, 0); in bra()
1344 env->error = REG_ECTYPE; in bra()
1355 if (env->flags & REG_REGEXP) in bra()
1364 … if ((c = regcollate((char*)env->cursor, (char**)&env->cursor, (char*)buf, sizeof(buf), NiL)) < 0) in bra()
1376 if (env->flags & REG_REGEXP) in bra()
1378 … if ((c = regcollate((char*)env->cursor, (char**)&env->cursor, (char*)buf, sizeof(buf), NiL)) < 0) in bra()
1387 …if (*env->cursor == env->terminator || *env->cursor == env->delimiter && (env->flags & REG_ESCAPE)) in bra()
1400 inrange = env->type >= SRE || (env->flags & (REG_LENIENT|REG_REGEXP)); in bra()
1403 else if (env->type >= SRE) in bra()
1410 else if (!(env->flags & (REG_LENIENT|REG_REGEXP))) in bra()
1464 drop(env->disc, e); in bra()
1470 drop(env->disc, e); in bra()
1471 if (ic = env->flags & REG_ICASE) in bra()
1473 if (!(e = node(env, REX_COLL_CLASS, 1, 1, (elements + 3) * sizeof(Celt_t)))) in bra()
1478 env->cursor = first; in bra()
1482 …if ((c = *env->cursor) == 0 || c == env->terminator || (env->flags & REG_ESCAPE) && c == env->deli… in bra()
1484 pp = env->cursor; in bra()
1485 env->cursor += (w = MBSIZE(env->cursor)); in bra()
1486 …if (c == '\\' && ((env->flags & REG_CLASS_ESCAPE) || *env->cursor == env->delimiter && (env->flags… in bra()
1488 if (*env->cursor) in bra()
1490 if (*env->cursor == 'n') in bra()
1492 pp = env->cursor++; in bra()
1495 else if (env->type < SRE || !(env->flags & REG_SHELL_ESCAPED)) in bra()
1497 env->token.len = 1; in bra()
1498 w = magic(env, *env->cursor, 2); in bra()
1499 if (env->token.len > 1 || w != T_BAD) in bra()
1501 if (env->token.len == 1 && (f = classfun(w))) in bra()
1505 if (env->type < SRE && !(env->flags & (REG_LENIENT|REG_REGEXP))) in bra()
1509 env->cursor++; in bra()
1515 if (env->token.len > 1 || w >= 0 && w < T_META) in bra()
1520 env->cursor += env->token.len; in bra()
1528 if (env->cursor == begin) in bra()
1545 if (!inrange && env->cursor != begin && *env->cursor != ']') in bra()
1547 if (env->type < SRE && !(env->flags & (REG_LENIENT|REG_REGEXP))) in bra()
1559 switch (*env->cursor) in bra()
1564 if (env->flags & REG_REGEXP) in bra()
1568 if (!(f = regclass((char*)env->cursor, (char**)&env->cursor))) in bra()
1570 …if (env->cursor == start && (c = *(env->cursor + 1)) && *(env->cursor + 2) == ':' && *(env->cursor… in bra()
1586 env->cursor += 5; in bra()
1587 drop(env->disc, e); in bra()
1588 return node(env, i, 0, 0, 0); in bra()
1591 env->error = REG_ECTYPE; in bra()
1600 if (env->flags & REG_REGEXP) in bra()
1607 rp = env->cursor + 1; in bra()
1608 … if ((rw = regcollate((char*)env->cursor, (char**)&env->cursor, (char*)pp, COLL_KEY_MAX, &wc)) < 0) in bra()
1676 if (env->flags & REG_REGEXP) in bra()
1679 … if ((w = regcollate((char*)env->cursor, (char**)&env->cursor, (char*)pp, COLL_KEY_MAX, NiL)) < 0) in bra()
1685 …if (*env->cursor == env->terminator || *env->cursor == env->delimiter && (env->flags & REG_ESCAPE)) in bra()
1696 if (env->type < SRE && !(env->flags & (REG_LENIENT|REG_REGEXP))) in bra()
1703 inrange = env->type >= SRE || (env->flags & (REG_LENIENT|REG_REGEXP)); in bra()
1720 if (env->flags & REG_ICASE) in bra()
1736 if (env->explicit >= 0) in bra()
1737 setclr(e->re.charclass, env->explicit); in bra()
1741 env->error = REG_ECOLLATE; in bra()
1744 env->error = REG_ERANGE; in bra()
1746 drop(env->disc, e); in bra()
1747 if (!env->error) in bra()
1748 env->error = REG_EBRACK; in bra()
1753 ccl(Cenv_t* env, int type) in ccl() argument
1762 env->error = REG_BADESC; in ccl()
1767 if (!(e = node(env, REX_CLASS, 1, 1, sizeof(Set_t)))) in ccl()
1772 if (env->explicit >= 0) in ccl()
1773 setclr(e->re.charclass, env->explicit); in ccl()
1777 if (!(e = node(env, REX_COLL_CLASS, 1, 1, 2 * sizeof(Celt_t)))) in ccl()
1791 rep(Cenv_t* env, Rex_t* e, int number, int last) in rep() argument
1800 switch (token(env)) in rep()
1803 eat(env); in rep()
1804 if (!(f = node(env, REX_NEG, m, n, 0))) in rep()
1806 drop(env->disc, e); in rep()
1812 eat(env); in rep()
1816 eat(env); in rep()
1819 eat(env); in rep()
1823 eat(env); in rep()
1824 m = env->token.min; in rep()
1825 n = env->token.max; in rep()
1830 if (env->token.att) in rep()
1832 else if (env->type < SRE) in rep()
1833 switch (token(env)) in rep()
1836 eat(env); in rep()
1837 minimal = !(env->flags & REG_MINIMAL); in rep()
1840 eat(env); in rep()
1841 minimal = !!(env->flags & REG_MINIMAL); in rep()
1865 env->error = REG_BADRPT; in rep()
1866 drop(env->disc, e); in rep()
1875 if (!(f = node(env, REX_REP, m, n, 0))) in rep()
1877 drop(env->disc, e); in rep()
1908 trienode(Cenv_t* env, int c) in trienode() argument
1912 if (t = (Trie_node_t*)alloc(env->disc, 0, sizeof(Trie_node_t))) in trienode()
1921 insert(Cenv_t* env, Rex_t* f, Rex_t* g) in insert() argument
1942 if (!(t = g->re.trie.root[*s]) && !(t = g->re.trie.root[*s] = trienode(env, *s))) in insert()
1950 if (!t->son && !(t->son = trienode(env, *s))) in insert()
1957 if (!t->sib && !(t->sib = trienode(env, *s))) in insert()
1977 trie(Cenv_t* env, Rex_t* e, Rex_t* f) in trie() argument
1985 if (!(g = node(env, REX_TRIE, 0, 0, (UCHAR_MAX + 1) * sizeof(Trie_node_t*)))) in trie()
1988 if (insert(env, f, g)) in trie()
1990 drop(env->disc, f); in trie()
1996 if (insert(env, e, g)) in trie()
1998 drop(env->disc, e); in trie()
2002 drop(env->disc, g); in trie()
2009 chr(register Cenv_t* env, int* escaped) in chr() argument
2015 if (!(c = *env->cursor)) in chr()
2017 env->cursor++; in chr()
2020 if (env->flags & REG_SHELL_ESCAPED) in chr()
2022 if (!(c = *(env->cursor + 1)) || c == env->terminator) in chr()
2024 if (env->flags & (REG_LENIENT|REG_REGEXP)) in chr()
2026 env->error = REG_EESCAPE; in chr()
2029 p = env->cursor; in chr()
2030 c = chresc((char*)env->cursor - 1, (char**)&env->cursor); in chr()
2031 *escaped = env->cursor - p; in chr()
2041 grp(Cenv_t* env, int parno) in grp() argument
2055 g = env->flags; in grp()
2056 beg = env->pattern == env->cursor - env->token.len; in grp()
2057 if (!(c = env->token.lex) && (c = *env->cursor)) in grp()
2058 env->cursor++; in grp()
2059 env->token.len = 0; in grp()
2060 env->parnest++; in grp()
2094 env->token.push = 1; in grp()
2100 if (!(env->flags & REG_LITERAL)) in grp()
2102 env->error = REG_BADRPT; in grp()
2111 eat(env); in grp()
2112 if (token(env) == T_CLOSE) in grp()
2123 env->flags |= (REG_LEFT|REG_RIGHT); in grp()
2125 env->flags &= ~(REG_LEFT|REG_RIGHT); in grp()
2129 env->flags &= ~REG_MINIMAL; in grp()
2131 env->flags |= REG_MINIMAL; in grp()
2135 env->flags |= REG_ICASE; in grp()
2137 env->flags &= ~REG_ICASE; in grp()
2141 env->flags |= REG_LEFT; in grp()
2143 env->flags &= ~REG_LEFT; in grp()
2147 env->flags |= REG_NEWLINE; in grp()
2149 env->flags &= ~REG_NEWLINE; in grp()
2150 env->explicit = (env->flags & (REG_NEWLINE|REG_SPAN)) == REG_NEWLINE ? env->mappednewline : -1; in grp()
2154 env->flags &= ~REG_LENIENT; in grp()
2156 env->flags |= REG_LENIENT; in grp()
2160 env->flags |= REG_RIGHT; in grp()
2162 env->flags &= ~REG_RIGHT; in grp()
2166 env->flags |= REG_SPAN; in grp()
2168 env->flags &= ~REG_SPAN; in grp()
2169 env->explicit = (env->flags & (REG_NEWLINE|REG_SPAN)) == REG_NEWLINE ? env->mappednewline : -1; in grp()
2173 env->flags |= REG_COMMENT; in grp()
2175 env->flags &= ~REG_COMMENT; in grp()
2178 if (typ >= 0 || env->type == ERE && (env->flags & REG_CLASS_ESCAPE)) in grp()
2182 env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_REGEXP|REG_SHELL|REG_LEFT|REG_RIGHT); in grp()
2183 env->flags |= REG_AUGMENTED|REG_EXTENDED; in grp()
2188 env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_REGEXP|REG_SHELL|REG_LEFT|REG_RIGHT); in grp()
2192 env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_REGEXP|REG_SHELL|REG_LEFT|REG_RIGHT); in grp()
2193 env->flags |= REG_EXTENDED; in grp()
2198 env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_REGEXP|REG_SHELL|REG_LEFT|REG_RIGHT); in grp()
2199 env->flags |= REG_LITERAL; in grp()
2203 env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_REGEXP|REG_SHELL|REG_LEFT|REG_RIGHT); in grp()
2204 env->flags |= REG_AUGMENTED|REG_SHELL|REG_LEFT|REG_RIGHT; in grp()
2217 env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_REGEXP|REG_SHELL|REG_LEFT|REG_RIGHT); in grp()
2218 env->flags |= REG_EXTENDED|REG_CLASS_ESCAPE; in grp()
2222 env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_REGEXP|REG_SHELL|REG_LEFT|REG_RIGHT); in grp()
2223 env->flags |= REG_SHELL|REG_LEFT|REG_RIGHT; in grp()
2227 if (typ >= 0 || env->type == ERE && (env->flags & REG_CLASS_ESCAPE)) in grp()
2230 env->flags |= REG_MINIMAL; in grp()
2232 env->flags &= ~REG_MINIMAL; in grp()
2236 env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_REGEXP|REG_SHELL|REG_LEFT|REG_RIGHT); in grp()
2237 env->flags |= REG_REGEXP; in grp()
2241 env->error = REG_BADRPT; in grp()
2244 eat(env); in grp()
2245 c = token(env); in grp()
2259 switch (token(env)) in grp()
2269 env->error = REG_BADRPT; in grp()
2272 eat(env); in grp()
2279 e = node(env, REX_NEST, 0, 0, (UCHAR_MAX + 1) * sizeof(unsigned short)); in grp()
2280 e->re.nest.primary = isalnum(*env->cursor) ? -1 : *env->cursor; in grp()
2284 switch (i = chr(env, &esc)) in grp()
2289 env->cursor -= esc + 1; in grp()
2290 env->error = REG_EPAREN; in grp()
2296 if ((i = chr(env, &esc)) < 0) in grp()
2309 switch (i = chr(env, &esc)) in grp()
2322 if ((i = chr(env, &esc)) < 0) in grp()
2352 …if ((x = chr(env, &esc)) < 0 || (e->re.nest.type[x] & (REX_NEST_close|REX_NEST_escape|REX_NEST_del… in grp()
2367 env->parnest--; in grp()
2371 parno = ++env->parno; in grp()
2372 if (!(f = node(env, REX_GROUP, 0, 0, 0))) in grp()
2374 drop(env->disc, e); in grp()
2377 if (parno < elementsof(env->paren)) in grp()
2378 env->paren[parno] = f; in grp()
2387 if (isdigit(*env->cursor)) in grp()
2394 env->error = REG_BADRPT; in grp()
2397 c = c * 10 + (*env->cursor++ - '0'); in grp()
2398 } while (isdigit(*env->cursor)); in grp()
2399 if (*env->cursor++ != ')') in grp()
2401 env->error = REG_BADRPT; in grp()
2404 if (c && env->type >= SRE) in grp()
2406 if (!c || c > env->parno || !env->paren[c]) in grp()
2408 if (!(env->flags & (REG_LENIENT|REG_REGEXP))) in grp()
2410 env->error = REG_ESUBREG; in grp()
2419 if (env->type < SRE && *env->cursor++ != '?') in grp()
2421 env->error = REG_BADRPT; in grp()
2424 if (!(f = grp(env, parno + 1)) && env->error) in grp()
2427 if (!(e = node(env, REX_GROUP_COND, 0, 0, 0))) in grp()
2429 drop(env->disc, f); in grp()
2434 if (!(e->re.group.expr.binary.right = alt(env, parno, 1))) in grp()
2436 drop(env->disc, e); in grp()
2439 if (token(env) != T_CLOSE) in grp()
2441 env->error = REG_EPAREN; in grp()
2444 eat(env); in grp()
2445 env->parnest--; in grp()
2446 return rep(env, e, parno, parno); in grp()
2448 p = env->cursor; in grp()
2450 while (c = *env->cursor) in grp()
2452 if (c == '\\' && *(env->cursor + 1)) in grp()
2453 env->cursor++; in grp()
2458 else if (c == env->delimiter || c == env->terminator) in grp()
2460 env->cursor++; in grp()
2464 env->error = REG_EBRACE; in grp()
2467 if (*++env->cursor != ')') in grp()
2469 env->error = REG_EPAREN; in grp()
2472 env->cursor++; in grp()
2473 env->parnest--; in grp()
2474 if (env->disc->re_version < REG_VERSION_EXEC) in grp()
2476 env->error = REG_BADRPT; in grp()
2479 if (!env->disc->re_execf) in grp()
2481 if (!(e = node(env, REX_EXEC, 0, 0, 0))) in grp()
2484 e->re.exec.size = env->cursor - p - 2; in grp()
2485 if (!env->disc->re_compf) in grp()
2488 … e->re.exec.data = (*env->disc->re_compf)(env->regex, e->re.exec.text, e->re.exec.size, env->disc); in grp()
2493 while (isdigit(*env->cursor)) in grp()
2497 env->error = REG_ESUBREG; in grp()
2500 c = c * 10 + *env->cursor++ - '0'; in grp()
2502 if (*env->cursor == ')') in grp()
2504 env->cursor++; in grp()
2505 env->parnest--; in grp()
2506 env->token.len = 1; in grp()
2507 if (c > env->parno || !env->paren[c]) in grp()
2509 env->error = REG_ESUBREG; in grp()
2512 env->paren[c]->re.group.back = 1; in grp()
2513 return rep(env, node(env, REX_BACK, c, 0, 0), 0, 0); in grp()
2517 env->error = REG_BADRPT; in grp()
2520 p = env->pattern; in grp()
2521 i = env->type; in grp()
2525 env->type = typ; in grp()
2526 if (!(e = alt(env, parno, 0))) in grp()
2528 env->flags = g; in grp()
2529 env->type = i; in grp()
2531 c = token(env); in grp()
2532 env->parnest--; in grp()
2533 if (c != T_CLOSE && (!(env->flags & REG_LITERAL) || c != ')')) in grp()
2535 env->error = REG_EPAREN; in grp()
2538 eat(env); in grp()
2540 env->pattern = env->cursor; in grp()
2544 env->type = typ; in grp()
2547 if (!(f = node(env, x, 0, 0, 0))) in grp()
2549 drop(env->disc, e); in grp()
2555 if (stats(env, e)) in grp()
2557 drop(env->disc, f); in grp()
2558 if (!env->error) in grp()
2559 env->error = REG_ECOUNT; in grp()
2562 f->re.group.size = env->stats.m; in grp()
2563 memset(&env->stats, 0, sizeof(env->stats)); in grp()
2569 f = rep(env, f, parno, env->parno); in grp()
2575 env->flags = g; in grp()
2576 env->pattern = p; in grp()
2577 env->type = i; in grp()
2582 seq(Cenv_t* env) in seq() argument
2603 while ((c = token(env)) < T_META && s < &buf[sizeof(buf) - env->token.len]) in seq()
2606 p = env->cursor; in seq()
2610 *s++ = (env->flags & REG_ICASE) ? toupper(c) : c; in seq()
2612 else if (c == C_ESC || (env->flags & REG_ICASE)) in seq()
2614 c = (c == C_ESC) ? env->token.lex : mbchar(p); in seq()
2615 if (env->flags & REG_ICASE) in seq()
2631 n = env->token.len - env->token.esc; in seq()
2634 eat(env); in seq()
2651 if (!(e = node(env, REX_STRING, 0, 0, i))) in seq()
2658 if (!(f = node(env, REX_ONECHAR, 1, 1, 0))) in seq()
2660 drop(env->disc, e); in seq()
2663 f->re.onechar = (env->flags & REG_ICASE) ? toupper(x) : x; in seq()
2667 if (!(f = node(env, REX_STRING, 0, 0, n))) in seq()
2672 if (!(f = rep(env, f, 0, 0)) || !(f = cat(env, f, seq(env)))) in seq()
2674 drop(env->disc, e); in seq()
2678 f = cat(env, e, f); in seq()
2682 if (!(e = node(env, REX_STRING, 0, 0, c))) in seq()
2686 return cat(env, e, seq(env)); in seq()
2690 eat(env); in seq()
2692 if (c > env->parno || !env->paren[c]) in seq()
2694 env->error = REG_ESUBREG; in seq()
2697 env->paren[c]->re.group.back = 1; in seq()
2698 e = rep(env, node(env, REX_BACK, c, 0, 0), 0, 0); in seq()
2707 return node(env, REX_NULL, 0, 0, 0); in seq()
2709 eat(env); in seq()
2710 e = rep(env, node(env, REX_END, 0, 0, 0), 0, 0); in seq()
2713 eat(env); in seq()
2714 if ((e = node(env, REX_BEG, 0, 0, 0)) && (env->flags & REG_EXTENDED)) in seq()
2715 e = rep(env, e, 0, 0); in seq()
2718 tok = env->token; in seq()
2719 eat(env); in seq()
2720 flags = env->flags; in seq()
2721 type = env->type; in seq()
2722 if (env->token.att) in seq()
2723 env->flags |= REG_MINIMAL; in seq()
2724 env->parnest++; in seq()
2725 if (env->type == KRE) in seq()
2726 ++env->parno; in seq()
2727 parno = ++env->parno; in seq()
2728 if (!(e = alt(env, parno + 1, 0))) in seq()
2730 if (e->type == REX_NULL && env->type == ERE && !(env->flags & (REG_NULL|REG_REGEXP))) in seq()
2732 drop(env->disc, e); in seq()
2733env->error = (*env->cursor == 0 || *env->cursor == env->delimiter || *env->cursor == env->terminat… in seq()
2736 if (token(env) != T_CLOSE) in seq()
2738 drop(env->disc, e); in seq()
2739 env->error = REG_EPAREN; in seq()
2742 env->parnest--; in seq()
2743 eat(env); in seq()
2744 if (!(f = node(env, REX_GROUP, 0, 0, 0))) in seq()
2746 drop(env->disc, e); in seq()
2749 if (parno < elementsof(env->paren)) in seq()
2750 env->paren[parno] = f; in seq()
2757 env->token = tok; in seq()
2759 if (!(e = rep(env, f, parno, env->parno))) in seq()
2761 if (env->type == KRE) in seq()
2763 if (!(f = node(env, REX_GROUP, 0, 0, 0))) in seq()
2765 drop(env->disc, e); in seq()
2768 if (--parno < elementsof(env->paren)) in seq()
2769 env->paren[parno] = f; in seq()
2775 env->flags = flags; in seq()
2776 env->type = type; in seq()
2779 p = env->cursor; in seq()
2780 eat(env); in seq()
2781 flags = env->flags; in seq()
2782 type = env->type; in seq()
2783 if (!(e = grp(env, env->parno + 1))) in seq()
2785 if (env->error) in seq()
2787 if (env->literal == env->pattern && env->literal == p) in seq()
2788 env->literal = env->cursor; in seq()
2791 env->flags = flags; in seq()
2792 env->type = type; in seq()
2795 eat(env); in seq()
2796 if (e = bra(env)) in seq()
2797 e = rep(env, e, 0, 0); in seq()
2805 eat(env); in seq()
2806 if (e = ccl(env, c)) in seq()
2807 e = rep(env, e, 0, 0); in seq()
2810 eat(env); in seq()
2811 e = rep(env, node(env, REX_WBEG, 0, 0, 0), 0, 0); in seq()
2814 eat(env); in seq()
2815 e = rep(env, node(env, REX_WEND, 0, 0, 0), 0, 0); in seq()
2818 eat(env); in seq()
2819 e = rep(env, node(env, REX_DOT, 1, 1, 0), 0, 0); in seq()
2822 eat(env); in seq()
2823 env->token.lex = T_STAR; in seq()
2824 env->token.push = 1; in seq()
2825 e = rep(env, node(env, REX_DOT, 1, 1, 0), 0, 0); in seq()
2828 eat(env); in seq()
2829 env->token.lex = T_PLUS; in seq()
2830 env->token.push = 1; in seq()
2831 if (e = node(env, REX_ONECHAR, 1, 1, 0)) in seq()
2834 e = rep(env, e, 0, 0); in seq()
2838 eat(env); in seq()
2839 e = rep(env, node(env, REX_WORD, 0, 0, 0), 0, 0); in seq()
2842 eat(env); in seq()
2843 e = rep(env, node(env, REX_WORD_NOT, 0, 0, 0), 0, 0); in seq()
2846 eat(env); in seq()
2847 e = rep(env, node(env, REX_BEG_STR, 0, 0, 0), 0, 0); in seq()
2850 eat(env); in seq()
2851 e = rep(env, node(env, REX_END_STR, 0, 0, 0), 0, 0); in seq()
2854 eat(env); in seq()
2855 e = rep(env, node(env, REX_FIN_STR, 0, 0, 0), 0, 0); in seq()
2858 env->error = REG_BADRPT; in seq()
2861 if (e && *env->cursor != 0 && *env->cursor != env->delimiter && *env->cursor != env->terminator) in seq()
2862 e = cat(env, e, seq(env)); in seq()
2868 con(Cenv_t* env) in con() argument
2874 if (!(e = seq(env)) || !(env->flags & REG_AUGMENTED) || token(env) != T_AND) in con()
2876 eat(env); in con()
2877 if (!(f = con(env))) in con()
2879 drop(env->disc, e); in con()
2882 if (!(g = node(env, REX_CONJ, 0, 0, 0))) in con()
2884 drop(env->disc, e); in con()
2885 drop(env->disc, f); in con()
2894 alt(Cenv_t* env, int number, int cond) in alt() argument
2900 if (!(e = con(env))) in alt()
2902 else if (token(env) != T_BAR) in alt()
2912 eat(env); in alt()
2913 if (!(f = alt(env, number, 0))) in alt()
2915 drop(env->disc, e); in alt()
2918 if ((e->type == REX_NULL || f->type == REX_NULL) && !(env->flags & (REG_NULL|REG_REGEXP))) in alt()
2920 if (!cond && (g = trie(env, e, f))) in alt()
2923 if (!(g = node(env, REX_ALT, 0, 0, 0))) in alt()
2925 env->error = REG_ESPACE; in alt()
2929 g->re.group.last = env->parno; in alt()
2934 drop(env->disc, e); in alt()
2935 drop(env->disc, f); in alt()
2936 if (!env->error) in alt()
2937 env->error = REG_ENULL; in alt()
2946 bmstr(Cenv_t* env, register Rex_t* a, unsigned char* v, int n, Bm_mask_t b) in bmstr() argument
2980 bmtrie(Cenv_t* env, Rex_t* a, unsigned char* v, Trie_node_t* x, int n, int m, Bm_mask_t b) in bmtrie() argument
2987 bmstr(env, a, v, n, b); in bmtrie()
2997 b = bmtrie(env, a, v, x->son, n, m + 1, b); in bmtrie()
3011 special(Cenv_t* env, regex_t* p) in special() argument
3025 if (e = p->env->rex) in special()
3027 if ((x = env->stats.x) && x->re.string.size < 3) in special()
3029 if ((t = env->stats.y) && t->re.trie.min < 3) in special()
3052 l = env->stats.l; in special()
3059 l = env->stats.k; in special()
3061 if (!(q = (size_t*)alloc(env->disc, 0, (n + 1) * sizeof(size_t)))) in special()
3063 …if (!(a = node(env, REX_BM, 0, 0, n * (sizeof(Bm_mask_t*) + (UCHAR_MAX + 1) * sizeof(Bm_mask_t)) +… in special()
3065 alloc(env->disc, q, 0); in special()
3073 a->re.bm.right = env->stats.m - l - n; in special()
3074 …a->re.bm.complete = (env->stats.e || y != e && (e->type != REX_GROUP || y != e->re.group.expr.rex)… in special()
3080 …a->re.bm.skip[0] = a->re.bm.skip[env->mappednewline] = (y->next && y->next->type == REX_END) ? HIT… in special()
3090 bmstr(env, a, x->re.string.base, n, 1); in special()
3098 m = bmtrie(env, a, v, t->re.trie.root[i], n, 0, m); in special()
3168 alloc(env->disc, q, 0); in special()
3170 p->env->rex = a; in special()
3176 if (env->flags & REG_NEWLINE) in special()
3180 if (env->stats.b) in special()
3191 if (env->flags & (REG_NULL|REG_REGEXP)) in special()
3193 env->error = REG_ENULL; in special()
3196 if ((env->flags & (REG_LEFT|REG_LITERAL|REG_RIGHT)) || e->map) in special()
3200 if (!(a = node(env, REX_KMP, 0, 0, n * (sizeof(int*) + 1)))) in special()
3218 p->env->rex = a; in special()
3220 drop(env->disc, e); in special()
3226 p->env->once = 1; in special()
3238 Cenv_t env; in regcomp() local
3251 p->env = 0; in regcomp()
3269 if (!(p->env = (Env_t*)alloc(disc, 0, sizeof(Env_t)))) in regcomp()
3271 memset(p->env, 0, sizeof(*p->env)); in regcomp()
3272 memset(&env, 0, sizeof(env)); in regcomp()
3273 env.regex = p; in regcomp()
3274 env.flags = flags; in regcomp()
3275 env.disc = p->env->disc = disc; in regcomp()
3276 if (env.flags & REG_AUGMENTED) in regcomp()
3277 env.flags |= REG_EXTENDED; in regcomp()
3278 env.mappeddot = '.'; in regcomp()
3279 env.mappednewline = '\n'; in regcomp()
3280 env.mappedslash = '/'; in regcomp()
3283 env.map = disc->re_map; in regcomp()
3284 env.MAP = p->env->fold; in regcomp()
3287 env.MAP[i] = fold[env.map[i]]; in regcomp()
3288 if (env.map[i] == '.') in regcomp()
3289 env.mappeddot = i; in regcomp()
3290 if (env.map[i] == '\n') in regcomp()
3291 env.mappednewline = i; in regcomp()
3292 if (env.map[i] == '/') in regcomp()
3293 env.mappedslash = i; in regcomp()
3297 env.MAP = fold; in regcomp()
3298 env.type = (env.flags & REG_AUGMENTED) ? ARE : (env.flags & REG_EXTENDED) ? ERE : BRE; in regcomp()
3299 env.explicit = -1; in regcomp()
3300 if (env.flags & REG_SHELL) in regcomp()
3302 if (env.flags & REG_SHELL_PATH) in regcomp()
3303 env.explicit = env.mappedslash; in regcomp()
3304 if (!(env.flags & REG_SHELL_ESCAPED)) in regcomp()
3305 env.flags |= REG_CLASS_ESCAPE; in regcomp()
3306 env.flags |= REG_LENIENT|REG_NULL; in regcomp()
3307 env.type = env.type == BRE ? SRE : KRE; in regcomp()
3310 env.flags &= ~(REG_SHELL_DOT|REG_SHELL_ESCAPED|REG_SHELL_GROUP|REG_SHELL_PATH); in regcomp()
3311 if ((env.flags & (REG_NEWLINE|REG_SPAN)) == REG_NEWLINE) in regcomp()
3312 env.explicit = env.mappednewline; in regcomp()
3313 p->env->leading = (env.flags & REG_SHELL_DOT) ? env.mappeddot : -1; in regcomp()
3314 env.posixkludge = !(env.flags & (REG_EXTENDED|REG_SHELL)); in regcomp()
3315 env.token.lex = 0; in regcomp()
3316 env.token.push = 0; in regcomp()
3317 if (env.flags & REG_DELIMITED) in regcomp()
3319 switch (env.delimiter = *pattern++) in regcomp()
3325 env.error = REG_EDELIM; in regcomp()
3328 env.terminator = '\n'; in regcomp()
3330 env.literal = env.pattern = env.cursor = (unsigned char*)pattern; in regcomp()
3331 if (!(p->env->rex = alt(&env, 1, 0))) in regcomp()
3333 if (env.parnest) in regcomp()
3335 env.error = REG_EPAREN; in regcomp()
3338 if ((env.flags & REG_LEFT) && p->env->rex->type != REX_BEG) in regcomp()
3340 if (p->env->rex->type == REX_ALT) in regcomp()
3341 env.flags &= ~REG_FIRST; in regcomp()
3342 if (!(e = node(&env, REX_BEG, 0, 0, 0))) in regcomp()
3347 e->next = p->env->rex; in regcomp()
3348 p->env->rex = e; in regcomp()
3349 p->env->once = 1; in regcomp()
3351 for (e = p->env->rex; e->next; e = e->next); in regcomp()
3352 p->env->done.type = REX_DONE; in regcomp()
3353 p->env->done.flags = e->flags; in regcomp()
3354 if ((env.flags & REG_RIGHT) && e->type != REX_END) in regcomp()
3356 if (p->env->rex->type == REX_ALT) in regcomp()
3357 env.flags &= ~REG_FIRST; in regcomp()
3358 if (!(f = node(&env, REX_END, 0, 0, 0))) in regcomp()
3367 if (stats(&env, p->env->rex)) in regcomp()
3369 if (!env.error) in regcomp()
3370 env.error = REG_ECOUNT; in regcomp()
3373 if (env.stats.b) in regcomp()
3374 p->env->hard = p->env->separate = 1; in regcomp()
3375 … (!(env.flags & REG_FIRST) && (env.stats.a || env.stats.c > 1 && env.stats.c != env.stats.s || env in regcomp()
3376 p->env->hard = 1; in regcomp()
3377 if (p->env->hard || env.stats.c || env.stats.i) in regcomp()
3378 p->env->stats.re_min = p->env->stats.re_max = -1; in regcomp()
3381 if (!(p->env->stats.re_min = env.stats.m)) in regcomp()
3382 p->env->stats.re_min = -1; in regcomp()
3383 if (!(p->env->stats.re_max = env.stats.n)) in regcomp()
3384 p->env->stats.re_max = -1; in regcomp()
3386 if (special(&env, p)) in regcomp()
3388 serialize(&env, p->env->rex, 1); in regcomp()
3389 p->re_nsub = env.stats.p; in regcomp()
3390 if (env.type == KRE) in regcomp()
3392 if (env.flags & REG_DELIMITED) in regcomp()
3394 p->re_npat = env.cursor - env.pattern + 1; in regcomp()
3395 if (*env.cursor == env.delimiter) in regcomp()
3397 else if (env.flags & REG_MUSTDELIM) in regcomp()
3399 env.error = REG_EDELIM; in regcomp()
3403 env.flags &= ~REG_DELIMITED; in regcomp()
3405 p->env->explicit = env.explicit; in regcomp()
3406 p->env->flags = env.flags & REG_COMP; in regcomp()
3407 p->env->min = env.stats.m; in regcomp()
3408 p->env->nsub = env.stats.p + env.stats.u; in regcomp()
3409 p->env->refs = 1; in regcomp()
3413 if (!env.error) in regcomp()
3414 env.error = REG_ESPACE; in regcomp()
3415 if (env.type >= SRE && env.error != REG_ESPACE && !(flags & REG_LITERAL)) in regcomp()
3418 pattern = (const char*)env.literal; in regcomp()
3421 return fatal(disc, env.error, pattern); in regcomp()
3455 Rex_t* e = p->env->rex; in regcomb()
3456 Rex_t* f = q->env->rex; in regcomb()
3459 Cenv_t env; in regcomb() local
3462 return fatal(p->env->disc, REG_BADPAT, NiL); in regcomb()
3463 if (p->env->separate || q->env->separate) in regcomb()
3465 memset(&env, 0, sizeof(env)); in regcomb()
3466 env.disc = p->env->disc; in regcomb()
3469 p->env->rex = e->next; in regcomb()
3471 drop(env.disc, e); in regcomb()
3472 e = p->env->rex; in regcomb()
3476 q->env->rex = f->next; in regcomb()
3478 drop(env.disc, f); in regcomb()
3479 f = q->env->rex; in regcomb()
3483 p->env->flags |= REG_LEFT; in regcomb()
3484 p->env->rex = e->next; in regcomb()
3486 drop(env.disc, e); in regcomb()
3487 e = p->env->rex; in regcomb()
3488 q->env->rex = f->next; in regcomb()
3490 drop(env.disc, f); in regcomb()
3491 f = q->env->rex; in regcomb()
3497 p->env->flags |= REG_RIGHT; in regcomb()
3498 drop(env.disc, g->next); in regcomb()
3500 drop(env.disc, h->next); in regcomb()
3503 if (!(g = trie(&env, f, e))) in regcomb()
3504 return fatal(p->env->disc, REG_BADPAT, NiL); in regcomb()
3505 p->env->rex = g; in regcomb()
3506 if (!q->env->once) in regcomb()
3507 p->env->once = 0; in regcomb()
3508 q->env->rex = 0; in regcomb()
3509 if (p->env->flags & REG_LEFT) in regcomb()
3511 if (!(e = node(&env, REX_BEG, 0, 0, 0))) in regcomb()
3514 return fatal(p->env->disc, REG_ESPACE, NiL); in regcomb()
3516 e->next = p->env->rex; in regcomb()
3517 p->env->rex = e; in regcomb()
3518 p->env->once = 1; in regcomb()
3520 if (p->env->flags & REG_RIGHT) in regcomb()
3522 for (f = p->env->rex; f->next; f = f->next); in regcomb()
3525 if (!(e = node(&env, REX_END, 0, 0, 0))) in regcomb()
3528 return fatal(p->env->disc, REG_ESPACE, NiL); in regcomb()
3533 env.explicit = p->env->explicit; in regcomb()
3534 env.flags = p->env->flags; in regcomb()
3535 env.disc = p->env->disc; in regcomb()
3536 if (stats(&env, p->env->rex)) in regcomb()
3539 return fatal(p->env->disc, env.error ? env.error : REG_ECOUNT, NiL); in regcomb()
3541 if (special(&env, p)) in regcomb()
3544 return fatal(p->env->disc, env.error ? env.error : REG_ESPACE, NiL); in regcomb()
3546 p->env->min = g->re.trie.min; in regcomb()
3561 p->env->refs++; in regdup()