2 #ifndef __b_REGEXPR_H__
3 #define __b_REGEXPR_H__
12 * Author: Tatu Ylonen <ylo@ngs.fi>
14 * Copyright (c) 1991 Tatu Ylonen, Espoo, Finland
16 * Permission to use, copy, modify, distribute, and sell this software
17 * and its documentation for any purpose is hereby granted without fee,
18 * provided that the above copyright notice appear in all copies. This
19 * software is provided "as is" without express or implied warranty.
21 * Created: Thu Sep 26 17:15:36 1991 ylo
22 * Last modified: Mon Nov 4 15:49:46 1991 ylo
24 * Modified to work with C++ for use in Bacula,
25 * Kern Sibbald April, 2006
28 Bacula(R) - The Network Backup Solution
30 Copyright (C) 2000-2016 Kern Sibbald
32 The original author of Bacula is Kern Sibbald, with contributions
33 from many others, a complete list can be found in the file AUTHORS.
35 You may use this file and others of this release according to the
36 license defined in the LICENSE file, which includes the Affero General
37 Public License, v3.0 ("AGPLv3") and some additional permissions and
38 terms pursuant to its AGPLv3 Section 7.
40 This notice must be preserved when any source code is
41 conveyed and/or propagated.
43 Bacula(R) is a registered trademark of Kern Sibbald.
49 /* If we pull in this header, make sure we only get our own library
52 #define regex_t b_regex_t
53 #define regmatch_t b_regmatch_t
54 #define re_syntax b_re_syntax
55 #define re_syntax_table b_re_syntax_table
56 #define re_compile_initialize b_re_compile_initialize
57 #define re_set_syntax b_re_set_syntax
58 #define re_compile_pattern b_re_compile_pattern
59 #define re_match b_re_match
60 #define re_search b_re_search
61 #define re_compile_fastmap b_re_compile_fastmap
62 #define re_comp b_re_comp
63 #define re_exec b_re_exec
64 #define regcomp b_regcomp
65 #define regexec b_regexec
66 #define regerror b_regerror
67 #define regfree b_regfree
70 #define RE_NREGS 100 /* number of registers available */
80 #define REG_EXTENDED (1<<1)
81 #define REG_ICASE (1<<2)
82 #define REG_NOSUB (1<<3)
83 #define REG_NEWLINE (1<<4)
84 #define REG_NOTBOL (1<<5)
86 #define REG_NOMATCH -1
90 unsigned char *buffer; /* compiled pattern */
91 int allocated; /* allocated size of compiled pattern */
92 int used; /* actual length of compiled pattern */
93 unsigned char *fastmap; /* fastmap[ch] is true if ch can start pattern */
94 unsigned char *translate; /* translation to apply during compilation/matching */
95 unsigned char fastmap_accurate; /* true if fastmap is valid */
96 unsigned char can_be_null; /* true if can match empty string */
97 unsigned char uses_registers; /* registers are used and need to be initialized */
98 int num_registers; /* number of registers used */
99 unsigned char anchor; /* anchor: 0=none 1=begline 2=begbuf */
101 int cflags; /* compilation flags */
102 POOLMEM *lcase; /* used by REG_ICASE */
106 typedef struct re_registers
108 int start[RE_NREGS]; /* start offset of region */
109 int end[RE_NREGS]; /* end offset of region */
110 } *regexp_registers_t;
112 /* bit definitions for syntax */
113 #define RE_NO_BK_PARENS 1 /* no quoting for parentheses */
114 #define RE_NO_BK_VBAR 2 /* no quoting for vertical bar */
115 #define RE_BK_PLUS_QM 4 /* quoting needed for + and ? */
116 #define RE_TIGHT_VBAR 8 /* | binds tighter than ^ and $ */
117 #define RE_NEWLINE_OR 16 /* treat newline as or */
118 #define RE_CONTEXT_INDEP_OPS 32 /* ^$?*+ are special in all contexts */
119 #define RE_ANSI_HEX 64 /* ansi sequences (\n etc) and \xhh */
120 #define RE_NO_GNU_EXTENSIONS 128 /* no gnu extensions */
122 /* definitions for some common regexp styles */
123 #define RE_SYNTAX_AWK (RE_NO_BK_PARENS|RE_NO_BK_VBAR|RE_CONTEXT_INDEP_OPS)
124 #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK|RE_NEWLINE_OR)
125 #define RE_SYNTAX_GREP (RE_BK_PLUS_QM|RE_NEWLINE_OR)
126 #define RE_SYNTAX_EMACS 0
129 #define Swhitespace 2
131 #define Soctaldigit 8
134 /* Rename all exported symbols to avoid conflicts with similarly named
135 symbols in some systems' standard C libraries... */
138 extern int re_syntax;
139 /* This is the actual syntax mask. It was added so that Python could do
140 * syntax-dependent munging of patterns before compilation. */
142 extern unsigned char re_syntax_table[256];
144 void re_compile_initialize(void);
146 int re_set_syntax(int syntax);
147 /* This sets the syntax to use and returns the previous syntax. The
148 * syntax is specified by a bit mask of the above defined bits. */
150 const char *re_compile_pattern(regex_t *compiled, unsigned char *regex);
151 /* This compiles the regexp (given in regex and length in regex_size).
152 * This returns NULL if the regexp compiled successfully, and an error
153 * message if an error was encountered. The buffer field must be
154 * initialized to a memory area allocated by malloc (or to NULL) before
155 * use, and the allocated field must be set to its length (or 0 if
156 * buffer is NULL). Also, the translate field must be set to point to a
157 * valid translation table, or NULL if it is not used. */
159 int re_match(regex_t *compiled, unsigned char *string, int size, int pos,
160 regexp_registers_t old_regs);
161 /* This tries to match the regexp against the string. This returns the
162 * length of the matched portion, or -1 if the pattern could not be
163 * matched and -2 if an error (such as failure stack overflow) is
166 int re_search(regex_t *compiled, unsigned char *string, int size, int startpos,
167 int range, regexp_registers_t regs);
168 /* This searches for a substring matching the regexp. This returns the
169 * first index at which a match is found. range specifies at how many
170 * positions to try matching; positive values indicate searching
171 * forwards, and negative values indicate searching backwards. mstop
172 * specifies the offset beyond which a match must not go. This returns
173 * -1 if no match is found, and -2 if an error (such as failure stack
174 * overflow) is encountered. */
176 void re_compile_fastmap(regex_t *compiled);
177 /* This computes the fastmap for the regexp. For this to have any effect,
178 * the calling program must have initialized the fastmap field to point
179 * to an array of 256 characters. */
182 int regcomp(regex_t *preg, const char *regex, int cflags);
183 int regexec(regex_t *preg, const char *string, size_t nmatch,
184 regmatch_t pmatch[], int eflags);
185 size_t regerror(int errcode, regex_t *preg, char *errbuf,
187 void regfree(regex_t *preg);
189 #endif /* REGEXPR_H */
196 #endif /* !__b_REGEXPR_H__ */