#include <sys/types.h>#include <stdio.h>#include <string.h>#include <ctype.h>#include <limits.h>#include <stdlib.h>#include <regex.h>#include "utils.h"#include <assert.h>

Go to the source code of this file.
Data Structures | |
| struct | parse |
Defines | |
| #define | NPAREN 10 |
| #define | PEEK() (*p->next) |
| #define | PEEK2() (*(p->next+1)) |
| #define | MORE() (p->next < p->end) |
| #define | MORE2() (p->next+1 < p->end) |
| #define | SEE(c) (MORE() && PEEK() == (c)) |
| #define | SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) |
| #define | EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0) |
| #define | EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) |
| #define | NEXT() (p->next++) |
| #define | NEXT2() (p->next += 2) |
| #define | NEXTn(n) (p->next += (n)) |
| #define | GETNEXT() (*p->next++) |
| #define | SETERROR(e) seterr(p, (e)) |
| #define | REQUIRE(co, e) ((co) || SETERROR(e)) |
| #define | MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e)) |
| #define | MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e)) |
| #define | MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e)) |
| #define | EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd)) |
| #define | INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos) |
| #define | AHEAD(pos) dofwd(p, pos, HERE()-(pos)) |
| #define | ASTERN(sop, pos) EMIT(sop, HERE()-pos) |
| #define | HERE() (p->slen) |
| #define | THERE() (p->slen - 1) |
| #define | THERETHERE() (p->slen - 2) |
| #define | DROP(n) (p->slen -= (n)) |
| #define | GOODFLAGS(f) ((f)&~REG_DUMP) |
| #define | BACKSL (1<<CHAR_BIT) |
| #define | N 2 |
| #define | INF 3 |
| #define | REP(f, t) ((f)*8 + (t)) |
| #define | MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N) |
Functions | |
| static void | p_ere (struct parse *, int) |
| static void | p_ere_exp (struct parse *) |
| static void | p_str (struct parse *) |
| static void | p_bre (struct parse *, int, int) |
| static int | p_simp_re (struct parse *, int) |
| static int | p_count (struct parse *) |
| static void | p_bracket (struct parse *) |
| static void | p_b_term (struct parse *, cset *) |
| static void | p_b_cclass (struct parse *, cset *) |
| static void | p_b_eclass (struct parse *, cset *) |
| static char | p_b_symbol (struct parse *) |
| static char | p_b_coll_elem (struct parse *, int) |
| static char | othercase (int) |
| static void | bothcases (struct parse *, int) |
| static void | ordinary (struct parse *, int) |
| static void | nonnewline (struct parse *) |
| static void | repeat (struct parse *, sopno, int, int) |
| static int | seterr (struct parse *, int) |
| static cset * | allocset (struct parse *) |
| static void | freeset (struct parse *, cset *) |
| static int | freezeset (struct parse *, cset *) |
| static int | firstch (struct parse *, cset *) |
| static int | nch (struct parse *, cset *) |
| static void | mcadd (struct parse *, cset *, char *) |
| static void | mcinvert (struct parse *, cset *) |
| static void | mccase (struct parse *, cset *) |
| static int | isinsets (struct re_guts *, int) |
| static int | samesets (struct re_guts *, int, int) |
| static void | categorize (struct parse *, struct re_guts *) |
| static sopno | dupl (struct parse *, sopno, sopno) |
| static void | doemit (struct parse *, sop, size_t) |
| static void | doinsert (struct parse *, sop, size_t, sopno) |
| static void | dofwd (struct parse *, sopno, sop) |
| static void | enlarge (struct parse *, sopno) |
| static void | stripsnug (struct parse *, struct re_guts *) |
| static void | findmust (struct parse *, struct re_guts *) |
| static sopno | pluscount (struct parse *, struct re_guts *) |
| int | regcomp (regex_t *preg, const char *pattern, int cflags) |
Variables | |
| static char | nuls [10] |
| static int | never = 0 |
| #define AHEAD | ( | pos | ) | dofwd(p, pos, HERE()-(pos)) |
Definition at line 132 of file regcomp.c.
Referenced by p_ere(), p_ere_exp(), and repeat().
Definition at line 133 of file regcomp.c.
Referenced by p_ere(), p_ere_exp(), p_simp_re(), and repeat().
| #define BACKSL (1<<CHAR_BIT) |
Referenced by p_simp_re().
| #define DROP | ( | n | ) | (p->slen -= (n)) |
| #define EAT | ( | c | ) | ((SEE(c)) ? (NEXT(), 1) : 0) |
Definition at line 119 of file regcomp.c.
Referenced by p_b_term(), p_bracket(), p_bre(), p_ere(), p_ere_exp(), and p_simp_re().
| #define EATTWO | ( | a, | |||
| b | ) | ((SEETWO(a, b)) ? (NEXT2(), 1) : 0) |
Definition at line 120 of file regcomp.c.
Referenced by p_b_symbol(), p_b_term(), and p_simp_re().
| #define EMIT | ( | op, | |||
| sopnd | ) | doemit(p, (sop)(op), (size_t)(sopnd)) |
Definition at line 130 of file regcomp.c.
Referenced by doinsert(), ordinary(), p_bracket(), p_bre(), p_ere(), p_ere_exp(), p_simp_re(), regcomp(), and repeat().
| #define GETNEXT | ( | ) | (*p->next++) |
Definition at line 124 of file regcomp.c.
Referenced by p_b_symbol(), p_count(), p_ere_exp(), p_simp_re(), and p_str().
| #define HERE | ( | ) | (p->slen) |
Definition at line 134 of file regcomp.c.
Referenced by doinsert(), dupl(), p_bre(), p_ere(), p_ere_exp(), p_simp_re(), and repeat().
| #define INF 3 |
Referenced by repeat().
| #define INSERT | ( | op, | |||
| pos | ) | doinsert(p, (sop)(op), HERE()-(pos)+1, pos) |
Definition at line 131 of file regcomp.c.
Referenced by p_ere(), p_ere_exp(), p_simp_re(), and repeat().
| #define MAP | ( | n | ) | (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N) |
Referenced by repeat().
| #define MORE | ( | ) | (p->next < p->end) |
Definition at line 115 of file regcomp.c.
Referenced by p_b_cclass(), p_b_coll_elem(), p_b_symbol(), p_b_term(), p_bracket(), p_bre(), p_count(), p_ere(), p_ere_exp(), p_simp_re(), and p_str().
| #define MORE2 | ( | ) | (p->next+1 < p->end) |
Definition at line 116 of file regcomp.c.
Referenced by p_b_term(), and p_ere_exp().
| #define MUSTEAT | ( | c, | |||
| e | ) | (REQUIRE(MORE() && GETNEXT() == (c), e)) |
Definition at line 128 of file regcomp.c.
Referenced by p_bracket(), and p_ere_exp().
| #define MUSTNOTSEE | ( | c, | |||
| e | ) | (REQUIRE(!MORE() || PEEK() != (c), e)) |
| #define MUSTSEE | ( | c, | |||
| e | ) | (REQUIRE(MORE() && PEEK() == (c), e)) |
| #define N 2 |
Referenced by repeat().
| #define NEXT | ( | ) | (p->next++) |
Definition at line 121 of file regcomp.c.
Referenced by p_b_cclass(), p_b_coll_elem(), p_b_term(), p_ere_exp(), and p_simp_re().
| #define NEXT2 | ( | ) | (p->next += 2) |
Definition at line 122 of file regcomp.c.
Referenced by p_b_term().
| #define NEXTn | ( | n | ) | (p->next += (n)) |
Definition at line 123 of file regcomp.c.
Referenced by p_bracket().
| #define NPAREN 10 |
Definition at line 59 of file regcomp.c.
Referenced by doinsert(), p_ere_exp(), p_simp_re(), and regcomp().
| #define PEEK | ( | ) | (*p->next) |
Definition at line 113 of file regcomp.c.
Referenced by p_b_cclass(), p_b_term(), p_bracket(), p_count(), p_ere(), p_ere_exp(), and p_simp_re().
| #define PEEK2 | ( | ) | (*(p->next+1)) |
Definition at line 114 of file regcomp.c.
Referenced by p_b_term(), and p_ere_exp().
| #define REP | ( | f, | |||
| t | ) | ((f)*8 + (t)) |
Referenced by repeat().
| #define REQUIRE | ( | co, | |||
| e | ) | ((co) || SETERROR(e)) |
Definition at line 126 of file regcomp.c.
Referenced by p_b_symbol(), p_b_term(), p_bre(), p_count(), p_ere(), p_ere_exp(), p_simp_re(), and p_str().
| #define SEE | ( | c | ) | (MORE() && PEEK() == (c)) |
Definition at line 117 of file regcomp.c.
Referenced by p_b_term(), p_ere(), and p_ere_exp().
| #define SEETWO | ( | a, | |||
| b | ) | (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b)) |
Definition at line 118 of file regcomp.c.
Referenced by p_b_coll_elem(), p_bracket(), p_bre(), and p_simp_re().
| #define SETERROR | ( | e | ) | seterr(p, (e)) |
Definition at line 125 of file regcomp.c.
Referenced by allocset(), enlarge(), mcadd(), p_b_cclass(), p_b_coll_elem(), p_b_term(), p_ere_exp(), p_simp_re(), regcomp(), repeat(), and stripsnug().
| #define THERE | ( | ) | (p->slen - 1) |
| #define THERETHERE | ( | ) | (p->slen - 2) |
Definition at line 136 of file regcomp.c.
Referenced by p_ere_exp(), and repeat().
Definition at line 1022 of file regcomp.c.
References re_guts::csetsize, parse::g, cset::hash, cset::mask, cset::multis, parse::ncsalloc, re_guts::ncsets, cset::ptr, REG_ESPACE, re_guts::setbits, SETERROR, re_guts::sets, and cset::smultis.
Referenced by p_bracket().
| static void bothcases | ( | struct parse * | p, | |
| int | ch | |||
| ) | [static] |
Definition at line 875 of file regcomp.c.
References parse::end, parse::next, othercase(), and p_bracket().
Referenced by ordinary().

Definition at line 1250 of file regcomp.c.
References re_guts::categories, parse::error, isinsets(), re_guts::ncategories, and samesets().
Referenced by regcomp().

Definition at line 1301 of file regcomp.c.
References enlarge(), parse::error, OPSHIFT, parse::slen, SOP, parse::ssize, and parse::strip.

Definition at line 1358 of file regcomp.c.
References parse::error, OP, OPSHIFT, and parse::strip.
Definition at line 1323 of file regcomp.c.
References EMIT, parse::error, HERE, NPAREN, parse::pbegin, parse::pend, and parse::strip.
Definition at line 1275 of file regcomp.c.
References enlarge(), HERE, parse::slen, parse::ssize, and parse::strip.
Referenced by p_simp_re(), and repeat().

Definition at line 1372 of file regcomp.c.
References REG_ESPACE, SETERROR, parse::ssize, and parse::strip.
Definition at line 1412 of file regcomp.c.
References BAD, parse::error, re_guts::iflags, re_guts::mlen, re_guts::must, O_CH, O_QUEST, OCH_, OCHAR, OEND, OLPAREN, OOR2, OP, OPLUS_, OPND, OQUEST_, ORPAREN, and re_guts::strip.
Referenced by regcomp().
Definition at line 1134 of file regcomp.c.
References CHIN, re_guts::csetsize, parse::g, and never.
Referenced by p_bracket().
Definition at line 1081 of file regcomp.c.
References CHsub, re_guts::csetsize, parse::g, re_guts::ncsets, and re_guts::sets.
Referenced by freezeset(), and p_bracket().
Definition at line 1103 of file regcomp.c.
References CHIN, re_guts::csetsize, freeset(), parse::g, cset::hash, re_guts::ncsets, and re_guts::sets.
Referenced by p_bracket().

| static int isinsets | ( | struct re_guts * | g, | |
| int | c | |||
| ) | [static] |
Definition at line 1215 of file regcomp.c.
References re_guts::ncsets, and re_guts::setbits.
Referenced by categorize().
Definition at line 1166 of file regcomp.c.
References cset::multis, REG_ESPACE, SETERROR, and cset::smultis.
Definition at line 1150 of file regcomp.c.
References CHIN, re_guts::csetsize, and parse::g.
Referenced by p_bracket().
| static void nonnewline | ( | struct parse * | p | ) | [static] |
Definition at line 917 of file regcomp.c.
References parse::end, parse::next, and p_bracket().
Referenced by p_ere_exp(), and p_simp_re().

| static void ordinary | ( | struct parse * | p, | |
| int | ch | |||
| ) | [static] |
Definition at line 898 of file regcomp.c.
References bothcases(), re_guts::categories, re_guts::cflags, EMIT, parse::g, re_guts::ncategories, OCHAR, othercase(), and REG_ICASE.
Referenced by p_bracket(), p_ere_exp(), p_simp_re(), and p_str().

| static char othercase | ( | int | ch | ) | [static] |
Definition at line 857 of file regcomp.c.
Referenced by bothcases(), ordinary(), and p_bracket().
Definition at line 767 of file regcomp.c.
References cclasses, CHadd, cclass::chars, MCadd, MORE, cclass::multis, cclass::name, NEXT, parse::next, PEEK, REG_ECTYPE, and SETERROR.
Referenced by p_b_term().
| static char p_b_coll_elem | ( | struct parse * | p, | |
| int | endc | |||
| ) | [static] |
Definition at line 830 of file regcomp.c.
References cnames, cname::code, MORE, cname::name, NEXT, parse::next, REG_EBRACK, REG_ECOLLATE, SEETWO, and SETERROR.
Referenced by p_b_eclass(), and p_b_symbol().
Definition at line 800 of file regcomp.c.
References CHadd, and p_b_coll_elem().
Referenced by p_b_term().

| static char p_b_symbol | ( | struct parse * | p | ) | [static] |
Definition at line 812 of file regcomp.c.
References EATTWO, GETNEXT, MORE, p_b_coll_elem(), REG_EBRACK, REG_ECOLLATE, and REQUIRE.
Referenced by p_b_term().

Definition at line 704 of file regcomp.c.
References CHadd, EAT, EATTWO, MORE, MORE2, NEXT, NEXT2, p_b_cclass(), p_b_eclass(), p_b_symbol(), PEEK, PEEK2, REG_EBRACK, REG_ECOLLATE, REG_ECTYPE, REG_ERANGE, REQUIRE, SEE, and SETERROR.
Referenced by p_bracket().

| static void p_bracket | ( | struct parse * | p | ) | [static] |
Definition at line 625 of file regcomp.c.
References allocset(), re_guts::cflags, CHadd, CHIN, CHsub, re_guts::csetsize, EAT, EMIT, parse::end, parse::error, firstch(), freeset(), freezeset(), parse::g, mccase(), mcinvert(), MORE, cset::multis, MUSTEAT, nch(), parse::next, NEXTn, OANYOF, OBOW, OEOW, ordinary(), othercase(), p_b_term(), PEEK, REG_EBRACK, REG_ICASE, REG_NEWLINE, and SEETWO.
Referenced by bothcases(), nonnewline(), p_ere_exp(), and p_simp_re().

| static void p_bre | ( | struct parse * | p, | |
| int | end1, | |||
| int | end2 | |||
| ) | [static] |
Definition at line 457 of file regcomp.c.
References DROP, EAT, EMIT, parse::g, HERE, re_guts::iflags, MORE, re_guts::nbol, re_guts::neol, OBOL, OEOL, p_simp_re(), REG_EMPTY, REQUIRE, SEETWO, USEBOL, and USEEOL.
Referenced by p_simp_re(), and regcomp().

| static int p_count | ( | struct parse * | p | ) | [static] |
Definition at line 604 of file regcomp.c.
References DUPMAX, GETNEXT, MORE, PEEK, REG_BADBR, and REQUIRE.
Referenced by p_ere_exp(), and p_simp_re().
| static void p_ere | ( | struct parse * | p, | |
| int | stop | |||
| ) | [static] |
| static void p_ere_exp | ( | struct parse * | p | ) | [static] |
Definition at line 292 of file regcomp.c.
References AHEAD, ASTERN, re_guts::cflags, EAT, EMIT, parse::g, GETNEXT, HERE, re_guts::iflags, INFINITY, INSERT, MORE, MORE2, MUSTEAT, re_guts::nbol, re_guts::neol, NEXT, nonnewline(), NPAREN, re_guts::nsub, O_CH, O_PLUS, O_QUEST, OANY, OBOL, OCH_, OEOL, OLPAREN, OOR1, OOR2, OPLUS_, OQUEST_, ordinary(), ORPAREN, p_bracket(), p_count(), p_ere(), parse::pbegin, PEEK, PEEK2, parse::pend, REG_BADBR, REG_BADRPT, REG_EBRACE, REG_EESCAPE, REG_EMPTY, REG_EPAREN, REG_NEWLINE, repeat(), REQUIRE, SEE, SETERROR, THERE, THERETHERE, USEBOL, and USEEOL.
Referenced by p_ere().

| static int p_simp_re | ( | struct parse * | p, | |
| int | starordinary | |||
| ) | [static] |
Definition at line 488 of file regcomp.c.
References ASTERN, re_guts::backrefs, BACKSL, re_guts::cflags, dupl(), EAT, EATTWO, EMIT, parse::g, GETNEXT, HERE, INFINITY, INSERT, MORE, NEXT, nonnewline(), NPAREN, re_guts::nsub, O_BACK, O_PLUS, O_QUEST, OANY, OBACK_, OLPAREN, OP, OPLUS_, OQUEST_, ordinary(), ORPAREN, p_bracket(), p_bre(), p_count(), parse::pbegin, PEEK, parse::pend, REG_BADBR, REG_BADRPT, REG_EBRACE, REG_EESCAPE, REG_EPAREN, REG_ESUBREG, REG_NEWLINE, repeat(), REQUIRE, SEETWO, SETERROR, and parse::strip.
Referenced by p_bre().

| static void p_str | ( | struct parse * | p | ) | [static] |
Definition at line 1490 of file regcomp.c.
References BAD, parse::error, re_guts::iflags, O_PLUS, OEND, OP, OPLUS_, and re_guts::strip.
Referenced by regcomp().
| int regcomp | ( | regex_t * | preg, | |
| const char * | pattern, | |||
| int | cflags | |||
| ) |
Definition at line 149 of file regcomp.c.
References re_guts::backrefs, BAD, re_guts::categories, categorize(), re_guts::catspace, re_guts::cflags, re_guts::csetsize, EMIT, parse::end, parse::error, findmust(), re_guts::firststate, parse::g, GOODFLAGS, re_guts::iflags, re_guts::laststate, re_guts::magic, MAGIC1, MAGIC2, re_guts::mlen, re_guts::must, re_guts::nbol, NC, re_guts::ncategories, parse::ncsalloc, re_guts::ncsets, re_guts::neol, parse::next, NPAREN, re_guts::nplus, re_guts::nsub, OEND, OUT, p_bre(), p_ere(), p_str(), parse::pbegin, parse::pend, pluscount(), regex_t::re_endp, regex_t::re_g, regex_t::re_magic, regex_t::re_nsub, REG_ASSERT, REG_ESPACE, REG_EXTENDED, REG_INVARG, REG_NOSPEC, REG_PEND, regfree(), re_guts::setbits, SETERROR, re_guts::sets, parse::slen, parse::ssize, parse::strip, stripsnug(), and THERE.
Referenced by name_init().

Definition at line 939 of file regcomp.c.
References AHEAD, ASTERN, DROP, dupl(), EMIT, parse::error, HERE, INF, INSERT, MAP, N, O_CH, O_PLUS, OCH_, OOR1, OOR2, OPLUS_, REG_ASSERT, REP, SETERROR, THERE, and THERETHERE.
Referenced by p_ere_exp(), and p_simp_re().

| static int samesets | ( | struct re_guts * | g, | |
| int | c1, | |||
| int | c2 | |||
| ) | [static] |
Definition at line 1232 of file regcomp.c.
References re_guts::ncsets, and re_guts::setbits.
Referenced by categorize().
| static int seterr | ( | struct parse * | p, | |
| int | e | |||
| ) | [static] |
Definition at line 1009 of file regcomp.c.
References parse::end, parse::error, parse::next, and nuls.
Definition at line 1392 of file regcomp.c.
References re_guts::nstates, REG_ESPACE, SETERROR, parse::slen, parse::strip, and re_guts::strip.
Referenced by regcomp().
1.6.3