4 /** regexp(3)-compatible regular expression implementation for Jim.
6 * See jimregexp.c for details
21 * The "internal use only" fields in regexp.h are present to pass info from
22 * compile to execute that permits the execute phase to run lots faster on
23 * simple cases. They are:
25 * regstart char that must begin a match; '\0' if none obvious
26 * reganch is the match anchored (at beginning-of-line only)?
27 * regmust string (pointer into program) that match must include, or NULL
28 * regmlen length of regmust string
30 * Regstart and reganch permit very fast decisions on suitable starting points
31 * for a match, cutting down the work a lot. Regmust permits fast rejection
32 * of lines that cannot possibly match. The regmust tests are costly enough
33 * that regcomp() supplies a regmust only if the r.e. contains something
34 * potentially expensive (at present, the only such thing detected is * or +
35 * at the start of the r.e., which can involve a lot of backup). Regmlen is
36 * supplied because the test in regexec() needs it and regcomp() is computing
40 typedef struct regexp
{
42 int re_nsub
; /* number of parenthesized subexpressions */
45 int cflags
; /* Flags used when compiling */
46 int err
; /* Any error which occurred during compile */
47 int regstart
; /* Internal use only. */
48 int reganch
; /* Internal use only. */
49 int regmust
; /* Internal use only. */
50 int regmlen
; /* Internal use only. */
51 int *program
; /* Allocated */
53 /* working state - compile */
54 const char *regparse
; /* Input-scan pointer. */
55 int p
; /* Current output pos in program */
56 int proglen
; /* Allocated program size */
58 /* working state - exec */
59 int eflags
; /* Flags used when executing */
60 const char *start
; /* Initial string pointer. */
61 const char *reginput
; /* Current input pointer. */
62 const char *regbol
; /* Beginning of input, for ^ check. */
64 /* Input to regexec() */
65 regmatch_t
*pmatch
; /* submatches will be stored here */
66 int nmatch
; /* size of pmatch[] */
69 typedef regexp regex_t
;
71 #define REG_EXTENDED 0
78 REG_NOERROR
, /* Success. */
79 REG_NOMATCH
, /* Didn't find a match (for regexec). */
80 REG_BADPAT
, /* >= REG_BADPAT is an error */
81 REG_ERR_NULL_ARGUMENT
,
85 REG_ERR_TOO_MANY_PAREN
,
86 REG_ERR_UNMATCHED_PAREN
,
87 REG_ERR_UNMATCHED_BRACES
,
90 REG_ERR_OPERAND_COULD_BE_EMPTY
,
93 REG_ERR_COUNT_FOLLOWS_NOTHING
,
94 REG_ERR_TRAILING_BACKSLASH
,
100 int regcomp(regex_t
*preg
, const char *regex
, int cflags
);
101 int regexec(regex_t
*preg
, const char *string
, size_t nmatch
, regmatch_t pmatch
[], int eflags
);
102 size_t regerror(int errcode
, const regex_t
*preg
, char *errbuf
, size_t errbuf_size
);
103 void regfree(regex_t
*preg
);