]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bregex.h
Complete port to Windows
[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 #define REG_NOTBOL   (1<<5)
66
67 #define REG_NOMATCH -1
68
69 struct regex_t
70 {
71    unsigned char *buffer;          /* compiled pattern */
72    int allocated;         /* allocated size of compiled pattern */
73    int used;              /* actual length of compiled pattern */
74    unsigned char *fastmap;         /* fastmap[ch] is true if ch can start pattern */
75    unsigned char *translate;       /* translation to apply during compilation/matching */
76    unsigned char fastmap_accurate; /* true if fastmap is valid */
77    unsigned char can_be_null;      /* true if can match empty string */
78    unsigned char uses_registers;   /* registers are used and need to be initialized */
79    int num_registers;     /* number of registers used */
80    unsigned char anchor;           /* anchor: 0=none 1=begline 2=begbuf */
81    char *errmsg;
82 };        
83
84
85 typedef struct re_registers
86 {
87    int start[RE_NREGS];  /* start offset of region */
88    int end[RE_NREGS];    /* end offset of region */
89 } *regexp_registers_t;
90
91 /* bit definitions for syntax */
92 #define RE_NO_BK_PARENS         1    /* no quoting for parentheses */
93 #define RE_NO_BK_VBAR           2    /* no quoting for vertical bar */
94 #define RE_BK_PLUS_QM           4    /* quoting needed for + and ? */
95 #define RE_TIGHT_VBAR           8    /* | binds tighter than ^ and $ */
96 #define RE_NEWLINE_OR           16   /* treat newline as or */
97 #define RE_CONTEXT_INDEP_OPS    32   /* ^$?*+ are special in all contexts */
98 #define RE_ANSI_HEX             64   /* ansi sequences (\n etc) and \xhh */
99 #define RE_NO_GNU_EXTENSIONS   128   /* no gnu extensions */
100
101 /* definitions for some common regexp styles */
102 #define RE_SYNTAX_AWK   (RE_NO_BK_PARENS|RE_NO_BK_VBAR|RE_CONTEXT_INDEP_OPS)
103 #define RE_SYNTAX_EGREP (RE_SYNTAX_AWK|RE_NEWLINE_OR)
104 #define RE_SYNTAX_GREP  (RE_BK_PLUS_QM|RE_NEWLINE_OR)
105 #define RE_SYNTAX_EMACS 0
106
107 #define Sword       1
108 #define Swhitespace 2
109 #define Sdigit      4
110 #define Soctaldigit 8
111 #define Shexdigit   16
112
113 /* Rename all exported symbols to avoid conflicts with similarly named
114    symbols in some systems' standard C libraries... */
115
116
117 extern int re_syntax;
118 /* This is the actual syntax mask.  It was added so that Python could do
119  * syntax-dependent munging of patterns before compilation. */
120
121 extern unsigned char re_syntax_table[256];
122
123 void re_compile_initialize(void);
124
125 int re_set_syntax(int syntax);
126 /* This sets the syntax to use and returns the previous syntax.  The
127  * syntax is specified by a bit mask of the above defined bits. */
128
129 const char *re_compile_pattern(regex_t *compiled, unsigned char *regex);
130 /* This compiles the regexp (given in regex and length in regex_size).
131  * This returns NULL if the regexp compiled successfully, and an error
132  * message if an error was encountered.  The buffer field must be
133  * initialized to a memory area allocated by malloc (or to NULL) before
134  * use, and the allocated field must be set to its length (or 0 if
135  * buffer is NULL).  Also, the translate field must be set to point to a
136  * valid translation table, or NULL if it is not used. */
137
138 int re_match(regex_t *compiled, unsigned char *string, int size, int pos,
139              regexp_registers_t old_regs);
140 /* This tries to match the regexp against the string.  This returns the
141  * length of the matched portion, or -1 if the pattern could not be
142  * matched and -2 if an error (such as failure stack overflow) is
143  * encountered. */
144
145 int re_search(regex_t *compiled, unsigned char *string, int size, int startpos,
146               int range, regexp_registers_t regs);
147 /* This searches for a substring matching the regexp.  This returns the
148  * first index at which a match is found.  range specifies at how many
149  * positions to try matching; positive values indicate searching
150  * forwards, and negative values indicate searching backwards.  mstop
151  * specifies the offset beyond which a match must not go.  This returns
152  * -1 if no match is found, and -2 if an error (such as failure stack
153  * overflow) is encountered. */
154
155 void re_compile_fastmap(regex_t *compiled);
156 /* This computes the fastmap for the regexp.  For this to have any effect,
157  * the calling program must have initialized the fastmap field to point
158  * to an array of 256 characters. */
159
160
161 int regcomp(regex_t *preg, const char *regex, int cflags);
162 int regexec(regex_t *preg, const char *string, size_t nmatch,
163             regmatch_t pmatch[], int eflags);
164 size_t regerror(int errcode, regex_t *preg, char *errbuf, 
165                 size_t errbuf_size);
166 void regfree(regex_t *preg);
167
168 #endif /* REGEXPR_H */
169
170
171
172 #ifdef __cplusplus
173 }
174 #endif
175 #endif /* !b_REGEXPR_H */