Lines Matching refs:env

142 node(Cenv_t* env, int type, int lo, int hi, size_t extra)  in node()  argument
146 if (e = (Rex_t*)alloc(env->disc, 0, sizeof(Rex_t) + extra)) in node()
153 e->flags = env->flags; in node()
154 e->map = (e->flags & REG_ICASE) ? env->MAP : env->map; in node()
155 e->explicit = env->explicit; in node()
262 serialize(Cenv_t* env, Rex_t* e, int n) in serialize() argument
272 n = serialize(env, e->re.group.expr.binary.left, n); in serialize()
275 n = serialize(env, e->re.group.expr.binary.right, n); in serialize()
278 n = serialize(env, e->re.group.expr.binary.left, n); in serialize()
279 n = serialize(env, e->re.group.expr.binary.right, n); in serialize()
289 n = serialize(env, e->re.group.expr.rex, n); in serialize()
301 cat(Cenv_t* env, Rex_t* e, Rex_t* f) in cat() argument
307 drop(env->disc, e); in cat()
312 drop(env->disc, e); in cat()
319 drop(env->disc, f); in cat()
341 drop(env->disc, f); in cat()
355 stats(register Cenv_t* env, register Rex_t* e) in stats() argument
377 x = env->stats.x; in stats()
378 l = env->stats.l; in stats()
379 y = env->stats.y; in stats()
380 k = env->stats.k; in stats()
381 t = env->stats.t; in stats()
382 if (++env->stats.a <= 0) in stats()
384 cm = env->stats.m; in stats()
385 env->stats.m = 0; in stats()
386 cn = env->stats.n; in stats()
387 env->stats.n = 0; in stats()
388 if (stats(env, e->re.group.expr.binary.left)) in stats()
390 m = env->stats.m; in stats()
391 env->stats.m = 0; in stats()
392 n = env->stats.n; in stats()
393 env->stats.n = 0; in stats()
394 if (e->re.group.expr.binary.right && stats(env, e->re.group.expr.binary.right)) in stats()
396 if (env->stats.m > m) in stats()
397 env->stats.m = m; in stats()
399 m = env->stats.m; in stats()
400 if ((env->stats.m += cm) < m) in stats()
402 if (env->stats.n < n) in stats()
403 env->stats.n = n; in stats()
405 n = env->stats.n; in stats()
406 if ((env->stats.n += cn) < n) in stats()
408 env->stats.x = x; in stats()
409 env->stats.l = l; in stats()
410 env->stats.y = y; in stats()
411 env->stats.k = k; in stats()
412 env->stats.t = t; in stats()
415 if (++env->stats.b <= 0) in stats()
422 n = env->stats.m; in stats()
423 if ((env->stats.m += e->lo) < n) in stats()
427 n = env->stats.n; in stats()
428 if ((env->stats.n += e->hi) < n) in stats()
433 if (++env->stats.c <= 0) in stats()
435 if (++env->stats.s <= 0) in stats()
440 cm = env->stats.m; in stats()
441 env->stats.m = 0; in stats()
442 cn = env->stats.n; in stats()
443 env->stats.n = 0; in stats()
444 if (stats(env, e->re.group.expr.binary.left)) in stats()
446 nm = env->stats.m; in stats()
447 env->stats.m = 0; in stats()
448 nn = env->stats.n; in stats()
449 env->stats.n = 0; in stats()
450 if (stats(env, e->re.group.expr.binary.right)) in stats()
452 if (env->stats.m < nm) in stats()
453 env->stats.m = nm; in stats()
455 nm = env->stats.m; in stats()
456 if ((env->stats.m += cm) < nm) in stats()
458 if (env->stats.n < nn) in stats()
459 env->stats.n = nn; in stats()
461 nn = env->stats.n; in stats()
462 if ((env->stats.n += cn) < nn) in stats()
466 env->stats.e = 1; in stats()
469 if (e->re.group.number && ++env->stats.p <= 0 || !e->re.group.number && ++env->stats.u <= 0) in stats()
471 if (stats(env, e->re.group.expr.rex)) in stats()
478 m = env->stats.m; in stats()
479 n = env->stats.n; in stats()
480 x = env->stats.x; in stats()
481 y = env->stats.y; in stats()
482 if (stats(env, e->re.group.expr.rex)) in stats()
484 env->stats.m = m; in stats()
485 env->stats.n = n; in stats()
486 env->stats.x = x; in stats()
487 env->stats.y = y; in stats()
492 if (++env->stats.u <= 0) in stats()
498 if (++env->stats.u <= 0) in stats()
500 m = env->stats.m; in stats()
501 n = env->stats.n; in stats()
502 x = env->stats.x; in stats()
503 y = env->stats.y; in stats()
504 if (e->re.group.size > 0 && ++env->stats.b <= 0) in stats()
506 if (e->re.group.expr.binary.left && stats(env, e->re.group.expr.binary.left)) in stats()
510 if (q->re.group.expr.binary.left && stats(env, q->re.group.expr.binary.left)) in stats()
512 if (q->re.group.expr.binary.right && stats(env, q->re.group.expr.binary.right)) in stats()
515 env->stats.m = m; in stats()
516 env->stats.n = n; in stats()
517 env->stats.x = x; in stats()
518 env->stats.y = y; in stats()
521 if (++env->stats.u <= 0) in stats()
523 m = env->stats.m; in stats()
524 n = env->stats.n; in stats()
525 x = env->stats.x; in stats()
526 y = env->stats.y; in stats()
527 if (stats(env, e->re.group.expr.rex)) in stats()
529 env->stats.m = m; in stats()
530 env->stats.n = n; in stats()
531 env->stats.x = x; in stats()
532 env->stats.y = y; in stats()
535 env->stats.i++; in stats()
536 x = env->stats.x; in stats()
537 l = env->stats.l; in stats()
538 y = env->stats.y; in stats()
539 k = env->stats.k; in stats()
540 t = env->stats.t; in stats()
541 cm = env->stats.m; in stats()
542 env->stats.m = 0; in stats()
543 if (stats(env, e->re.group.expr.rex)) in stats()
545 env->stats.m = !env->stats.m; in stats()
546 if ((env->stats.m += cm) < cm) in stats()
548 env->stats.x = x; in stats()
549 env->stats.l = l; in stats()
550 env->stats.y = y; in stats()
551 env->stats.k = k; in stats()
552 env->stats.t = t; in stats()
555 x = env->stats.x; in stats()
556 l = env->stats.l; in stats()
557 y = env->stats.y; in stats()
558 k = env->stats.k; in stats()
559 t = env->stats.t; in stats()
560 if (++env->stats.c <= 0) in stats()
562 b = env->stats.b; in stats()
563 c = env->stats.c; in stats()
564 cm = env->stats.m; in stats()
565 env->stats.m = 0; in stats()
566 if (stats(env, e->re.group.expr.rex)) in stats()
568 if (env->stats.m == 1 && b == env->stats.b && c == env->stats.c && ++env->stats.s <= 0) in stats()
572 env->stats.x = x; in stats()
573 env->stats.l = l; in stats()
574 env->stats.y = y; in stats()
575 env->stats.k = k; in stats()
576 env->stats.t = t; in stats()
577 env->stats.m = cm; in stats()
581 m = env->stats.m; in stats()
582 if ((env->stats.m *= e->lo) > 0 && env->stats.m < m) in stats()
584 m = env->stats.m; in stats()
585 if ((env->stats.m += cm) < m) in stats()
587 if (env->stats.x != x) in stats()
588 env->stats.l = cm; in stats()
589 if (env->stats.y != y) in stats()
590 env->stats.k = cm; in stats()
596 cm = env->stats.m; in stats()
597 if ((env->stats.m += e->re.string.size) < cm) in stats()
599 cn = env->stats.n; in stats()
600 if ((env->stats.n += e->re.string.size) < cn) in stats()
602 if (!env->stats.x || env->stats.x->re.string.size < e->re.string.size) in stats()
604 env->stats.x = e; in stats()
605 env->stats.l = cm; in stats()
610 if (++env->stats.s <= 0) in stats()
612 cm = env->stats.m; in stats()
613 if ((env->stats.m += e->re.trie.min) < cm) in stats()
615 cn = env->stats.n; in stats()
616 if ((env->stats.n += e->re.trie.max) < cn) in stats()
618 env->stats.t++; in stats()
619 if (!env->stats.y || env->stats.y->re.trie.min < e->re.trie.min) in stats()
621 env->stats.y = e; in stats()
622 env->stats.k = cm; in stats()
633 magic(register Cenv_t* env, register int c, int escaped) in magic() argument
638 int e = env->error; in magic()
639 int l = env->token.len; in magic()
645 c = mp[env->type+escaped]; in magic()
648 sp = (char*)env->cursor + env->token.len; in magic()
658 env->error = REG_BADBR; in magic()
665 if (env->type < SRE || *sp != ',') in magic()
667 env->error = *sp ? REG_BADBR : REG_EBRACE; in magic()
673 env->error = REG_BADBR; in magic()
676 env->token.min = n; in magic()
685 env->error = REG_BADBR; in magic()
692 else if (n < env->token.min) in magic()
694 env->error = REG_BADBR; in magic()
698 env->token.max = n; in magic()
702 env->error = REG_EBRACE; in magic()
707 env->error = REG_BADBR; in magic()
715 env->error = REG_BADBR; in magic()
723 env->error = REG_EBRACE; in magic()
728 env->error = REG_BADBR; in magic()
731 env->token.len = sp - (char*)env->cursor; in magic()
734 env->error = REG_EBRACE; in magic()
737 if (env->type < SRE && *sp == '?') in magic()
739 env->token.len++; in magic()
740 env->token.lex = 0; in magic()
748 env->token.len += ep - sp; in magic()
751 env->token.lex = c; in magic()
766 env->token.len += ep - sp; in magic()
772 if (env->type == SRE || c == T_BACK && !(env->flags & REG_LENIENT)) in magic()
774 env->error = REG_BADESC; in magic()
777 if ((env->flags & REG_MULTIREF) && isdigit(*sp)) in magic()
780 if (c > 0 && c <= env->parno && env->paren[c]) in magic()
784 env->token.len++; in magic()
790 if (escaped == 1 && (env->flags & REG_LENIENT) && (c = mp[env->type+escaped+2]) >= T_META) in magic()
794 if (env->type >= SRE) in magic()
800 …if (env->type == KRE && *(env->cursor + env->token.len) == '-' && *(env->cursor + env->token.len +… in magic()
802 env->token.len++; in magic()
803 env->token.att = 1; in magic()
805 if (env->type == KRE && *(env->cursor + env->token.len) == '(') in magic()
807 env->token.len++; in magic()
813 env->token.lex = c; in magic()
816 env->token.lex = 0; in magic()
819 env->token.lex = c; in magic()
831 env->token.len = l; in magic()
837 c = (c > env->parno || !env->paren[c]) ? o : T_BACK + c; in magic()
839 else if (env->type == KRE && !env->parnest && (env->flags & REG_SHELL_GROUP)) in magic()
853 … (env->type >= SRE && !(env->flags & REG_SHELL_ESCAPED) || (env->flags & REG_ESCAPE) && (c == '[' … in magic()
857 env->error = REG_BADESC; in magic()
861 else if (escaped && !(env->flags & REG_LENIENT) && c != ']') in magic()
863 env->error = REG_BADESC; in magic()
868 sp = (char*)env->cursor + env->token.len; in magic()
879 env->error = REG_EPAREN; in magic()
892 env->cursor = (unsigned char*)sp; in magic()
893 return token(env); in magic()
896 env->error = e; in magic()
897 else if (env->flags & REG_LENIENT) in magic()
899 else if (escaped == 1 && !env->error) in magic()
903 env->error = REG_BADESC; in magic()
909 token(register Cenv_t* env) in token() argument
914 if (env->token.push) in token()
915 return env->token.lex; in token()
916 env->token.att = env->token.esc = 0; in token()
917 if ((env->token.len = MBSIZE(env->cursor)) > 1) in token()
918 return env->token.lex = C_MB; in token()
919 env->token.lex = 0; in token()
922 c = *env->cursor; in token()
923 if (c == 0 || c == env->delimiter || c == env->terminator) in token()
925 if (!(env->flags & REG_COMMENT)) in token()
931 c = *++env->cursor; in token()
932 if (c == 0 || c == env->delimiter) in token()
938 env->cursor++; in token()
940 if (c == '\n' && (env->flags & REG_MULTIPLE) && !env->delimiter) in token()
942 if (env->parnest) in token()
944 env->error = REG_EPAREN; in token()
947 env->parno = 0; in token()
948 env->pattern = env->cursor + 1; in token()
951 if (env->flags & REG_LITERAL) in token()
953 if (posixkludge = env->posixkludge) in token()
955 env->posixkludge = 0; in token()
961 if (env->flags & REG_SHELL_ESCAPED) in token()
963 if (!(c = *(env->cursor + 1)) || c == env->terminator) in token()
965 if (env->flags & REG_LENIENT) in token()
969 env->token.esc = env->token.len; in token()
970 env->token.len += MBSIZE(env->cursor + 1); in token()
975 env->error = REG_EESCAPE; in token()
978 env->token.esc = env->token.len; in token()
979 env->token.len += MBSIZE(env->cursor + 1); in token()
980 if (env->delimiter && c == 'n') in token()
982 else if (c == env->delimiter) in token()
983 return magic(env, c, 0); in token()
984 else if (c == '(' && env->type == BRE) in token()
985 env->posixkludge = 1; in token()
986 else if (c == ')' && env->type == BRE && env->parnest <= 0) in token()
988 env->error = REG_EPAREN; in token()
991 else if (isspace(c) && (env->flags & REG_COMMENT)) in token()
993 return magic(env, c, 1); in token()
997env->type == BRE && (*(env->cursor + 1) == 0 || *(env->cursor + 1) == env->delimiter || *(env->cur… in token()
1002 if (env->type == BRE && (env->cursor == env->pattern || posixkludge == 1)) in token()
1004 env->posixkludge = 2; in token()
1010 if (env->type != BRE && env->parnest <= 0) in token()
1013 else if (c == '/' && env->explicit == env->mappedslash) in token()
1015 while (*(env->cursor + env->token.len) == c) in token()
1016 env->token.len++; in token()
1019 return magic(env, c, 0); in token()
1160 bra(Cenv_t* env) in bra() argument
1183 if (!(e = node(env, REX_CLASS, 1, 1, sizeof(Set_t)))) in bra()
1186 if (*env->cursor == '^' || env->type >= SRE && *env->cursor == '!') in bra()
1188 env->cursor++; in bra()
1193 first = env->cursor; in bra()
1195env->cursor == 0 || *(env->cursor + 1) == 0 || *env->cursor == env->terminator || *(env->cursor + … in bra()
1197 begin = env->cursor + MBSIZE(env->cursor); in bra()
1206 …if (!(c = *env->cursor) || c == env->terminator || c == env->delimiter && (env->flags & REG_ESCAPE… in bra()
1208 env->cursor += (w = MBSIZE(env->cursor)); in bra()
1209 …if (c == '\\' && ((env->flags & REG_CLASS_ESCAPE) || env->type >= SRE && env->parnest || *env->cur… in bra()
1211 if (*env->cursor) in bra()
1213 if (*env->cursor == 'n') in bra()
1215 env->cursor++; in bra()
1218 else if (env->type < SRE || !(env->flags & REG_SHELL_ESCAPED)) in bra()
1220 env->token.len = 1; in bra()
1221 w = magic(env, *env->cursor, 2); in bra()
1222 if (env->token.len > 1 || w != T_BAD) in bra()
1224 if (env->token.len == 1 && (f = classfun(w))) in bra()
1228 if (env->type < SRE && !(env->flags & REG_LENIENT)) in bra()
1232 env->cursor++; in bra()
1240 if (env->token.len > 1 || w >= 0 && w < T_META) in bra()
1245 if (env->type < SRE && !(env->flags & REG_LENIENT) && !mbwide()) in bra()
1249 env->cursor += env->token.len; in bra()
1257 if (env->cursor == begin) in bra()
1277 if (!inrange && env->cursor != begin && *env->cursor != ']') in bra()
1279 if (env->type < SRE && !(env->flags & REG_LENIENT)) in bra()
1292 switch (*env->cursor) in bra()
1297 if (env->regexp) in bra()
1304 if (!(f = regclass((char*)env->cursor, (char**)&env->cursor))) in bra()
1306 if (env->cursor == start && (c = *(env->cursor + 1))) in bra()
1308 s = start = env->cursor + 1; in bra()
1328 env->cursor = s + 3; in bra()
1329 drop(env->disc, e); in bra()
1330 return node(env, i, 0, 0, 0); in bra()
1335 env->error = REG_ECTYPE; in bra()
1346 if (env->regexp) in bra()
1355 if ((c = regcollate((char*)env->cursor, (char**)&env->cursor, (char*)buf, sizeof(buf))) < 0) in bra()
1367 if (env->regexp) in bra()
1369 if ((c = regcollate((char*)env->cursor, (char**)&env->cursor, (char*)buf, sizeof(buf))) < 0) in bra()
1378 …if (*env->cursor == env->terminator || *env->cursor == env->delimiter && (env->flags & REG_ESCAPE)) in bra()
1391 inrange = env->type >= SRE || (env->flags & REG_LENIENT); in bra()
1394 else if (env->type >= SRE) in bra()
1401 else if (!(env->flags & REG_LENIENT)) in bra()
1456 drop(env->disc, e); in bra()
1462 drop(env->disc, e); in bra()
1463 if (ic = env->flags & REG_ICASE) in bra()
1465 if (!(e = node(env, REX_COLL_CLASS, 1, 1, (elements + 2) * sizeof(Celt_t)))) in bra()
1470 env->cursor = first; in bra()
1474 …if ((c = *env->cursor) == 0 || c == env->terminator || (env->flags & REG_ESCAPE) && c == env->deli… in bra()
1476 pp = env->cursor; in bra()
1477 env->cursor += (w = MBSIZE(env->cursor)); in bra()
1478 …if (c == '\\' && ((env->flags & REG_CLASS_ESCAPE) || env->type >= SRE && env->parnest || *env->cur… in bra()
1480 if (*env->cursor) in bra()
1482 if (*env->cursor == 'n') in bra()
1484 pp = env->cursor++; in bra()
1487 else if (env->type < SRE || !(env->flags & REG_SHELL_ESCAPED)) in bra()
1489 env->token.len = 1; in bra()
1490 w = magic(env, *env->cursor, 2); in bra()
1491 if (env->token.len > 1 || w != T_BAD) in bra()
1493 if (env->token.len == 1 && (f = classfun(w))) in bra()
1497 if (env->type < SRE && !(env->flags & REG_LENIENT)) in bra()
1501 env->cursor++; in bra()
1507 if (env->token.len > 1 || w >= 0 && w < T_META) in bra()
1512 env->cursor += env->token.len; in bra()
1520 if (env->cursor == begin) in bra()
1537 if (!inrange && env->cursor != begin && *env->cursor != ']') in bra()
1539 if (env->type < SRE && !(env->flags & REG_LENIENT)) in bra()
1551 switch (*env->cursor) in bra()
1556 if (env->regexp) in bra()
1560 if (!(f = regclass((char*)env->cursor, (char**)&env->cursor))) in bra()
1562 …if (env->cursor == start && (c = *(env->cursor + 1)) && *(env->cursor + 2) == ':' && *(env->cursor… in bra()
1578 env->cursor += 5; in bra()
1579 drop(env->disc, e); in bra()
1580 return node(env, i, 0, 0, 0); in bra()
1583 env->error = REG_ECTYPE; in bra()
1592 if (env->regexp) in bra()
1599 rp = env->cursor + 1; in bra()
1600 if ((rw = regcollate((char*)env->cursor, (char**)&env->cursor, (char*)pp, COLL_KEY_MAX)) < 0) in bra()
1654 if (env->regexp) in bra()
1657 if ((w = regcollate((char*)env->cursor, (char**)&env->cursor, (char*)pp, COLL_KEY_MAX)) < 0) in bra()
1663 …if (*env->cursor == env->terminator || *env->cursor == env->delimiter && (env->flags & REG_ESCAPE)) in bra()
1673 if (env->type < SRE && !(env->flags & REG_LENIENT)) in bra()
1680 inrange = env->type >= SRE || (env->flags & REG_LENIENT); in bra()
1697 if (env->flags & REG_ICASE) in bra()
1713 if (env->explicit >= 0) in bra()
1714 setclr(e->re.charclass, env->explicit); in bra()
1718 env->error = REG_ECOLLATE; in bra()
1721 env->error = REG_ERANGE; in bra()
1723 drop(env->disc, e); in bra()
1724 if (!env->error) in bra()
1725 env->error = REG_EBRACK; in bra()
1730 ccl(Cenv_t* env, int type) in ccl() argument
1739 env->error = REG_BADESC; in ccl()
1744 if (!(e = node(env, REX_CLASS, 1, 1, sizeof(Set_t)))) in ccl()
1749 if (env->explicit >= 0) in ccl()
1750 setclr(e->re.charclass, env->explicit); in ccl()
1754 if (!(e = node(env, REX_COLL_CLASS, 1, 1, 2 * sizeof(Celt_t)))) in ccl()
1768 rep(Cenv_t* env, Rex_t* e, int number, int last) in rep() argument
1777 switch (token(env)) in rep()
1780 eat(env); in rep()
1781 if (!(f = node(env, REX_NEG, m, n, 0))) in rep()
1783 drop(env->disc, e); in rep()
1789 eat(env); in rep()
1793 eat(env); in rep()
1796 eat(env); in rep()
1800 eat(env); in rep()
1801 m = env->token.min; in rep()
1802 n = env->token.max; in rep()
1807 if (env->token.att) in rep()
1809 else if (env->type < SRE) in rep()
1810 switch (token(env)) in rep()
1813 eat(env); in rep()
1814 minimal = !(env->flags & REG_MINIMAL); in rep()
1817 eat(env); in rep()
1818 minimal = !!(env->flags & REG_MINIMAL); in rep()
1842 env->error = REG_BADRPT; in rep()
1843 drop(env->disc, e); in rep()
1852 if (!(f = node(env, REX_REP, m, n, 0))) in rep()
1854 drop(env->disc, e); in rep()
1885 trienode(Cenv_t* env, int c) in trienode() argument
1889 if (t = (Trie_node_t*)alloc(env->disc, 0, sizeof(Trie_node_t))) in trienode()
1898 insert(Cenv_t* env, Rex_t* f, Rex_t* g) in insert() argument
1919 if (!(t = g->re.trie.root[*s]) && !(t = g->re.trie.root[*s] = trienode(env, *s))) in insert()
1927 if (!t->son && !(t->son = trienode(env, *s))) in insert()
1934 if (!t->sib && !(t->sib = trienode(env, *s))) in insert()
1954 trie(Cenv_t* env, Rex_t* e, Rex_t* f) in trie() argument
1962 if (!(g = node(env, REX_TRIE, 0, 0, (UCHAR_MAX + 1) * sizeof(Trie_node_t*)))) in trie()
1965 if (insert(env, f, g)) in trie()
1967 drop(env->disc, f); in trie()
1973 if (insert(env, e, g)) in trie()
1975 drop(env->disc, e); in trie()
1979 drop(env->disc, g); in trie()
1986 chr(register Cenv_t* env, int* escaped) in chr() argument
1992 if (!(c = *env->cursor)) in chr()
1994 env->cursor++; in chr()
1997 if (env->flags & REG_SHELL_ESCAPED) in chr()
1999 if (!(c = *(env->cursor + 1)) || c == env->terminator) in chr()
2001 if (env->flags & REG_LENIENT) in chr()
2003 env->error = REG_EESCAPE; in chr()
2006 p = env->cursor; in chr()
2007 c = chresc((char*)env->cursor - 1, (char**)&env->cursor); in chr()
2008 *escaped = env->cursor - p; in chr()
2018 grp(Cenv_t* env, int parno) in grp() argument
2031 beg = env->pattern == env->cursor - env->token.len; in grp()
2032 if (!(c = env->token.lex) && (c = *env->cursor)) in grp()
2033 env->cursor++; in grp()
2034 env->token.len = 0; in grp()
2035 env->parnest++; in grp()
2068 env->token.push = 1; in grp()
2074 if (!(env->flags & REG_LITERAL)) in grp()
2076 env->error = REG_BADRPT; in grp()
2085 eat(env); in grp()
2086 if (token(env) == T_CLOSE) in grp()
2097 env->flags |= (REG_LEFT|REG_RIGHT); in grp()
2099 env->flags &= ~(REG_LEFT|REG_RIGHT); in grp()
2103 env->flags &= ~REG_MINIMAL; in grp()
2105 env->flags |= REG_MINIMAL; in grp()
2109 env->flags |= REG_ICASE; in grp()
2111 env->flags &= ~REG_ICASE; in grp()
2115 env->flags |= REG_LEFT; in grp()
2117 env->flags &= ~REG_LEFT; in grp()
2121 env->flags |= REG_NEWLINE; in grp()
2123 env->flags &= ~REG_NEWLINE; in grp()
2124 env->explicit = (env->flags & (REG_NEWLINE|REG_SPAN)) == REG_NEWLINE ? env->mappednewline : -1; in grp()
2128 env->flags &= ~REG_LENIENT; in grp()
2130 env->flags |= REG_LENIENT; in grp()
2134 env->flags |= REG_RIGHT; in grp()
2136 env->flags &= ~REG_RIGHT; in grp()
2140 env->flags |= REG_SPAN; in grp()
2142 env->flags &= ~REG_SPAN; in grp()
2143 env->explicit = (env->flags & (REG_NEWLINE|REG_SPAN)) == REG_NEWLINE ? env->mappednewline : -1; in grp()
2147 env->flags |= REG_COMMENT; in grp()
2149 env->flags &= ~REG_COMMENT; in grp()
2152env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_SHELL|REG_LEFT|REG_RIGHT|REG_CLASS_ESCA… in grp()
2153 env->flags |= REG_AUGMENTED|REG_EXTENDED; in grp()
2158env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_SHELL|REG_LEFT|REG_RIGHT|REG_CLASS_ESCA… in grp()
2162env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_SHELL|REG_LEFT|REG_RIGHT|REG_CLASS_ESCA… in grp()
2163 env->flags |= REG_EXTENDED; in grp()
2168env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_SHELL|REG_LEFT|REG_RIGHT|REG_CLASS_ESCA… in grp()
2169 env->flags |= REG_LITERAL; in grp()
2173env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_SHELL|REG_LEFT|REG_RIGHT|REG_CLASS_ESCA… in grp()
2174 env->flags |= REG_AUGMENTED|REG_SHELL|REG_LEFT|REG_RIGHT; in grp()
2187env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_SHELL|REG_LEFT|REG_RIGHT|REG_CLASS_ESCA… in grp()
2188 env->flags |= REG_EXTENDED|REG_CLASS_ESCAPE; in grp()
2192env->flags &= ~(REG_AUGMENTED|REG_EXTENDED|REG_LITERAL|REG_SHELL|REG_LEFT|REG_RIGHT|REG_CLASS_ESCA… in grp()
2193 env->flags |= REG_SHELL|REG_LEFT|REG_RIGHT; in grp()
2198 env->flags |= REG_MINIMAL; in grp()
2200 env->flags &= ~REG_MINIMAL; in grp()
2205 env->error = REG_BADRPT; in grp()
2208 eat(env); in grp()
2209 c = token(env); in grp()
2223 switch (token(env)) in grp()
2233 env->error = REG_BADRPT; in grp()
2236 eat(env); in grp()
2243 e = node(env, REX_NEST, 0, 0, (UCHAR_MAX + 1) * sizeof(unsigned short)); in grp()
2244 e->re.nest.primary = isalnum(*env->cursor) ? -1 : *env->cursor; in grp()
2248 switch (i = chr(env, &esc)) in grp()
2253 env->cursor -= esc + 1; in grp()
2254 env->error = REG_EPAREN; in grp()
2260 if ((i = chr(env, &esc)) < 0) in grp()
2273 switch (i = chr(env, &esc)) in grp()
2286 if ((i = chr(env, &esc)) < 0) in grp()
2316 …if ((x = chr(env, &esc)) < 0 || (e->re.nest.type[x] & (REX_NEST_close|REX_NEST_escape|REX_NEST_del… in grp()
2331 env->parnest--; in grp()
2335 parno = ++env->parno; in grp()
2336 if (!(f = node(env, REX_GROUP, 0, 0, 0))) in grp()
2338 drop(env->disc, e); in grp()
2341 if (parno < elementsof(env->paren)) in grp()
2342 env->paren[parno] = f; in grp()
2351 if (isdigit(*env->cursor)) in grp()
2358 env->error = REG_BADRPT; in grp()
2361 c = c * 10 + (*env->cursor++ - '0'); in grp()
2362 } while (isdigit(*env->cursor)); in grp()
2363 if (*env->cursor++ != ')') in grp()
2365 env->error = REG_BADRPT; in grp()
2368 if (c && env->type >= SRE) in grp()
2370 if (!c || c > env->parno || !env->paren[c]) in grp()
2372 if (!(env->flags & REG_LENIENT)) in grp()
2374 env->error = REG_ESUBREG; in grp()
2383 if (env->type < SRE && *env->cursor++ != '?') in grp()
2385 env->error = REG_BADRPT; in grp()
2388 if (!(f = grp(env, parno + 1)) && env->error) in grp()
2391 if (!(e = node(env, REX_GROUP_COND, 0, 0, 0))) in grp()
2393 drop(env->disc, f); in grp()
2398 if (!(e->re.group.expr.binary.right = alt(env, parno, 1))) in grp()
2400 drop(env->disc, e); in grp()
2403 if (token(env) != T_CLOSE) in grp()
2405 env->error = REG_EPAREN; in grp()
2408 eat(env); in grp()
2409 env->parnest--; in grp()
2410 return rep(env, e, parno, parno); in grp()
2412 p = env->cursor; in grp()
2414 while (c = *env->cursor) in grp()
2416 if (c == '\\' && *(env->cursor + 1)) in grp()
2417 env->cursor++; in grp()
2422 else if (c == env->delimiter || c == env->terminator) in grp()
2424 env->cursor++; in grp()
2428 env->error = REG_EBRACE; in grp()
2431 if (*++env->cursor != ')') in grp()
2433 env->error = REG_EPAREN; in grp()
2436 env->cursor++; in grp()
2437 env->parnest--; in grp()
2438 if (env->disc->re_version < REG_VERSION_EXEC) in grp()
2440 env->error = REG_BADRPT; in grp()
2443 if (!env->disc->re_execf) in grp()
2445 if (!(e = node(env, REX_EXEC, 0, 0, 0))) in grp()
2448 e->re.exec.size = env->cursor - p - 2; in grp()
2449 if (!env->disc->re_compf) in grp()
2452 … e->re.exec.data = (*env->disc->re_compf)(env->regex, e->re.exec.text, e->re.exec.size, env->disc); in grp()
2457 while (isdigit(*env->cursor)) in grp()
2461 env->error = REG_ESUBREG; in grp()
2464 c = c * 10 + *env->cursor++ - '0'; in grp()
2466 if (*env->cursor == ')') in grp()
2468 env->cursor++; in grp()
2469 env->parnest--; in grp()
2470 env->token.len = 1; in grp()
2471 if (c > env->parno || !env->paren[c]) in grp()
2473 env->error = REG_ESUBREG; in grp()
2476 env->paren[c]->re.group.back = 1; in grp()
2477 return rep(env, node(env, REX_BACK, c, 0, 0), 0, 0); in grp()
2481 env->error = REG_BADRPT; in grp()
2484 if (x && !(e = alt(env, parno, 0))) in grp()
2486 c = token(env); in grp()
2487 env->parnest--; in grp()
2488 if (c != T_CLOSE && (!(env->flags & REG_LITERAL) || c != ')')) in grp()
2490 env->error = REG_EPAREN; in grp()
2493 eat(env); in grp()
2497 env->pattern = env->cursor; in grp()
2498 env->type = typ; in grp()
2502 if (!(f = node(env, x, 0, 0, 0))) in grp()
2504 drop(env->disc, e); in grp()
2510 if (stats(env, e)) in grp()
2512 drop(env->disc, f); in grp()
2513 if (!env->error) in grp()
2514 env->error = REG_ECOUNT; in grp()
2517 f->re.group.size = env->stats.m; in grp()
2518 memset(&env->stats, 0, sizeof(env->stats)); in grp()
2524 f = rep(env, f, parno, env->parno); in grp()
2531 seq(Cenv_t* env) in seq() argument
2552 while ((c = token(env)) < T_META && s < &buf[sizeof(buf) - env->token.len]) in seq()
2555 p = env->cursor; in seq()
2559 *s++ = (env->flags & REG_ICASE) ? toupper(c) : c; in seq()
2561 else if (c == C_ESC || (env->flags & REG_ICASE)) in seq()
2563 c = (c == C_ESC) ? env->token.lex : mbchar(p); in seq()
2564 if (env->flags & REG_ICASE) in seq()
2580 n = env->token.len - env->token.esc; in seq()
2583 eat(env); in seq()
2600 if (!(e = node(env, REX_STRING, 0, 0, i))) in seq()
2607 if (!(f = node(env, REX_ONECHAR, 1, 1, 0))) in seq()
2609 drop(env->disc, e); in seq()
2612 f->re.onechar = (env->flags & REG_ICASE) ? toupper(x) : x; in seq()
2616 if (!(f = node(env, REX_STRING, 0, 0, n))) in seq()
2621 if (!(f = rep(env, f, 0, 0)) || !(f = cat(env, f, seq(env)))) in seq()
2623 drop(env->disc, e); in seq()
2627 f = cat(env, e, f); in seq()
2631 if (!(e = node(env, REX_STRING, 0, 0, c))) in seq()
2635 return cat(env, e, seq(env)); in seq()
2639 eat(env); in seq()
2641 if (c > env->parno || !env->paren[c]) in seq()
2643 env->error = REG_ESUBREG; in seq()
2646 env->paren[c]->re.group.back = 1; in seq()
2647 e = rep(env, node(env, REX_BACK, c, 0, 0), 0, 0); in seq()
2656 return node(env, REX_NULL, 0, 0, 0); in seq()
2658 eat(env); in seq()
2659 e = rep(env, node(env, REX_END, 0, 0, 0), 0, 0); in seq()
2662 eat(env); in seq()
2663 if ((e = node(env, REX_BEG, 0, 0, 0)) && (env->flags & REG_EXTENDED)) in seq()
2664 e = rep(env, e, 0, 0); in seq()
2667 tok = env->token; in seq()
2668 eat(env); in seq()
2669 flags = env->flags; in seq()
2670 type = env->type; in seq()
2671 if (env->token.att) in seq()
2672 env->flags |= REG_MINIMAL; in seq()
2673 env->parnest++; in seq()
2674 if (env->type == KRE) in seq()
2675 ++env->parno; in seq()
2676 parno = ++env->parno; in seq()
2677 if (!(e = alt(env, parno + 1, 0))) in seq()
2679 if (e->type == REX_NULL && env->type == ERE && !(env->flags & REG_NULL)) in seq()
2681 drop(env->disc, e); in seq()
2682env->error = (*env->cursor == 0 || *env->cursor == env->delimiter || *env->cursor == env->terminat… in seq()
2685 if (token(env) != T_CLOSE) in seq()
2687 drop(env->disc, e); in seq()
2688 env->error = REG_EPAREN; in seq()
2691 env->parnest--; in seq()
2692 eat(env); in seq()
2693 if (!(f = node(env, REX_GROUP, 0, 0, 0))) in seq()
2695 drop(env->disc, e); in seq()
2698 if (parno < elementsof(env->paren)) in seq()
2699 env->paren[parno] = f; in seq()
2706 env->token = tok; in seq()
2708 if (!(e = rep(env, f, parno, env->parno))) in seq()
2710 if (env->type == KRE) in seq()
2712 if (!(f = node(env, REX_GROUP, 0, 0, 0))) in seq()
2714 drop(env->disc, e); in seq()
2717 if (--parno < elementsof(env->paren)) in seq()
2718 env->paren[parno] = f; in seq()
2724 env->flags = flags; in seq()
2725 env->type = type; in seq()
2728 p = env->cursor; in seq()
2729 eat(env); in seq()
2730 flags = env->flags; in seq()
2731 type = env->type; in seq()
2732 if (!(e = grp(env, env->parno + 1))) in seq()
2734 if (env->error) in seq()
2736 if (env->literal == env->pattern && env->literal == p) in seq()
2737 env->literal = env->cursor; in seq()
2740 env->flags = flags; in seq()
2741 env->type = type; in seq()
2744 eat(env); in seq()
2745 if (e = bra(env)) in seq()
2746 e = rep(env, e, 0, 0); in seq()
2754 eat(env); in seq()
2755 if (e = ccl(env, c)) in seq()
2756 e = rep(env, e, 0, 0); in seq()
2759 eat(env); in seq()
2760 e = rep(env, node(env, REX_WBEG, 0, 0, 0), 0, 0); in seq()
2763 eat(env); in seq()
2764 e = rep(env, node(env, REX_WEND, 0, 0, 0), 0, 0); in seq()
2767 eat(env); in seq()
2768 e = rep(env, node(env, REX_DOT, 1, 1, 0), 0, 0); in seq()
2771 eat(env); in seq()
2772 env->token.lex = T_STAR; in seq()
2773 env->token.push = 1; in seq()
2774 e = rep(env, node(env, REX_DOT, 1, 1, 0), 0, 0); in seq()
2777 eat(env); in seq()
2778 env->token.lex = T_PLUS; in seq()
2779 env->token.push = 1; in seq()
2780 if (e = node(env, REX_ONECHAR, 1, 1, 0)) in seq()
2783 e = rep(env, e, 0, 0); in seq()
2787 eat(env); in seq()
2788 e = rep(env, node(env, REX_WORD, 0, 0, 0), 0, 0); in seq()
2791 eat(env); in seq()
2792 e = rep(env, node(env, REX_WORD_NOT, 0, 0, 0), 0, 0); in seq()
2795 eat(env); in seq()
2796 e = rep(env, node(env, REX_BEG_STR, 0, 0, 0), 0, 0); in seq()
2799 eat(env); in seq()
2800 e = rep(env, node(env, REX_END_STR, 0, 0, 0), 0, 0); in seq()
2803 eat(env); in seq()
2804 e = rep(env, node(env, REX_FIN_STR, 0, 0, 0), 0, 0); in seq()
2807 env->error = REG_BADRPT; in seq()
2810 if (e && *env->cursor != 0 && *env->cursor != env->delimiter && *env->cursor != env->terminator) in seq()
2811 e = cat(env, e, seq(env)); in seq()
2817 con(Cenv_t* env) in con() argument
2823 if (!(e = seq(env)) || !(env->flags & REG_AUGMENTED) || token(env) != T_AND) in con()
2825 eat(env); in con()
2826 if (!(f = con(env))) in con()
2828 drop(env->disc, e); in con()
2831 if (!(g = node(env, REX_CONJ, 0, 0, 0))) in con()
2833 drop(env->disc, e); in con()
2834 drop(env->disc, f); in con()
2843 alt(Cenv_t* env, int number, int cond) in alt() argument
2849 if (!(e = con(env))) in alt()
2851 else if (token(env) != T_BAR) in alt()
2861 eat(env); in alt()
2862 if (!(f = alt(env, number, 0))) in alt()
2864 drop(env->disc, e); in alt()
2867 if ((e->type == REX_NULL || f->type == REX_NULL) && !(env->flags & REG_NULL)) in alt()
2869 if (!cond && (g = trie(env, e, f))) in alt()
2872 if (!(g = node(env, REX_ALT, 0, 0, 0))) in alt()
2874 env->error = REG_ESPACE; in alt()
2878 g->re.group.last = env->parno; in alt()
2883 drop(env->disc, e); in alt()
2884 drop(env->disc, f); in alt()
2885 if (!env->error) in alt()
2886 env->error = REG_ENULL; in alt()
2895 bmstr(Cenv_t* env, register Rex_t* a, unsigned char* v, int n, Bm_mask_t b) in bmstr() argument
2929 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
2936 bmstr(env, a, v, n, b); in bmtrie()
2946 b = bmtrie(env, a, v, x->son, n, m + 1, b); in bmtrie()
2960 special(Cenv_t* env, regex_t* p) in special() argument
2974 if (e = p->env->rex) in special()
2976 if ((x = env->stats.x) && x->re.string.size < 3) in special()
2978 if ((t = env->stats.y) && t->re.trie.min < 3) in special()
3001 l = env->stats.l; in special()
3008 l = env->stats.k; in special()
3010 if (!(q = (size_t*)alloc(env->disc, 0, (n + 1) * sizeof(size_t)))) in special()
3012 …if (!(a = node(env, REX_BM, 0, 0, n * (sizeof(Bm_mask_t*) + (UCHAR_MAX + 1) * sizeof(Bm_mask_t)) +… in special()
3014 alloc(env->disc, q, 0); in special()
3022 a->re.bm.right = env->stats.m - l - n; in special()
3023 …a->re.bm.complete = (env->stats.e || y != e && (e->type != REX_GROUP || y != e->re.group.expr.rex)… in special()
3029 …a->re.bm.skip[0] = a->re.bm.skip[env->mappednewline] = (y->next && y->next->type == REX_END) ? HIT… in special()
3039 bmstr(env, a, x->re.string.base, n, 1); in special()
3047 m = bmtrie(env, a, v, t->re.trie.root[i], n, 0, m); in special()
3117 alloc(env->disc, q, 0); in special()
3119 p->env->rex = a; in special()
3125 if (env->flags & REG_NEWLINE) in special()
3129 if (env->stats.b) in special()
3140 if (env->flags & REG_NULL) in special()
3142 env->error = REG_ENULL; in special()
3145 if ((env->flags & (REG_LEFT|REG_LITERAL|REG_RIGHT)) || e->map) in special()
3149 if (!(a = node(env, REX_KMP, 0, 0, n * (sizeof(int*) + 1)))) in special()
3167 p->env->rex = a; in special()
3169 drop(env->disc, e); in special()
3175 p->env->once = 1; in special()
3187 Cenv_t env; in regcomp() local
3200 p->env = 0; in regcomp()
3218 if (!(p->env = (Env_t*)alloc(disc, 0, sizeof(Env_t)))) in regcomp()
3220 memset(p->env, 0, sizeof(*p->env)); in regcomp()
3221 memset(&env, 0, sizeof(env)); in regcomp()
3222 env.regex = p; in regcomp()
3223 env.flags = flags; in regcomp()
3224 env.disc = p->env->disc = disc; in regcomp()
3225 if (env.flags & REG_AUGMENTED) in regcomp()
3226 env.flags |= REG_EXTENDED; in regcomp()
3227 env.mappeddot = '.'; in regcomp()
3228 env.mappednewline = '\n'; in regcomp()
3229 env.mappedslash = '/'; in regcomp()
3232 env.map = disc->re_map; in regcomp()
3233 env.MAP = p->env->fold; in regcomp()
3236 env.MAP[i] = fold[env.map[i]]; in regcomp()
3237 if (env.map[i] == '.') in regcomp()
3238 env.mappeddot = i; in regcomp()
3239 if (env.map[i] == '\n') in regcomp()
3240 env.mappednewline = i; in regcomp()
3241 if (env.map[i] == '/') in regcomp()
3242 env.mappedslash = i; in regcomp()
3246 env.MAP = fold; in regcomp()
3247 env.type = (env.flags & REG_AUGMENTED) ? ARE : (env.flags & REG_EXTENDED) ? ERE : BRE; in regcomp()
3248 env.explicit = -1; in regcomp()
3249 if (env.flags & REG_SHELL) in regcomp()
3251 if (env.flags & REG_SHELL_PATH) in regcomp()
3252 env.explicit = env.mappedslash; in regcomp()
3253 env.flags |= REG_LENIENT|REG_NULL; in regcomp()
3254 env.type = env.type == BRE ? SRE : KRE; in regcomp()
3256 if ((env.flags & (REG_NEWLINE|REG_SPAN)) == REG_NEWLINE) in regcomp()
3257 env.explicit = env.mappednewline; in regcomp()
3258 p->env->leading = (env.flags & REG_SHELL_DOT) ? env.mappeddot : -1; in regcomp()
3259 env.posixkludge = !(env.flags & (REG_EXTENDED|REG_SHELL)); in regcomp()
3260 env.regexp = !!(env.flags & REG_REGEXP); in regcomp()
3261 env.token.lex = 0; in regcomp()
3262 env.token.push = 0; in regcomp()
3263 if (env.flags & REG_DELIMITED) in regcomp()
3265 switch (env.delimiter = *pattern++) in regcomp()
3271 env.error = REG_EDELIM; in regcomp()
3274 env.terminator = '\n'; in regcomp()
3276 env.literal = env.pattern = env.cursor = (unsigned char*)pattern; in regcomp()
3277 if (!(p->env->rex = alt(&env, 1, 0))) in regcomp()
3279 if (env.parnest) in regcomp()
3281 env.error = REG_EPAREN; in regcomp()
3284 p->env->stats.re_flags = env.flags & (REG_EXTENDED|REG_AUGMENTED|REG_SHELL); in regcomp()
3285 if (env.flags & REG_LEFT) in regcomp()
3287 if (p->env->rex->type != REX_BEG) in regcomp()
3289 if (p->env->rex->type == REX_ALT) in regcomp()
3290 env.flags &= ~REG_FIRST; in regcomp()
3291 if (!(e = node(&env, REX_BEG, 0, 0, 0))) in regcomp()
3296 e->next = p->env->rex; in regcomp()
3297 p->env->rex = e; in regcomp()
3298 p->env->once = 1; in regcomp()
3300 p->env->stats.re_flags |= REG_LEFT; in regcomp()
3302 for (e = p->env->rex; e->next; e = e->next); in regcomp()
3303 p->env->done.type = REX_DONE; in regcomp()
3304 p->env->done.flags = e->flags; in regcomp()
3305 if (env.flags & REG_RIGHT) in regcomp()
3309 if (p->env->rex->type == REX_ALT) in regcomp()
3310 env.flags &= ~REG_FIRST; in regcomp()
3311 if (!(f = node(&env, REX_END, 0, 0, 0))) in regcomp()
3320 p->env->stats.re_flags |= REG_RIGHT; in regcomp()
3322 if (stats(&env, p->env->rex)) in regcomp()
3324 if (!env.error) in regcomp()
3325 env.error = REG_ECOUNT; in regcomp()
3328 if (env.stats.b) in regcomp()
3329 p->env->hard = p->env->separate = 1; in regcomp()
3330 … (!(env.flags & REG_FIRST) && (env.stats.a || env.stats.c > 1 && env.stats.c != env.stats.s || env in regcomp()
3331 p->env->hard = 1; in regcomp()
3332 if (p->env->hard || env.stats.c || env.stats.i) in regcomp()
3333 p->env->stats.re_min = p->env->stats.re_max = -1; in regcomp()
3336 if (!(p->env->stats.re_min = env.stats.m)) in regcomp()
3337 p->env->stats.re_min = -1; in regcomp()
3338 if (!(p->env->stats.re_max = env.stats.n)) in regcomp()
3339 p->env->stats.re_max = -1; in regcomp()
3341 if (special(&env, p)) in regcomp()
3343 serialize(&env, p->env->rex, 1); in regcomp()
3344 p->re_nsub = env.stats.p; in regcomp()
3345 if (env.type == KRE) in regcomp()
3347 if (env.flags & REG_DELIMITED) in regcomp()
3349 p->re_npat = env.cursor - env.pattern + 1; in regcomp()
3350 if (*env.cursor == env.delimiter) in regcomp()
3352 else if (env.flags & REG_MUSTDELIM) in regcomp()
3354 env.error = REG_EDELIM; in regcomp()
3358 env.flags &= ~REG_DELIMITED; in regcomp()
3360 p->env->explicit = env.explicit; in regcomp()
3361 p->env->flags = env.flags & REG_COMP; in regcomp()
3362 p->env->min = env.stats.m; in regcomp()
3363 p->env->nsub = env.stats.p + env.stats.u; in regcomp()
3364 p->env->refs = 1; in regcomp()
3368 if (!env.error) in regcomp()
3369 env.error = REG_ESPACE; in regcomp()
3370 if (env.type >= SRE && env.error != REG_ESPACE && !(flags & REG_LITERAL)) in regcomp()
3373 pattern = (const char*)env.literal; in regcomp()
3376 return fatal(disc, env.error, pattern); in regcomp()
3410 Rex_t* e = p->env->rex; in regcomb()
3411 Rex_t* f = q->env->rex; in regcomb()
3414 Cenv_t env; in regcomb() local
3417 return fatal(p->env->disc, REG_BADPAT, NiL); in regcomb()
3418 if (p->env->separate || q->env->separate) in regcomb()
3420 memset(&env, 0, sizeof(env)); in regcomb()
3421 env.disc = p->env->disc; in regcomb()
3424 p->env->rex = e->next; in regcomb()
3426 drop(env.disc, e); in regcomb()
3427 e = p->env->rex; in regcomb()
3431 q->env->rex = f->next; in regcomb()
3433 drop(env.disc, f); in regcomb()
3434 f = q->env->rex; in regcomb()
3438 p->env->flags |= REG_LEFT; in regcomb()
3439 p->env->rex = e->next; in regcomb()
3441 drop(env.disc, e); in regcomb()
3442 e = p->env->rex; in regcomb()
3443 q->env->rex = f->next; in regcomb()
3445 drop(env.disc, f); in regcomb()
3446 f = q->env->rex; in regcomb()
3452 p->env->flags |= REG_RIGHT; in regcomb()
3453 drop(env.disc, g->next); in regcomb()
3455 drop(env.disc, h->next); in regcomb()
3458 if (!(g = trie(&env, f, e))) in regcomb()
3459 return fatal(p->env->disc, REG_BADPAT, NiL); in regcomb()
3460 p->env->rex = g; in regcomb()
3461 if (!q->env->once) in regcomb()
3462 p->env->once = 0; in regcomb()
3463 q->env->rex = 0; in regcomb()
3464 if (p->env->flags & REG_LEFT) in regcomb()
3466 if (!(e = node(&env, REX_BEG, 0, 0, 0))) in regcomb()
3469 return fatal(p->env->disc, REG_ESPACE, NiL); in regcomb()
3471 e->next = p->env->rex; in regcomb()
3472 p->env->rex = e; in regcomb()
3473 p->env->once = 1; in regcomb()
3475 if (p->env->flags & REG_RIGHT) in regcomb()
3477 for (f = p->env->rex; f->next; f = f->next); in regcomb()
3480 if (!(e = node(&env, REX_END, 0, 0, 0))) in regcomb()
3483 return fatal(p->env->disc, REG_ESPACE, NiL); in regcomb()
3488 env.explicit = p->env->explicit; in regcomb()
3489 env.flags = p->env->flags; in regcomb()
3490 env.disc = p->env->disc; in regcomb()
3491 if (stats(&env, p->env->rex)) in regcomb()
3494 return fatal(p->env->disc, env.error ? env.error : REG_ECOUNT, NiL); in regcomb()
3496 if (special(&env, p)) in regcomb()
3499 return fatal(p->env->disc, env.error ? env.error : REG_ESPACE, NiL); in regcomb()
3501 p->env->min = g->re.trie.min; in regcomb()
3516 p->env->refs++; in regdup()