fixed pkg-config rule
[k8jam.git] / src / hsregexp.h
blob382b60f259f5d2324e7a2ce24376858e79b7e6dc
1 /*
2 * definitions etc. for regexp(3) routines
4 * caveat: this is V8 regexp(3) [actually, a reimplementation thereof], not the System V one
6 * 11/04/02 (seiwald) - const-ing for string literals
7 */
8 #ifndef HEADER_LIBHSRX_H
9 #define HEADER_LIBHSRX_H
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
15 #include <stdlib.h>
19 * The "internal use only" fields in regexp.h are present to pass info from
20 * compile to execute that permits the execute phase to run lots faster on
21 * simple cases. They are:
23 * regstart char that must begin a match; '\0' if none obvious
24 * reganch is the match anchored (at beginning-of-line only)?
25 * regmust string (pointer into program) that match must include, or NULL
26 * regmlen length of regmust string
28 * Regstart and reganch permit very fast decisions on suitable starting points
29 * for a match, cutting down the work a lot. Regmust permits fast rejection
30 * of lines that cannot possibly match. The regmust tests are costly enough
31 * that hsrxCompile() supplies a regmust only if the r.e. contains something
32 * potentially expensive (at present, the only such thing detected is * or +
33 * at the start of the r.e., which can involve a lot of backup). Regmlen is
34 * supplied because the test in hsrxExec() needs it and hsrxCompile() is computing
35 * it anyway.
37 typedef struct {
38 int rm_so;
39 int rm_eo;
40 } HSRxMatch;
43 typedef struct HSRegExp {
44 /* -- public -- */
45 int re_nsub; /* number of parenthesized subexpressions */
46 /* -- private -- */
47 int cflags; /* flags used when compiling */
48 int err; /* any error which occurred during compile */
49 int regstart; /* internal use only */
50 int reganch; /* internal use only */
51 int regmust; /* internal use only */
52 int regmlen; /* internal use only */
53 int *program; /* allocated */
54 /* working state - compile */
55 const char *regparse; /* input-scan pointer */
56 int p; /* current output pos in program */
57 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 */
63 /* input to hsrxExec() */
64 HSRxMatch *pmatch; /* submatches will be stored here */
65 int nmatch; /* size of pmatch[] */
66 HSRxMatch *bmatch; /* submatches for backtracing */
67 } HSRegExp;
70 enum {
71 HSRX_EXTENDED = 0x01,
72 HSRX_NEWLINE = 0x02,
73 HSRX_ICASE = 0x04,
74 HSRX_UTF8 = 0x08,
75 HSRX_NOTBOL = 0x10,
76 HSRX_NOTEOL = 0x20
80 enum {
81 HSRX_NOERROR, /* success */
82 HSRX_NOMATCH, /* didn't find a match (for hsrxExec) */
83 HSRX_BADPAT, /* >= HSRX_BADPAT is an error */
84 HSRX_ERR_NULL_ARGUMENT,
85 HSRX_ERR_UNKNOWN,
86 HSRX_ERR_TOO_BIG,
87 HSRX_ERR_NOMEM,
88 HSRX_ERR_TOO_MANY_PAREN,
89 HSRX_ERR_UNMATCHED_PAREN,
90 HSRX_ERR_UNMATCHED_BRACES,
91 HSRX_ERR_BAD_COUNT,
92 HSRX_ERR_JUNK_ON_END,
93 HSRX_ERR_OPERAND_COULD_BE_EMPTY,
94 HSRX_ERR_NESTED_COUNT,
95 HSRX_ERR_INTERNAL,
96 HSRX_ERR_COUNT_FOLLOWS_NOTHING,
97 HSRX_ERR_TRAILING_BACKSLASH,
98 HSRX_ERR_CORRUPTED,
99 HSRX_ERR_NULL_CHAR,
100 HSRX_ERR_INVALID_BACKREF,
101 HSRX_ERR_NUM
105 extern int hsrxCompile (HSRegExp *preg, const char *regex, int cflags);
106 extern int hsrxExec (HSRegExp *preg, const char *string, size_t nmatch, HSRxMatch pmatch[], int eflags);
107 //eflags:
108 // HSRX_NEWLINE
109 // HSRX_NOTBOL
110 extern size_t hsrxError (int errcode, const HSRegExp *preg, char *errbuf, size_t errbuf_size);
111 extern void hsrxFree (HSRegExp *preg);
114 #ifdef HSRX_DEBUG
115 extern int hsrxNarrate;
116 extern void hsrxDump (HSRegExp *preg);
117 #endif
120 #ifdef __cplusplus
122 #endif
123 #endif