]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bregex.h
Remove obsolete .cvsignore files.
[bacula/bacula] / bacula / src / lib / bregex.h
1
2 #ifndef b_REGEXPR_H
3 #define b_REGEXPR_H
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7
8 /*
9  * regexpr.h
10  *
11  * Author: Tatu Ylonen <ylo@ngs.fi>
12  *
13  * Copyright (c) 1991 Tatu Ylonen, Espoo, Finland
14  *
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.
19  *
20  * Created: Thu Sep 26 17:15:36 1991 ylo
21  * Last modified: Mon Nov  4 15:49:46 1991 ylo
22  *
23  *  Modified to work with C++ for use in Bacula,           
24  *     Kern Sibbald April, 2006
25  */ 
26 /*
27    Bacula® - The Network Backup Solution
28
29    Copyright (C) 2006-2006 Free Software Foundation Europe e.V.
30
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 two of the GNU General Public
35    License as published by the Free Software Foundation plus additions
36    that are listed in the file LICENSE.
37
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.
42
43    You should have received a copy of the GNU 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
46    02110-1301, USA.
47
48    Bacula® is a registered trademark of John Walker.
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.
52 */
53
54 #ifndef REGEXPR_H
55 #define REGEXPR_H
56
57 /* If we pull in this header, make sure we only get our own library
58  *  bregex.c 
59  */
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
76
77
78 #define RE_NREGS        100  /* number of registers available */
79
80 #define regoff_t int
81
82 typedef struct {
83    regoff_t rm_so;
84    regoff_t rm_eo;
85 } regmatch_t;
86
87
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)
93
94 #define REG_NOMATCH -1
95
96 struct regex_t
97 {
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 */
108    char *errmsg;
109 };        
110
111
112 typedef struct re_registers
113 {
114    int start[RE_NREGS];  /* start offset of region */
115    int end[RE_NREGS];    /* end offset of region */
116 } *regexp_registers_t;
117
118 /* bit definitions for syntax */
119 #define RE_NO_BK_PARENS         1    /* no quoting for parentheses */
120 #define RE_NO_BK_VBAR           2    /* no quoting for vertical bar */
121 #define RE_BK_PLUS_QM           4    /* quoting needed for + and ? */
122 #define RE_TIGHT_VBAR           8    /* | binds tighter than ^ and $ */
123 #define RE_NEWLINE_OR           16   /* treat newline as or */
124 #define RE_CONTEXT_INDEP_OPS    32   /* ^$?*+ are special in all contexts */
125 #define RE_ANSI_HEX             64   /* ansi sequences (\n etc) and \xhh */
126 #define RE_NO_GNU_EXTENSIONS   128   /* no gnu extensions */
127
128 /* definitions for some common regexp styles */
129 #define RE_SYNTAX_AWK   (RE_NO_BK_PARENS|RE_NO_BK_VBAR|RE_CONTEXT_INDEP_OPS)
130 #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK|RE_NEWLINE_OR)
131 #define RE_SYNTAX_GREP  (RE_BK_PLUS_QM|RE_NEWLINE_OR)
132 #define RE_SYNTAX_EMACS 0
133
134 #define Sword       1
135 #define Swhitespace 2
136 #define Sdigit      4
137 #define Soctaldigit 8
138 #define Shexdigit   16
139
140 /* Rename all exported symbols to avoid conflicts with similarly named
141    symbols in some systems' standard C libraries... */
142
143
144 extern int re_syntax;
145 /* This is the actual syntax mask.  It was added so that Python could do
146  * syntax-dependent munging of patterns before compilation. */
147
148 extern unsigned char re_syntax_table[256];
149
150 void re_compile_initialize(void);
151
152 int re_set_syntax(int syntax);
153 /* This sets the syntax to use and returns the previous syntax.  The
154  * syntax is specified by a bit mask of the above defined bits. */
155
156 const char *re_compile_pattern(regex_t *compiled, unsigned char *regex);
157 /* This compiles the regexp (given in regex and length in regex_size).
158  * This returns NULL if the regexp compiled successfully, and an error
159  * message if an error was encountered.  The buffer field must be
160  * initialized to a memory area allocated by malloc (or to NULL) before
161  * use, and the allocated field must be set to its length (or 0 if
162  * buffer is NULL).  Also, the translate field must be set to point to a
163  * valid translation table, or NULL if it is not used. */
164
165 int re_match(regex_t *compiled, unsigned char *string, int size, int pos,
166              regexp_registers_t old_regs);
167 /* This tries to match the regexp against the string.  This returns the
168  * length of the matched portion, or -1 if the pattern could not be
169  * matched and -2 if an error (such as failure stack overflow) is
170  * encountered. */
171
172 int re_search(regex_t *compiled, unsigned char *string, int size, int startpos,
173               int range, regexp_registers_t regs);
174 /* This searches for a substring matching the regexp.  This returns the
175  * first index at which a match is found.  range specifies at how many
176  * positions to try matching; positive values indicate searching
177  * forwards, and negative values indicate searching backwards.  mstop
178  * specifies the offset beyond which a match must not go.  This returns
179  * -1 if no match is found, and -2 if an error (such as failure stack
180  * overflow) is encountered. */
181
182 void re_compile_fastmap(regex_t *compiled);
183 /* This computes the fastmap for the regexp.  For this to have any effect,
184  * the calling program must have initialized the fastmap field to point
185  * to an array of 256 characters. */
186
187
188 int regcomp(regex_t *preg, const char *regex, int cflags);
189 int regexec(regex_t *preg, const char *string, size_t nmatch,
190             regmatch_t pmatch[], int eflags);
191 size_t regerror(int errcode, regex_t *preg, char *errbuf, 
192                 size_t errbuf_size);
193 void regfree(regex_t *preg);
194
195 #endif /* REGEXPR_H */
196
197
198
199 #ifdef __cplusplus
200 }
201 #endif
202 #endif /* !b_REGEXPR_H */