usbmodeswitch: Updated to v.1.2.6 from shibby's branch.
[tomato.git] / release / src / router / usbmodeswitch / jim / jimregexp.h
blob79a87e5f6802e43d5b420d85d83d7ef4293060d3
1 #ifndef JIMREGEXP_H
2 #define JIMREGEXP_H
4 #ifndef _JIMAUTOCONF_H
5 #error Need jimautoconf.h
6 #endif
8 #if defined(HAVE_REGCOMP) && !defined(JIM_REGEXP)
9 /* Use POSIX regex */
10 #include <regex.h>
12 #else
14 #include <stdlib.h>
17 * Definitions etc. for regexp(3) routines.
19 * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof],
20 * not the System V one.
22 * 11/04/02 (seiwald) - const-ing for string literals
25 typedef struct {
26 int rm_so;
27 int rm_eo;
28 } regmatch_t;
31 * The "internal use only" fields in regexp.h are present to pass info from
32 * compile to execute that permits the execute phase to run lots faster on
33 * simple cases. They are:
35 * regstart char that must begin a match; '\0' if none obvious
36 * reganch is the match anchored (at beginning-of-line only)?
37 * regmust string (pointer into program) that match must include, or NULL
38 * regmlen length of regmust string
40 * Regstart and reganch permit very fast decisions on suitable starting points
41 * for a match, cutting down the work a lot. Regmust permits fast rejection
42 * of lines that cannot possibly match. The regmust tests are costly enough
43 * that regcomp() supplies a regmust only if the r.e. contains something
44 * potentially expensive (at present, the only such thing detected is * or +
45 * at the start of the r.e., which can involve a lot of backup). Regmlen is
46 * supplied because the test in regexec() needs it and regcomp() is computing
47 * it anyway.
50 typedef struct regexp {
51 /* -- public -- */
52 int re_nsub; /* number of parenthesized subexpressions */
54 /* -- private -- */
55 int cflags; /* Flags used when compiling */
56 int err; /* Any error which occurred during compile */
57 int regstart; /* Internal use only. */
58 int reganch; /* Internal use only. */
59 int regmust; /* Internal use only. */
60 int regmlen; /* Internal use only. */
61 int *program; /* Allocated */
63 /* working state - compile */
64 const char *regparse; /* Input-scan pointer. */
65 int p; /* Current output pos in program */
66 int proglen; /* Allocated program size */
68 /* working state - exec */
69 int eflags; /* Flags used when executing */
70 const char *start; /* Initial string pointer. */
71 const char *reginput; /* Current input pointer. */
72 const char *regbol; /* Beginning of input, for ^ check. */
74 /* Input to regexec() */
75 regmatch_t *pmatch; /* submatches will be stored here */
76 int nmatch; /* size of pmatch[] */
77 } regexp;
79 typedef regexp regex_t;
81 #define REG_EXTENDED 0
82 #define REG_NEWLINE 1
83 #define REG_ICASE 2
85 #define REG_NOTBOL 16
87 enum {
88 REG_NOERROR, /* Success. */
89 REG_NOMATCH, /* Didn't find a match (for regexec). */
90 REG_BADPAT, /* >= REG_BADPAT is an error */
91 REG_ERR_NULL_ARGUMENT,
92 REG_ERR_UNKNOWN,
93 REG_ERR_TOO_BIG,
94 REG_ERR_NOMEM,
95 REG_ERR_TOO_MANY_PAREN,
96 REG_ERR_UNMATCHED_PAREN,
97 REG_ERR_UNMATCHED_BRACES,
98 REG_ERR_BAD_COUNT,
99 REG_ERR_JUNK_ON_END,
100 REG_ERR_OPERAND_COULD_BE_EMPTY,
101 REG_ERR_NESTED_COUNT,
102 REG_ERR_INTERNAL,
103 REG_ERR_COUNT_FOLLOWS_NOTHING,
104 REG_ERR_TRAILING_BACKSLASH,
105 REG_ERR_CORRUPTED,
106 REG_ERR_NULL_CHAR,
107 REG_ERR_NUM
110 int regcomp(regex_t *preg, const char *regex, int cflags);
111 int regexec(regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);
112 size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size);
113 void regfree(regex_t *preg);
115 #endif
117 #endif