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
27 Bacula® - The Network Backup Solution
29 Copyright (C) 2006-2010 Free Software Foundation Europe e.V.
31 The main author of Bacula is Kern Sibbald, with contributions from
32 many others, a complete list can be found in the file AUTHORS.
33 This program is Free Software; you can redistribute it and/or
34 modify it under the terms of version three of the GNU Affero General Public
35 License as published by the Free Software Foundation and included
38 This program is distributed in the hope that it will be useful, but
39 WITHOUT ANY WARRANTY; without even the implied warranty of
40 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41 General Public License for more details.
43 You should have received a copy of the GNU Affero General Public License
44 along with this program; if not, write to the Free Software
45 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
48 Bacula® is a registered trademark of Kern Sibbald.
49 The licensor of Bacula is the Free Software Foundation Europe
50 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
51 Switzerland, email:ftf@fsfeurope.org.
57 /* If we pull in this header, make sure we only get our own library
60 #define regex_t b_regex_t
61 #define regmatch_t b_regmatch_t
62 #define re_syntax b_re_syntax
63 #define re_syntax_table b_re_syntax_table
64 #define re_compile_initialize b_re_compile_initialize
65 #define re_set_syntax b_re_set_syntax
66 #define re_compile_pattern b_re_compile_pattern
67 #define re_match b_re_match
68 #define re_search b_re_search
69 #define re_compile_fastmap b_re_compile_fastmap
70 #define re_comp b_re_comp
71 #define re_exec b_re_exec
72 #define regcomp b_regcomp
73 #define regexec b_regexec
74 #define regerror b_regerror
75 #define regfree b_regfree
78 #define RE_NREGS 100 /* number of registers available */
88 #define REG_EXTENDED (1<<1)
89 #define REG_ICASE (1<<2)
90 #define REG_NOSUB (1<<3)
91 #define REG_NEWLINE (1<<4)
92 #define REG_NOTBOL (1<<5)
94 #define REG_NOMATCH -1
98 unsigned char *buffer; /* compiled pattern */
99 int allocated; /* allocated size of compiled pattern */
100 int used; /* actual length of compiled pattern */
101 unsigned char *fastmap; /* fastmap[ch] is true if ch can start pattern */
102 unsigned char *translate; /* translation to apply during compilation/matching */
103 unsigned char fastmap_accurate; /* true if fastmap is valid */
104 unsigned char can_be_null; /* true if can match empty string */
105 unsigned char uses_registers; /* registers are used and need to be initialized */
106 int num_registers; /* number of registers used */
107 unsigned char anchor; /* anchor: 0=none 1=begline 2=begbuf */
109 int cflags; /* compilation flags */
110 POOLMEM *lcase; /* used by REG_ICASE */
114 typedef struct re_registers
116 int start[RE_NREGS]; /* start offset of region */
117 int end[RE_NREGS]; /* end offset of region */
118 } *regexp_registers_t;
120 /* bit definitions for syntax */
121 #define RE_NO_BK_PARENS 1 /* no quoting for parentheses */
122 #define RE_NO_BK_VBAR 2 /* no quoting for vertical bar */
123 #define RE_BK_PLUS_QM 4 /* quoting needed for + and ? */
124 #define RE_TIGHT_VBAR 8 /* | binds tighter than ^ and $ */
125 #define RE_NEWLINE_OR 16 /* treat newline as or */
126 #define RE_CONTEXT_INDEP_OPS 32 /* ^$?*+ are special in all contexts */
127 #define RE_ANSI_HEX 64 /* ansi sequences (\n etc) and \xhh */
128 #define RE_NO_GNU_EXTENSIONS 128 /* no gnu extensions */
130 /* definitions for some common regexp styles */
131 #define RE_SYNTAX_AWK (RE_NO_BK_PARENS|RE_NO_BK_VBAR|RE_CONTEXT_INDEP_OPS)
132 #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK|RE_NEWLINE_OR)
133 #define RE_SYNTAX_GREP (RE_BK_PLUS_QM|RE_NEWLINE_OR)
134 #define RE_SYNTAX_EMACS 0
137 #define Swhitespace 2
139 #define Soctaldigit 8
142 /* Rename all exported symbols to avoid conflicts with similarly named
143 symbols in some systems' standard C libraries... */
146 extern int re_syntax;
147 /* This is the actual syntax mask. It was added so that Python could do
148 * syntax-dependent munging of patterns before compilation. */
150 extern unsigned char re_syntax_table[256];
152 void re_compile_initialize(void);
154 int re_set_syntax(int syntax);
155 /* This sets the syntax to use and returns the previous syntax. The
156 * syntax is specified by a bit mask of the above defined bits. */
158 const char *re_compile_pattern(regex_t *compiled, unsigned char *regex);
159 /* This compiles the regexp (given in regex and length in regex_size).
160 * This returns NULL if the regexp compiled successfully, and an error
161 * message if an error was encountered. The buffer field must be
162 * initialized to a memory area allocated by malloc (or to NULL) before
163 * use, and the allocated field must be set to its length (or 0 if
164 * buffer is NULL). Also, the translate field must be set to point to a
165 * valid translation table, or NULL if it is not used. */
167 int re_match(regex_t *compiled, unsigned char *string, int size, int pos,
168 regexp_registers_t old_regs);
169 /* This tries to match the regexp against the string. This returns the
170 * length of the matched portion, or -1 if the pattern could not be
171 * matched and -2 if an error (such as failure stack overflow) is
174 int re_search(regex_t *compiled, unsigned char *string, int size, int startpos,
175 int range, regexp_registers_t regs);
176 /* This searches for a substring matching the regexp. This returns the
177 * first index at which a match is found. range specifies at how many
178 * positions to try matching; positive values indicate searching
179 * forwards, and negative values indicate searching backwards. mstop
180 * specifies the offset beyond which a match must not go. This returns
181 * -1 if no match is found, and -2 if an error (such as failure stack
182 * overflow) is encountered. */
184 void re_compile_fastmap(regex_t *compiled);
185 /* This computes the fastmap for the regexp. For this to have any effect,
186 * the calling program must have initialized the fastmap field to point
187 * to an array of 256 characters. */
190 int regcomp(regex_t *preg, const char *regex, int cflags);
191 int regexec(regex_t *preg, const char *string, size_t nmatch,
192 regmatch_t pmatch[], int eflags);
193 size_t regerror(int errcode, regex_t *preg, char *errbuf,
195 void regfree(regex_t *preg);
197 #endif /* REGEXPR_H */
204 #endif /* !b_REGEXPR_H */