]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bregex.h
15Apr06
[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 #ifndef REGEXPR_H
28 #define REGEXPR_H
29
30 /* If we pull in this header, make sure we only get our own library
31  *  bregex.c 
32  */
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
49
50
51 #define RE_NREGS        100  /* number of registers available */
52
53 #define regoff_t int
54
55 typedef struct {
56    regoff_t rm_so;
57    regoff_t rm_eo;
58 } regmatch_t;
59
60
61 #define REG_EXTENDED (1<<1)
62 #define REG_ICASE    (1<<2)
63 #define REG_NOSUB    (1<<3)
64 #define REG_NEWLINE  (1<<4)
65
66 #define REG_NOMATCH -1
67
68 struct regex_t
69 {
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 */
80    char *errmsg;
81 };        
82
83
84 typedef struct re_registers
85 {
86    int start[RE_NREGS];  /* start offset of region */
87    int end[RE_NREGS];    /* end offset of region */
88 } *regexp_registers_t;
89
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 */
99
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
105
106 #define Sword       1
107 #define Swhitespace 2
108 #define Sdigit      4
109 #define Soctaldigit 8
110 #define Shexdigit   16
111
112 /* Rename all exported symbols to avoid conflicts with similarly named
113    symbols in some systems' standard C libraries... */
114
115
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. */
119
120 extern unsigned char re_syntax_table[256];
121
122 void re_compile_initialize(void);
123
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. */
127
128 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. */
136
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
142  * encountered. */
143
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. */
153
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. */
158
159
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, 
164                 size_t errbuf_size);
165 void regfree(regex_t *preg);
166
167 #endif /* REGEXPR_H */
168
169
170
171 #ifdef __cplusplus
172 }
173 #endif
174 #endif /* !b_REGEXPR_H */