1 /* Definitions for data structures and routines for the regular 2 expression library, version 0.12. 3 Copyright (C) 1985,89,90,91,92,93,95,96,97,98 Free Software Foundation, Inc. 4 5 This file is part of the GNU C Library. Its master source is NOT part of 6 the C library, however. The master source lives in /gd/gnu/lib. 7 8 The GNU C Library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Library General Public License as 10 published by the Free Software Foundation; either version 2 of the 11 License, or (at your option) any later version. 12 13 The GNU C Library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Library General Public License for more details. 17 18 You should have received a copy of the GNU Library General Public 19 License along with the GNU C Library; see the file COPYING.LIB. If not, 20 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 Boston, MA 02110-1301, USA. */ 22 23 /* modified for Ruby by matz@netlab.co.jp */ 24 25 #ifndef __REGEXP_LIBRARY 26 #define __REGEXP_LIBRARY 27 28 29 #include <stddef.h> 30 31 /* Define number of parens for which we record the beginnings and ends. 32 This affects how much space the `struct pre_registers' type takes up. */ 33 #ifndef PRE_NREGS 34 #define PRE_NREGS 10 35 #endif 36 37 #define BYTEWIDTH 8 38 39 #define PRE_REG_MAX ((1<<BYTEWIDTH)-1) 40 41 /* Maximum number of duplicates an interval can allow. */ 42 #ifndef PRE_DUP_MAX 43 #define PRE_DUP_MAX ((1 << 15) - 1) 44 #endif 45 46 47 /* If this bit is set, then character classes are supported; they are: 48 [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], 49 [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. 50 If not set, then character classes are not supported. */ 51 #define PRE_CHAR_CLASSES (1L << 9) 52 53 /* match will be done case insensetively */ 54 #define PRE_OPTION_IGNORECASE (1L) 55 /* perl-style extended pattern available */ 56 #define PRE_OPTION_EXTENDED (PRE_OPTION_IGNORECASE<<1) 57 /* newline will be included for . */ 58 #define PRE_OPTION_SINGLELINE (PRE_OPTION_EXTENDED<<1) 59 /* ^ and $ look at newline */ 60 #define PRE_OPTION_MULTILINE (PRE_OPTION_SINGLELINE<<1) 61 /* search for longest match, in accord with POSIX regexp */ 62 #define PRE_OPTION_LONGEST (PRE_OPTION_MULTILINE<<1) 63 64 #define PRE_MAY_IGNORECASE (PRE_OPTION_LONGEST<<1) 65 #define PRE_OPTIMIZE_ANCHOR (PRE_MAY_IGNORECASE<<1) 66 #define PRE_OPTIMIZE_EXACTN (PRE_OPTIMIZE_ANCHOR<<1) 67 68 /* Structure used in pre_match() */ 69 70 typedef union 71 { 72 unsigned char *word; 73 struct { 74 unsigned is_active : 1; 75 unsigned matched_something : 1; 76 } bits; 77 } register_info_type; 78 79 /* This data structure is used to represent a compiled pattern. */ 80 81 struct pre_pattern_buffer 82 { 83 char *buffer; /* Space holding the compiled pattern commands. */ 84 int allocated; /* Size of space that `buffer' points to. */ 85 int used; /* Length of portion of buffer actually occupied */ 86 char *fastmap; /* Pointer to fastmap, if any, or zero if none. */ 87 /* pre_search uses the fastmap, if there is one, 88 to skip over totally implausible characters. */ 89 char *must; /* Pointer to exact pattern which strings should have 90 to be matched. */ 91 int *must_skip; /* Pointer to exact pattern skip table for bm_search */ 92 char *stclass; /* Pointer to character class list at top */ 93 long options; /* Flags for options such as extended_pattern. */ 94 long pre_nsub; /* Number of subexpressions found by the compiler. */ 95 char fastmap_accurate; 96 /* Set to zero when a new pattern is stored, 97 set to one when the fastmap is updated from it. */ 98 char can_be_null; /* Set to one by compiling fastmap 99 if this pattern might match the null string. 100 It does not necessarily match the null string 101 in that case, but if this is zero, it cannot. 102 2 as value means can match null string 103 but at end of range or before a character 104 listed in the fastmap. */ 105 106 /* stack & working area for pre_match() */ 107 unsigned char **regstart; 108 unsigned char **regend; 109 unsigned char **old_regstart; 110 unsigned char **old_regend; 111 register_info_type *reg_info; 112 unsigned char **best_regstart; 113 unsigned char **best_regend; 114 }; 115 116 typedef struct pre_pattern_buffer regex_t; 117 118 /* Structure to store register contents data in. 119 120 Pass the address of such a structure as an argument to pre_match, etc., 121 if you want this information back. 122 123 For i from 1 to PRE_NREGS - 1, start[i] records the starting index in 124 the string of where the ith subexpression matched, and end[i] records 125 one after the ending index. start[0] and end[0] are analogous, for 126 the entire pattern. */ 127 128 struct pre_registers 129 { 130 int allocated; 131 int num_regs; 132 int *beg; 133 int *end; 134 }; 135 136 /* Type for byte offsets within the string. POSIX mandates this. */ 137 typedef size_t regoff_t; 138 139 /* POSIX specification for registers. Aside from the different names than 140 `pre_registers', POSIX uses an array of structures, instead of a 141 structure of arrays. */ 142 typedef struct 143 { 144 regoff_t rm_so; /* Byte offset from string's start to substring's start. */ 145 regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ 146 } regmatch_t; 147 148 149 #ifdef __STDC__ 150 151 extern const char *pre_compile_pattern (const char *, int, struct pre_pattern_buffer *); 152 void pre_free_pattern (struct pre_pattern_buffer *); 153 /* Is this really advertised? */ 154 extern int pre_adjust_startpos (struct pre_pattern_buffer *, const char*, int, int, int); 155 extern void pre_compile_fastmap (struct pre_pattern_buffer *); 156 extern int pre_search (struct pre_pattern_buffer *, const char*, int, int, int, 157 struct pre_registers *); 158 extern int pre_match (struct pre_pattern_buffer *, const char *, int, int, 159 struct pre_registers *); 160 extern void pre_set_casetable (const char *table); 161 extern void pre_copy_registers (struct pre_registers*, struct pre_registers*); 162 extern void pre_free_registers (struct pre_registers*); 163 164 #else /* !__STDC__ */ 165 166 extern char *pre_compile_pattern (); 167 void pre_free_regexp (); 168 /* Is this really advertised? */ 169 extern int pre_adjust_startpos (); 170 extern void pre_compile_fastmap (); 171 extern int pre_search (); 172 extern int pre_match (); 173 extern void pre_set_casetable (); 174 extern void pre_copy_registers (); 175 extern void pre_free_registers (); 176 177 #endif /* __STDC__ */ 178 179 #endif /* !__REGEXP_LIBRARY */ 180