11 * Author: Tatu Ylonen <ylo@ngs.fi>
13 * Copyright (c) 1991 Tatu Ylonen, Espoo, Finland
15 * Permission to use, copy, modify, distribute, and sell this software
16 * and its documentation for any purpose is hereby granted without fee,
17 * provided that the above copyright notice appear in all copies. This
18 * software is provided "as is" without express or implied warranty.
20 * Created: Thu Sep 26 17:15:36 1991 ylo
21 * Last modified: Mon Nov 4 15:49:46 1991 ylo
23 * Modified to work with C++ for use in Bacula,
24 * Kern Sibbald April, 2006
30 /* If we pull in this header, make sure we only get our own library
33 #define regex_t b_regex_t
34 #define regmatch_t b_regmatch_t
35 #define re_syntax b_re_syntax
36 #define re_syntax_table b_re_syntax_table
37 #define re_compile_initialize b_re_compile_initialize
38 #define re_set_syntax b_re_set_syntax
39 #define re_compile_pattern b_re_compile_pattern
40 #define re_match b_re_match
41 #define re_search b_re_search
42 #define re_compile_fastmap b_re_compile_fastmap
43 #define re_comp b_re_comp
44 #define re_exec b_re_exec
45 #define regcomp b_regcomp
46 #define regexec b_regexec
47 #define regerror b_regerror
48 #define regfree b_regfree
51 #define RE_NREGS 100 /* number of registers available */
61 #define REG_EXTENDED (1<<1)
62 #define REG_ICASE (1<<2)
63 #define REG_NOSUB (1<<3)
64 #define REG_NEWLINE (1<<4)
66 #define REG_NOMATCH -1
70 unsigned char *buffer; /* compiled pattern */
71 int allocated; /* allocated size of compiled pattern */
72 int used; /* actual length of compiled pattern */
73 unsigned char *fastmap; /* fastmap[ch] is true if ch can start pattern */
74 unsigned char *translate; /* translation to apply during compilation/matching */
75 unsigned char fastmap_accurate; /* true if fastmap is valid */
76 unsigned char can_be_null; /* true if can match empty string */
77 unsigned char uses_registers; /* registers are used and need to be initialized */
78 int num_registers; /* number of registers used */
79 unsigned char anchor; /* anchor: 0=none 1=begline 2=begbuf */
84 typedef struct re_registers
86 int start[RE_NREGS]; /* start offset of region */
87 int end[RE_NREGS]; /* end offset of region */
88 } *regexp_registers_t;
90 /* bit definitions for syntax */
91 #define RE_NO_BK_PARENS 1 /* no quoting for parentheses */
92 #define RE_NO_BK_VBAR 2 /* no quoting for vertical bar */
93 #define RE_BK_PLUS_QM 4 /* quoting needed for + and ? */
94 #define RE_TIGHT_VBAR 8 /* | binds tighter than ^ and $ */
95 #define RE_NEWLINE_OR 16 /* treat newline as or */
96 #define RE_CONTEXT_INDEP_OPS 32 /* ^$?*+ are special in all contexts */
97 #define RE_ANSI_HEX 64 /* ansi sequences (\n etc) and \xhh */
98 #define RE_NO_GNU_EXTENSIONS 128 /* no gnu extensions */
100 /* definitions for some common regexp styles */
101 #define RE_SYNTAX_AWK (RE_NO_BK_PARENS|RE_NO_BK_VBAR|RE_CONTEXT_INDEP_OPS)
102 #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK|RE_NEWLINE_OR)
103 #define RE_SYNTAX_GREP (RE_BK_PLUS_QM|RE_NEWLINE_OR)
104 #define RE_SYNTAX_EMACS 0
107 #define Swhitespace 2
109 #define Soctaldigit 8
112 /* Rename all exported symbols to avoid conflicts with similarly named
113 symbols in some systems' standard C libraries... */
116 extern int re_syntax;
117 /* This is the actual syntax mask. It was added so that Python could do
118 * syntax-dependent munging of patterns before compilation. */
120 extern unsigned char re_syntax_table[256];
122 void re_compile_initialize(void);
124 int re_set_syntax(int syntax);
125 /* This sets the syntax to use and returns the previous syntax. The
126 * syntax is specified by a bit mask of the above defined bits. */
128 const char *re_compile_pattern(regex_t *compiled, unsigned char *regex);
129 /* This compiles the regexp (given in regex and length in regex_size).
130 * This returns NULL if the regexp compiled successfully, and an error
131 * message if an error was encountered. The buffer field must be
132 * initialized to a memory area allocated by malloc (or to NULL) before
133 * use, and the allocated field must be set to its length (or 0 if
134 * buffer is NULL). Also, the translate field must be set to point to a
135 * valid translation table, or NULL if it is not used. */
137 int re_match(regex_t *compiled, unsigned char *string, int size, int pos,
138 regexp_registers_t old_regs);
139 /* This tries to match the regexp against the string. This returns the
140 * length of the matched portion, or -1 if the pattern could not be
141 * matched and -2 if an error (such as failure stack overflow) is
144 int re_search(regex_t *compiled, unsigned char *string, int size, int startpos,
145 int range, regexp_registers_t regs);
146 /* This searches for a substring matching the regexp. This returns the
147 * first index at which a match is found. range specifies at how many
148 * positions to try matching; positive values indicate searching
149 * forwards, and negative values indicate searching backwards. mstop
150 * specifies the offset beyond which a match must not go. This returns
151 * -1 if no match is found, and -2 if an error (such as failure stack
152 * overflow) is encountered. */
154 void re_compile_fastmap(regex_t *compiled);
155 /* This computes the fastmap for the regexp. For this to have any effect,
156 * the calling program must have initialized the fastmap field to point
157 * to an array of 256 characters. */
160 int regcomp(regex_t *preg, const char *regex, int cflags);
161 int regexec(regex_t *preg, const char *string, size_t nmatch,
162 regmatch_t pmatch[], int eflags);
163 size_t regerror(int errcode, regex_t *preg, char *errbuf,
165 void regfree(regex_t *preg);
167 #endif /* REGEXPR_H */
174 #endif /* !b_REGEXPR_H */