event.test: Fix test on Haiku
[jimtcl.git] / jimregexp.h
blobb7598d4b3ae1113c2bcea3da2a03ea8e75548b8b
1 #ifndef JIMREGEXP_H
2 #define JIMREGEXP_H
4 /** regexp(3)-compatible regular expression implementation for Jim.
6 * See jimregexp.c for details
7 */
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
13 #include <stdlib.h>
15 typedef struct {
16 int rm_so;
17 int rm_eo;
18 } regmatch_t;
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
37 * it anyway.
40 typedef struct regexp {
41 /* -- public -- */
42 int re_nsub; /* number of parenthesized subexpressions */
44 /* -- private -- */
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[] */
67 } regexp;
69 typedef regexp regex_t;
71 #define REG_EXTENDED 0
72 #define REG_NEWLINE 1
73 #define REG_ICASE 2
75 #define REG_NOTBOL 16
77 enum {
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,
82 REG_ERR_UNKNOWN,
83 REG_ERR_TOO_BIG,
84 REG_ERR_NOMEM,
85 REG_ERR_TOO_MANY_PAREN,
86 REG_ERR_UNMATCHED_PAREN,
87 REG_ERR_UNMATCHED_BRACES,
88 REG_ERR_BAD_COUNT,
89 REG_ERR_JUNK_ON_END,
90 REG_ERR_OPERAND_COULD_BE_EMPTY,
91 REG_ERR_NESTED_COUNT,
92 REG_ERR_INTERNAL,
93 REG_ERR_COUNT_FOLLOWS_NOTHING,
94 REG_ERR_TRAILING_BACKSLASH,
95 REG_ERR_CORRUPTED,
96 REG_ERR_NULL_CHAR,
97 REG_ERR_NUM
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);
105 #ifdef __cplusplus
107 #endif
109 #endif