1 /* Definitions for data structures callers pass the regex library. 2 3 Copyright (C) 1985, 1989-90 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 1, or (at your option) 8 any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 18 /* Multi-byte extension added May, 1993 by t^2 (Takahiro Tanimoto) 19 Last change: May 21, 1993 by t^2 */ 20 /* modifis for Ruby by matz@caelum.co.jp */ 21 22 #ifndef __REGEXP_LIBRARY 23 #define __REGEXP_LIBRARY 24 25 /* Define number of parens for which we record the beginnings and ends. 26 This affects how much space the `struct re_registers' type takes up. */ 27 #ifndef RE_NREGS 28 #define RE_NREGS 10 29 #endif 30 31 #define BYTEWIDTH 8 32 33 #define RE_REG_MAX ((1<<BYTEWIDTH)-1) 34 35 /* Maximum number of duplicates an interval can allow. */ 36 #ifndef RE_DUP_MAX 37 #define RE_DUP_MAX ((1 << 15) - 1) 38 #endif 39 40 41 /* This defines the various regexp syntaxes. */ 42 extern long re_syntax_options; 43 44 45 /* The following bits are used in the re_syntax_options variable to choose among 46 alternative regexp syntaxes. */ 47 48 /* If this bit is set, plain parentheses serve as grouping, and backslash 49 parentheses are needed for literal searching. 50 If not set, backslash-parentheses are grouping, and plain parentheses 51 are for literal searching. */ 52 #define RE_NO_BK_PARENS 1L 53 54 /* If this bit is set, plain | serves as the `or'-operator, and \| is a 55 literal. 56 If not set, \| serves as the `or'-operator, and | is a literal. */ 57 #define RE_NO_BK_VBAR (1L << 1) 58 59 /* If this bit is set, | binds tighter than ^ or $. 60 If not set, the contrary. */ 61 #define RE_TIGHT_VBAR (1L << 3) 62 63 /* If this bit is set, then treat newline as an OR operator. 64 If not set, treat it as a normal character. */ 65 #define RE_NEWLINE_OR (1L << 4) 66 67 /* If this bit is set, then special characters may act as normal 68 characters in some contexts. Specifically, this applies to: 69 ^ -- only special at the beginning, or after ( or |; 70 $ -- only special at the end, or before ) or |; 71 *, +, ? -- only special when not after the beginning, (, or |. 72 If this bit is not set, special characters (such as *, ^, and $) 73 always have their special meaning regardless of the surrounding 74 context. */ 75 #define RE_CONTEXT_INDEP_OPS (1L << 5) 76 77 /* If this bit is not set, then \ before anything inside [ and ] is taken as 78 a real \. 79 If set, then such a \ escapes the following character. This is a 80 special case for awk. */ 81 #define RE_AWK_CLASS_HACK (1L << 6) 82 83 /* If this bit is set, then \{ and \} or { and } serve as interval operators. 84 If not set, then \{ and \} and { and } are treated as literals. */ 85 #define RE_INTERVALS (1L << 7) 86 87 /* If this bit is not set, then \{ and \} serve as interval operators and 88 { and } are literals. 89 If set, then { and } serve as interval operators and \{ and \} are 90 literals. */ 91 #define RE_NO_BK_CURLY_BRACES (1L << 8) 92 #define RE_NO_BK_BRACES RE_NO_BK_CURLY_BRACES 93 94 /* If this bit is set, then character classes are supported; they are: 95 [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], 96 [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. 97 If not set, then character classes are not supported. */ 98 #define RE_CHAR_CLASSES (1L << 9) 99 100 /* If this bit is set, then the dot re doesn't match a null byte. 101 If not set, it does. */ 102 #define RE_DOT_NOT_NULL (1L << 10) 103 104 /* If this bit is set, then [^...] doesn't match a newline. 105 If not set, it does. */ 106 #define RE_HAT_NOT_NEWLINE (1L << 11) 107 108 /* If this bit is set, back references are recognized. 109 If not set, they aren't. */ 110 #define RE_NO_BK_REFS (1L << 12) 111 112 /* If this bit is set, back references must refer to a preceding 113 subexpression. If not set, a back reference to a nonexistent 114 subexpression is treated as literal characters. */ 115 #define RE_NO_EMPTY_BK_REF (1L << 13) 116 117 /* If this bit is set, bracket expressions can't be empty. 118 If it is set, they can be empty. */ 119 #define RE_NO_EMPTY_BRACKETS (1L << 14) 120 121 /* If this bit is set, then *, +, ? and { cannot be first in an re or 122 immediately after a |, or a (. Furthermore, a | cannot be first or 123 last in an re, or immediately follow another | or a (. Also, a ^ 124 cannot appear in a nonleading position and a $ cannot appear in a 125 nontrailing position (outside of bracket expressions, that is). */ 126 #define RE_CONTEXTUAL_INVALID_OPS (1L << 15) 127 128 /* If this bit is set, then +, ? and | aren't recognized as operators. 129 If it's not, they are. */ 130 #define RE_LIMITED_OPS (1L << 16) 131 132 /* If this bit is set, then an ending range point has to collate higher 133 or equal to the starting range point. 134 If it's not set, then when the ending range point collates higher 135 than the starting range point, the range is just considered empty. */ 136 #define RE_NO_EMPTY_RANGES (1L << 17) 137 138 /* If this bit is set, then a hyphen (-) can't be an ending range point. 139 If it isn't, then it can. */ 140 #define RE_NO_HYPHEN_RANGE_END (1L << 18) 141 142 /* If this bit is not set, then \ inside a bracket expression is literal. 143 If set, then such a \ quotes the following character. */ 144 #define RE_BACKSLASH_ESCAPE_IN_LISTS (1L << 19) 145 146 /* Define combinations of bits for the standard possibilities. */ 147 #define RE_SYNTAX_POSIX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 148 | RE_CONTEXT_INDEP_OPS) 149 #define RE_SYNTAX_AWK (RE_NO_BK_PARENS | RE_NO_BK_VBAR | RE_AWK_CLASS_HACK) 150 #define RE_SYNTAX_EGREP (RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 151 | RE_CONTEXT_INDEP_OPS | RE_NEWLINE_OR) 152 #define RE_SYNTAX_GREP (RE_BK_PLUS_QM | RE_NEWLINE_OR) 153 #define RE_SYNTAX_EMACS 0 154 #define RE_SYNTAX_POSIX_BASIC (RE_INTERVALS | RE_BK_PLUS_QM \ 155 | RE_CHAR_CLASSES | RE_DOT_NOT_NULL \ 156 | RE_HAT_NOT_NEWLINE | RE_NO_EMPTY_BK_REF \ 157 | RE_NO_EMPTY_BRACKETS | RE_LIMITED_OPS \ 158 | RE_NO_EMPTY_RANGES | RE_NO_HYPHEN_RANGE_END) 159 160 #define RE_SYNTAX_POSIX_EXTENDED (RE_INTERVALS | RE_NO_BK_CURLY_BRACES \ 161 | RE_NO_BK_VBAR | RE_NO_BK_PARENS \ 162 | RE_HAT_NOT_NEWLINE | RE_CHAR_CLASSES \ 163 | RE_NO_EMPTY_BRACKETS | RE_CONTEXTUAL_INVALID_OPS \ 164 | RE_NO_BK_REFS | RE_NO_EMPTY_RANGES \ 165 | RE_NO_HYPHEN_RANGE_END) 166 167 #define RE_OPTION_EXTENDED (1L<<0) 168 #define RE_OPTION_IGNORECASE (1L<<1) 169 #define RE_MAY_IGNORECASE (1L<<2) 170 #define RE_OPTIMIZE_ANCHOR (1L<<4) 171 #define RE_OPTIMIZE_EXACTN (1L<<5) 172 #define RE_OPTIMIZE_NO_BM (1L<<6) 173 174 /* For multi-byte char support */ 175 #define MBCTYPE_ASCII 0 176 #define MBCTYPE_EUC 1 177 #define MBCTYPE_SJIS 2 178 179 extern int current_mbctype; 180 181 #ifdef __STDC__ 182 extern const unsigned char *mbctab; 183 void re_mbcinit (int); 184 #else 185 extern unsigned char *mbctab; 186 void re_mbcinit (); 187 #endif 188 189 #undef ismbchar 190 #define ismbchar(c) mbctab[(unsigned char)(c)] 191 192 /* This data structure is used to represent a compiled pattern. */ 193 194 struct re_pattern_buffer 195 { 196 char *buffer; /* Space holding the compiled pattern commands. */ 197 long allocated; /* Size of space that `buffer' points to. */ 198 long used; /* Length of portion of buffer actually occupied */ 199 char *fastmap; /* Pointer to fastmap, if any, or zero if none. */ 200 /* re_search uses the fastmap, if there is one, 201 to skip over totally implausible characters. */ 202 char *must; /* Pointer to exact pattern which strings should have 203 to be matched. */ 204 int *must_skip; /* Pointer to exact pattern skip table for bm_search */ 205 char *stclass; /* Pointer to character class list at top */ 206 long options; /* Flags for options such as extended_pattern. */ 207 long re_nsub; /* Number of subexpressions found by the compiler. */ 208 char fastmap_accurate; 209 /* Set to zero when a new pattern is stored, 210 set to one when the fastmap is updated from it. */ 211 char can_be_null; /* Set to one by compiling fastmap 212 if this pattern might match the null string. 213 It does not necessarily match the null string 214 in that case, but if this is zero, it cannot. 215 2 as value means can match null string 216 but at end of range or before a character 217 listed in the fastmap. */ 218 }; 219 220 221 /* Structure to store register contents data in. 222 223 Pass the address of such a structure as an argument to re_match, etc., 224 if you want this information back. 225 226 For i from 1 to RE_NREGS - 1, start[i] records the starting index in 227 the string of where the ith subexpression matched, and end[i] records 228 one after the ending index. start[0] and end[0] are analogous, for 229 the entire pattern. */ 230 231 struct re_registers 232 { 233 unsigned allocated; 234 unsigned num_regs; 235 int *beg; 236 int *end; 237 }; 238 239 240 241 #ifdef NeXT 242 #define re_match rre_match 243 #endif 244 245 #ifdef __STDC__ 246 247 extern char *re_compile_pattern (char *, size_t, struct re_pattern_buffer *); 248 void re_free_pattern (struct re_pattern_buffer *); 249 /* Is this really advertised? */ 250 extern void re_compile_fastmap (struct re_pattern_buffer *); 251 extern int re_search (struct re_pattern_buffer *, char*, int, int, int, 252 struct re_registers *); 253 extern int re_match (struct re_pattern_buffer *, char *, int, int, 254 struct re_registers *); 255 extern long re_set_syntax (long syntax); 256 extern void re_set_casetable (char *table); 257 extern void re_copy_registers (struct re_registers*, struct re_registers*); 258 extern void re_free_registers (struct re_registers*); 259 260 #ifndef RUBY 261 /* 4.2 bsd compatibility. */ 262 extern char *re_comp (char *); 263 extern int re_exec (char *); 264 #endif 265 266 #else /* !__STDC__ */ 267 268 extern char *re_compile_pattern (); 269 void re_free_regexp (); 270 /* Is this really advertised? */ 271 extern void re_compile_fastmap (); 272 extern int re_search (); 273 extern int re_match (); 274 extern long re_set_syntax (); 275 extern void re_set_casetable (); 276 extern void re_copy_registers (); 277 extern void re_free_registers (); 278 279 #endif /* __STDC__ */ 280 281 282 #ifdef SYNTAX_TABLE 283 extern char *re_syntax_table; 284 #endif 285 286 #endif /* !__REGEXP_LIBRARY */ 287