1*fae548d3Szrj /* Definitions for data structures and routines for the regular 2*fae548d3Szrj expression library, version 0.12. 3*fae548d3Szrj 4*fae548d3Szrj Copyright (C) 1985-2020 Free Software Foundation, Inc. 5*fae548d3Szrj 6*fae548d3Szrj This file is part of the GNU C Library. Its master source is NOT part of 7*fae548d3Szrj the C library, however. The master source lives in /gd/gnu/lib. 8*fae548d3Szrj 9*fae548d3Szrj The GNU C Library is free software; you can redistribute it and/or 10*fae548d3Szrj modify it under the terms of the GNU Lesser General Public 11*fae548d3Szrj License as published by the Free Software Foundation; either 12*fae548d3Szrj version 2.1 of the License, or (at your option) any later version. 13*fae548d3Szrj 14*fae548d3Szrj The GNU C Library is distributed in the hope that it will be useful, 15*fae548d3Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of 16*fae548d3Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17*fae548d3Szrj Lesser General Public License for more details. 18*fae548d3Szrj 19*fae548d3Szrj You should have received a copy of the GNU Lesser General Public 20*fae548d3Szrj License along with the GNU C Library; if not, write to the Free 21*fae548d3Szrj Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 22*fae548d3Szrj 02110-1301 USA. */ 23*fae548d3Szrj 24*fae548d3Szrj #ifndef _REGEX_H 25*fae548d3Szrj #define _REGEX_H 1 26*fae548d3Szrj 27*fae548d3Szrj /* Allow the use in C++ code. */ 28*fae548d3Szrj #ifdef __cplusplus 29*fae548d3Szrj extern "C" { 30*fae548d3Szrj #endif 31*fae548d3Szrj 32*fae548d3Szrj /* POSIX says that <sys/types.h> must be included (by the caller) before 33*fae548d3Szrj <regex.h>. */ 34*fae548d3Szrj 35*fae548d3Szrj #if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS 36*fae548d3Szrj /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it 37*fae548d3Szrj should be there. */ 38*fae548d3Szrj # include <stddef.h> 39*fae548d3Szrj #endif 40*fae548d3Szrj 41*fae548d3Szrj /* The following two types have to be signed and unsigned integer type 42*fae548d3Szrj wide enough to hold a value of a pointer. For most ANSI compilers 43*fae548d3Szrj ptrdiff_t and size_t should be likely OK. Still size of these two 44*fae548d3Szrj types is 2 for Microsoft C. Ugh... */ 45*fae548d3Szrj typedef long int s_reg_t; 46*fae548d3Szrj typedef unsigned long int active_reg_t; 47*fae548d3Szrj 48*fae548d3Szrj /* The following bits are used to determine the regexp syntax we 49*fae548d3Szrj recognize. The set/not-set meanings are chosen so that Emacs syntax 50*fae548d3Szrj remains the value 0. The bits are given in alphabetical order, and 51*fae548d3Szrj the definitions shifted by one from the previous bit; thus, when we 52*fae548d3Szrj add or remove a bit, only one other definition need change. */ 53*fae548d3Szrj typedef unsigned long int reg_syntax_t; 54*fae548d3Szrj 55*fae548d3Szrj /* If this bit is not set, then \ inside a bracket expression is literal. 56*fae548d3Szrj If set, then such a \ quotes the following character. */ 57*fae548d3Szrj #define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) 58*fae548d3Szrj 59*fae548d3Szrj /* If this bit is not set, then + and ? are operators, and \+ and \? are 60*fae548d3Szrj literals. 61*fae548d3Szrj If set, then \+ and \? are operators and + and ? are literals. */ 62*fae548d3Szrj #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) 63*fae548d3Szrj 64*fae548d3Szrj /* If this bit is set, then character classes are supported. They are: 65*fae548d3Szrj [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], 66*fae548d3Szrj [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. 67*fae548d3Szrj If not set, then character classes are not supported. */ 68*fae548d3Szrj #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) 69*fae548d3Szrj 70*fae548d3Szrj /* If this bit is set, then ^ and $ are always anchors (outside bracket 71*fae548d3Szrj expressions, of course). 72*fae548d3Szrj If this bit is not set, then it depends: 73*fae548d3Szrj ^ is an anchor if it is at the beginning of a regular 74*fae548d3Szrj expression or after an open-group or an alternation operator; 75*fae548d3Szrj $ is an anchor if it is at the end of a regular expression, or 76*fae548d3Szrj before a close-group or an alternation operator. 77*fae548d3Szrj 78*fae548d3Szrj This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because 79*fae548d3Szrj POSIX draft 11.2 says that * etc. in leading positions is undefined. 80*fae548d3Szrj We already implemented a previous draft which made those constructs 81*fae548d3Szrj invalid, though, so we haven't changed the code back. */ 82*fae548d3Szrj #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) 83*fae548d3Szrj 84*fae548d3Szrj /* If this bit is set, then special characters are always special 85*fae548d3Szrj regardless of where they are in the pattern. 86*fae548d3Szrj If this bit is not set, then special characters are special only in 87*fae548d3Szrj some contexts; otherwise they are ordinary. Specifically, 88*fae548d3Szrj * + ? and intervals are only special when not after the beginning, 89*fae548d3Szrj open-group, or alternation operator. */ 90*fae548d3Szrj #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) 91*fae548d3Szrj 92*fae548d3Szrj /* If this bit is set, then *, +, ?, and { cannot be first in an re or 93*fae548d3Szrj immediately after an alternation or begin-group operator. */ 94*fae548d3Szrj #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) 95*fae548d3Szrj 96*fae548d3Szrj /* If this bit is set, then . matches newline. 97*fae548d3Szrj If not set, then it doesn't. */ 98*fae548d3Szrj #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) 99*fae548d3Szrj 100*fae548d3Szrj /* If this bit is set, then . doesn't match NUL. 101*fae548d3Szrj If not set, then it does. */ 102*fae548d3Szrj #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) 103*fae548d3Szrj 104*fae548d3Szrj /* If this bit is set, nonmatching lists [^...] do not match newline. 105*fae548d3Szrj If not set, they do. */ 106*fae548d3Szrj #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) 107*fae548d3Szrj 108*fae548d3Szrj /* If this bit is set, either \{...\} or {...} defines an 109*fae548d3Szrj interval, depending on RE_NO_BK_BRACES. 110*fae548d3Szrj If not set, \{, \}, {, and } are literals. */ 111*fae548d3Szrj #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) 112*fae548d3Szrj 113*fae548d3Szrj /* If this bit is set, +, ? and | aren't recognized as operators. 114*fae548d3Szrj If not set, they are. */ 115*fae548d3Szrj #define RE_LIMITED_OPS (RE_INTERVALS << 1) 116*fae548d3Szrj 117*fae548d3Szrj /* If this bit is set, newline is an alternation operator. 118*fae548d3Szrj If not set, newline is literal. */ 119*fae548d3Szrj #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) 120*fae548d3Szrj 121*fae548d3Szrj /* If this bit is set, then `{...}' defines an interval, and \{ and \} 122*fae548d3Szrj are literals. 123*fae548d3Szrj If not set, then `\{...\}' defines an interval. */ 124*fae548d3Szrj #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) 125*fae548d3Szrj 126*fae548d3Szrj /* If this bit is set, (...) defines a group, and \( and \) are literals. 127*fae548d3Szrj If not set, \(...\) defines a group, and ( and ) are literals. */ 128*fae548d3Szrj #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) 129*fae548d3Szrj 130*fae548d3Szrj /* If this bit is set, then \<digit> matches <digit>. 131*fae548d3Szrj If not set, then \<digit> is a back-reference. */ 132*fae548d3Szrj #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) 133*fae548d3Szrj 134*fae548d3Szrj /* If this bit is set, then | is an alternation operator, and \| is literal. 135*fae548d3Szrj If not set, then \| is an alternation operator, and | is literal. */ 136*fae548d3Szrj #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) 137*fae548d3Szrj 138*fae548d3Szrj /* If this bit is set, then an ending range point collating higher 139*fae548d3Szrj than the starting range point, as in [z-a], is invalid. 140*fae548d3Szrj If not set, then when ending range point collates higher than the 141*fae548d3Szrj starting range point, the range is ignored. */ 142*fae548d3Szrj #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) 143*fae548d3Szrj 144*fae548d3Szrj /* If this bit is set, then an unmatched ) is ordinary. 145*fae548d3Szrj If not set, then an unmatched ) is invalid. */ 146*fae548d3Szrj #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) 147*fae548d3Szrj 148*fae548d3Szrj /* If this bit is set, succeed as soon as we match the whole pattern, 149*fae548d3Szrj without further backtracking. */ 150*fae548d3Szrj #define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) 151*fae548d3Szrj 152*fae548d3Szrj /* If this bit is set, do not process the GNU regex operators. 153*fae548d3Szrj If not set, then the GNU regex operators are recognized. */ 154*fae548d3Szrj #define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) 155*fae548d3Szrj 156*fae548d3Szrj /* If this bit is set, turn on internal regex debugging. 157*fae548d3Szrj If not set, and debugging was on, turn it off. 158*fae548d3Szrj This only works if regex.c is compiled -DDEBUG. 159*fae548d3Szrj We define this bit always, so that all that's needed to turn on 160*fae548d3Szrj debugging is to recompile regex.c; the calling code can always have 161*fae548d3Szrj this bit set, and it won't affect anything in the normal case. */ 162*fae548d3Szrj #define RE_DEBUG (RE_NO_GNU_OPS << 1) 163*fae548d3Szrj 164*fae548d3Szrj /* If this bit is set, a syntactically invalid interval is treated as 165*fae548d3Szrj a string of ordinary characters. For example, the ERE 'a{1' is 166*fae548d3Szrj treated as 'a\{1'. */ 167*fae548d3Szrj #define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) 168*fae548d3Szrj 169*fae548d3Szrj /* This global variable defines the particular regexp syntax to use (for 170*fae548d3Szrj some interfaces). When a regexp is compiled, the syntax used is 171*fae548d3Szrj stored in the pattern buffer, so changing this does not affect 172*fae548d3Szrj already-compiled regexps. */ 173*fae548d3Szrj extern reg_syntax_t re_syntax_options; 174*fae548d3Szrj 175*fae548d3Szrj /* Define combinations of the above bits for the standard possibilities. 176*fae548d3Szrj (The [[[ comments delimit what gets put into the Texinfo file, so 177*fae548d3Szrj don't delete them!) */ 178*fae548d3Szrj /* [[[begin syntaxes]]] */ 179*fae548d3Szrj #define RE_SYNTAX_EMACS 0 180*fae548d3Szrj 181*fae548d3Szrj #define RE_SYNTAX_AWK \ 182*fae548d3Szrj (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ 183*fae548d3Szrj | RE_NO_BK_PARENS | RE_NO_BK_REFS \ 184*fae548d3Szrj | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ 185*fae548d3Szrj | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ 186*fae548d3Szrj | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) 187*fae548d3Szrj 188*fae548d3Szrj #define RE_SYNTAX_GNU_AWK \ 189*fae548d3Szrj ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \ 190*fae548d3Szrj & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS)) 191*fae548d3Szrj 192*fae548d3Szrj #define RE_SYNTAX_POSIX_AWK \ 193*fae548d3Szrj (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ 194*fae548d3Szrj | RE_INTERVALS | RE_NO_GNU_OPS) 195*fae548d3Szrj 196*fae548d3Szrj #define RE_SYNTAX_GREP \ 197*fae548d3Szrj (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ 198*fae548d3Szrj | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ 199*fae548d3Szrj | RE_NEWLINE_ALT) 200*fae548d3Szrj 201*fae548d3Szrj #define RE_SYNTAX_EGREP \ 202*fae548d3Szrj (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ 203*fae548d3Szrj | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ 204*fae548d3Szrj | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ 205*fae548d3Szrj | RE_NO_BK_VBAR) 206*fae548d3Szrj 207*fae548d3Szrj #define RE_SYNTAX_POSIX_EGREP \ 208*fae548d3Szrj (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ 209*fae548d3Szrj | RE_INVALID_INTERVAL_ORD) 210*fae548d3Szrj 211*fae548d3Szrj /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ 212*fae548d3Szrj #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC 213*fae548d3Szrj 214*fae548d3Szrj #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC 215*fae548d3Szrj 216*fae548d3Szrj /* Syntax bits common to both basic and extended POSIX regex syntax. */ 217*fae548d3Szrj #define _RE_SYNTAX_POSIX_COMMON \ 218*fae548d3Szrj (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ 219*fae548d3Szrj | RE_INTERVALS | RE_NO_EMPTY_RANGES) 220*fae548d3Szrj 221*fae548d3Szrj #define RE_SYNTAX_POSIX_BASIC \ 222*fae548d3Szrj (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) 223*fae548d3Szrj 224*fae548d3Szrj /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes 225*fae548d3Szrj RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this 226*fae548d3Szrj isn't minimal, since other operators, such as \`, aren't disabled. */ 227*fae548d3Szrj #define RE_SYNTAX_POSIX_MINIMAL_BASIC \ 228*fae548d3Szrj (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) 229*fae548d3Szrj 230*fae548d3Szrj #define RE_SYNTAX_POSIX_EXTENDED \ 231*fae548d3Szrj (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ 232*fae548d3Szrj | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ 233*fae548d3Szrj | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 234*fae548d3Szrj | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) 235*fae548d3Szrj 236*fae548d3Szrj /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is 237*fae548d3Szrj removed and RE_NO_BK_REFS is added. */ 238*fae548d3Szrj #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ 239*fae548d3Szrj (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ 240*fae548d3Szrj | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ 241*fae548d3Szrj | RE_NO_BK_PARENS | RE_NO_BK_REFS \ 242*fae548d3Szrj | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) 243*fae548d3Szrj /* [[[end syntaxes]]] */ 244*fae548d3Szrj 245*fae548d3Szrj /* Maximum number of duplicates an interval can allow. Some systems 246*fae548d3Szrj (erroneously) define this in other header files, but we want our 247*fae548d3Szrj value, so remove any previous define. */ 248*fae548d3Szrj #ifdef RE_DUP_MAX 249*fae548d3Szrj # undef RE_DUP_MAX 250*fae548d3Szrj #endif 251*fae548d3Szrj /* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */ 252*fae548d3Szrj #define RE_DUP_MAX (0x7fff) 253*fae548d3Szrj 254*fae548d3Szrj 255*fae548d3Szrj /* POSIX `cflags' bits (i.e., information for `regcomp'). */ 256*fae548d3Szrj 257*fae548d3Szrj /* If this bit is set, then use extended regular expression syntax. 258*fae548d3Szrj If not set, then use basic regular expression syntax. */ 259*fae548d3Szrj #define REG_EXTENDED 1 260*fae548d3Szrj 261*fae548d3Szrj /* If this bit is set, then ignore case when matching. 262*fae548d3Szrj If not set, then case is significant. */ 263*fae548d3Szrj #define REG_ICASE (REG_EXTENDED << 1) 264*fae548d3Szrj 265*fae548d3Szrj /* If this bit is set, then anchors do not match at newline 266*fae548d3Szrj characters in the string. 267*fae548d3Szrj If not set, then anchors do match at newlines. */ 268*fae548d3Szrj #define REG_NEWLINE (REG_ICASE << 1) 269*fae548d3Szrj 270*fae548d3Szrj /* If this bit is set, then report only success or fail in regexec. 271*fae548d3Szrj If not set, then returns differ between not matching and errors. */ 272*fae548d3Szrj #define REG_NOSUB (REG_NEWLINE << 1) 273*fae548d3Szrj 274*fae548d3Szrj 275*fae548d3Szrj /* POSIX `eflags' bits (i.e., information for regexec). */ 276*fae548d3Szrj 277*fae548d3Szrj /* If this bit is set, then the beginning-of-line operator doesn't match 278*fae548d3Szrj the beginning of the string (presumably because it's not the 279*fae548d3Szrj beginning of a line). 280*fae548d3Szrj If not set, then the beginning-of-line operator does match the 281*fae548d3Szrj beginning of the string. */ 282*fae548d3Szrj #define REG_NOTBOL 1 283*fae548d3Szrj 284*fae548d3Szrj /* Like REG_NOTBOL, except for the end-of-line. */ 285*fae548d3Szrj #define REG_NOTEOL (1 << 1) 286*fae548d3Szrj 287*fae548d3Szrj 288*fae548d3Szrj /* If any error codes are removed, changed, or added, update the 289*fae548d3Szrj `re_error_msg' table in regex.c. */ 290*fae548d3Szrj typedef enum 291*fae548d3Szrj { 292*fae548d3Szrj #ifdef _XOPEN_SOURCE 293*fae548d3Szrj REG_ENOSYS = -1, /* This will never happen for this implementation. */ 294*fae548d3Szrj #endif 295*fae548d3Szrj 296*fae548d3Szrj REG_NOERROR = 0, /* Success. */ 297*fae548d3Szrj REG_NOMATCH, /* Didn't find a match (for regexec). */ 298*fae548d3Szrj 299*fae548d3Szrj /* POSIX regcomp return error codes. (In the order listed in the 300*fae548d3Szrj standard.) */ 301*fae548d3Szrj REG_BADPAT, /* Invalid pattern. */ 302*fae548d3Szrj REG_ECOLLATE, /* Not implemented. */ 303*fae548d3Szrj REG_ECTYPE, /* Invalid character class name. */ 304*fae548d3Szrj REG_EESCAPE, /* Trailing backslash. */ 305*fae548d3Szrj REG_ESUBREG, /* Invalid back reference. */ 306*fae548d3Szrj REG_EBRACK, /* Unmatched left bracket. */ 307*fae548d3Szrj REG_EPAREN, /* Parenthesis imbalance. */ 308*fae548d3Szrj REG_EBRACE, /* Unmatched \{. */ 309*fae548d3Szrj REG_BADBR, /* Invalid contents of \{\}. */ 310*fae548d3Szrj REG_ERANGE, /* Invalid range end. */ 311*fae548d3Szrj REG_ESPACE, /* Ran out of memory. */ 312*fae548d3Szrj REG_BADRPT, /* No preceding re for repetition op. */ 313*fae548d3Szrj 314*fae548d3Szrj /* Error codes we've added. */ 315*fae548d3Szrj REG_EEND, /* Premature end. */ 316*fae548d3Szrj REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ 317*fae548d3Szrj REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ 318*fae548d3Szrj } reg_errcode_t; 319*fae548d3Szrj 320*fae548d3Szrj /* This data structure represents a compiled pattern. Before calling 321*fae548d3Szrj the pattern compiler, the fields `buffer', `allocated', `fastmap', 322*fae548d3Szrj `translate', and `no_sub' can be set. After the pattern has been 323*fae548d3Szrj compiled, the `re_nsub' field is available. All other fields are 324*fae548d3Szrj private to the regex routines. */ 325*fae548d3Szrj 326*fae548d3Szrj #ifndef RE_TRANSLATE_TYPE 327*fae548d3Szrj # define RE_TRANSLATE_TYPE char * 328*fae548d3Szrj #endif 329*fae548d3Szrj 330*fae548d3Szrj struct re_pattern_buffer 331*fae548d3Szrj { 332*fae548d3Szrj /* [[[begin pattern_buffer]]] */ 333*fae548d3Szrj /* Space that holds the compiled pattern. It is declared as 334*fae548d3Szrj `unsigned char *' because its elements are 335*fae548d3Szrj sometimes used as array indexes. */ 336*fae548d3Szrj unsigned char *buffer; 337*fae548d3Szrj 338*fae548d3Szrj /* Number of bytes to which `buffer' points. */ 339*fae548d3Szrj unsigned long int allocated; 340*fae548d3Szrj 341*fae548d3Szrj /* Number of bytes actually used in `buffer'. */ 342*fae548d3Szrj unsigned long int used; 343*fae548d3Szrj 344*fae548d3Szrj /* Syntax setting with which the pattern was compiled. */ 345*fae548d3Szrj reg_syntax_t syntax; 346*fae548d3Szrj 347*fae548d3Szrj /* Pointer to a fastmap, if any, otherwise zero. re_search uses 348*fae548d3Szrj the fastmap, if there is one, to skip over impossible 349*fae548d3Szrj starting points for matches. */ 350*fae548d3Szrj char *fastmap; 351*fae548d3Szrj 352*fae548d3Szrj /* Either a translate table to apply to all characters before 353*fae548d3Szrj comparing them, or zero for no translation. The translation 354*fae548d3Szrj is applied to a pattern when it is compiled and to a string 355*fae548d3Szrj when it is matched. */ 356*fae548d3Szrj RE_TRANSLATE_TYPE translate; 357*fae548d3Szrj 358*fae548d3Szrj /* Number of subexpressions found by the compiler. */ 359*fae548d3Szrj size_t re_nsub; 360*fae548d3Szrj 361*fae548d3Szrj /* Zero if this pattern cannot match the empty string, one else. 362*fae548d3Szrj Well, in truth it's used only in `re_search_2', to see 363*fae548d3Szrj whether or not we should use the fastmap, so we don't set 364*fae548d3Szrj this absolutely perfectly; see `re_compile_fastmap' (the 365*fae548d3Szrj `duplicate' case). */ 366*fae548d3Szrj unsigned can_be_null : 1; 367*fae548d3Szrj 368*fae548d3Szrj /* If REGS_UNALLOCATED, allocate space in the `regs' structure 369*fae548d3Szrj for `max (RE_NREGS, re_nsub + 1)' groups. 370*fae548d3Szrj If REGS_REALLOCATE, reallocate space if necessary. 371*fae548d3Szrj If REGS_FIXED, use what's there. */ 372*fae548d3Szrj #define REGS_UNALLOCATED 0 373*fae548d3Szrj #define REGS_REALLOCATE 1 374*fae548d3Szrj #define REGS_FIXED 2 375*fae548d3Szrj unsigned regs_allocated : 2; 376*fae548d3Szrj 377*fae548d3Szrj /* Set to zero when `regex_compile' compiles a pattern; set to one 378*fae548d3Szrj by `re_compile_fastmap' if it updates the fastmap. */ 379*fae548d3Szrj unsigned fastmap_accurate : 1; 380*fae548d3Szrj 381*fae548d3Szrj /* If set, `re_match_2' does not return information about 382*fae548d3Szrj subexpressions. */ 383*fae548d3Szrj unsigned no_sub : 1; 384*fae548d3Szrj 385*fae548d3Szrj /* If set, a beginning-of-line anchor doesn't match at the 386*fae548d3Szrj beginning of the string. */ 387*fae548d3Szrj unsigned not_bol : 1; 388*fae548d3Szrj 389*fae548d3Szrj /* Similarly for an end-of-line anchor. */ 390*fae548d3Szrj unsigned not_eol : 1; 391*fae548d3Szrj 392*fae548d3Szrj /* If true, an anchor at a newline matches. */ 393*fae548d3Szrj unsigned newline_anchor : 1; 394*fae548d3Szrj 395*fae548d3Szrj /* [[[end pattern_buffer]]] */ 396*fae548d3Szrj }; 397*fae548d3Szrj 398*fae548d3Szrj typedef struct re_pattern_buffer regex_t; 399*fae548d3Szrj 400*fae548d3Szrj /* Type for byte offsets within the string. POSIX mandates this. */ 401*fae548d3Szrj typedef int regoff_t; 402*fae548d3Szrj 403*fae548d3Szrj 404*fae548d3Szrj /* This is the structure we store register match data in. See 405*fae548d3Szrj regex.texinfo for a full description of what registers match. */ 406*fae548d3Szrj struct re_registers 407*fae548d3Szrj { 408*fae548d3Szrj unsigned num_regs; 409*fae548d3Szrj regoff_t *start; 410*fae548d3Szrj regoff_t *end; 411*fae548d3Szrj }; 412*fae548d3Szrj 413*fae548d3Szrj 414*fae548d3Szrj /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, 415*fae548d3Szrj `re_match_2' returns information about at least this many registers 416*fae548d3Szrj the first time a `regs' structure is passed. */ 417*fae548d3Szrj #ifndef RE_NREGS 418*fae548d3Szrj # define RE_NREGS 30 419*fae548d3Szrj #endif 420*fae548d3Szrj 421*fae548d3Szrj 422*fae548d3Szrj /* POSIX specification for registers. Aside from the different names than 423*fae548d3Szrj `re_registers', POSIX uses an array of structures, instead of a 424*fae548d3Szrj structure of arrays. */ 425*fae548d3Szrj typedef struct 426*fae548d3Szrj { 427*fae548d3Szrj regoff_t rm_so; /* Byte offset from string's start to substring's start. */ 428*fae548d3Szrj regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ 429*fae548d3Szrj } regmatch_t; 430*fae548d3Szrj 431*fae548d3Szrj /* Declarations for routines. */ 432*fae548d3Szrj 433*fae548d3Szrj /* To avoid duplicating every routine declaration -- once with a 434*fae548d3Szrj prototype (if we are ANSI), and once without (if we aren't) -- we 435*fae548d3Szrj use the following macro to declare argument types. This 436*fae548d3Szrj unfortunately clutters up the declarations a bit, but I think it's 437*fae548d3Szrj worth it. */ 438*fae548d3Szrj 439*fae548d3Szrj /* Sets the current default syntax to SYNTAX, and return the old syntax. 440*fae548d3Szrj You can also simply assign to the `re_syntax_options' variable. */ 441*fae548d3Szrj extern reg_syntax_t re_set_syntax (reg_syntax_t syntax); 442*fae548d3Szrj 443*fae548d3Szrj /* Compile the regular expression PATTERN, with length LENGTH 444*fae548d3Szrj and syntax given by the global `re_syntax_options', into the buffer 445*fae548d3Szrj BUFFER. Return NULL if successful, and an error string if not. */ 446*fae548d3Szrj extern const char *re_compile_pattern (const char *pattern, size_t length, 447*fae548d3Szrj struct re_pattern_buffer *buffer); 448*fae548d3Szrj 449*fae548d3Szrj 450*fae548d3Szrj /* Compile a fastmap for the compiled pattern in BUFFER; used to 451*fae548d3Szrj accelerate searches. Return 0 if successful and -2 if was an 452*fae548d3Szrj internal error. */ 453*fae548d3Szrj extern int re_compile_fastmap (struct re_pattern_buffer *buffer); 454*fae548d3Szrj 455*fae548d3Szrj 456*fae548d3Szrj /* Search in the string STRING (with length LENGTH) for the pattern 457*fae548d3Szrj compiled into BUFFER. Start searching at position START, for RANGE 458*fae548d3Szrj characters. Return the starting position of the match, -1 for no 459*fae548d3Szrj match, or -2 for an internal error. Also return register 460*fae548d3Szrj information in REGS (if REGS and BUFFER->no_sub are nonzero). */ 461*fae548d3Szrj extern int re_search (struct re_pattern_buffer *buffer, const char *string, 462*fae548d3Szrj int length, int start, int range, 463*fae548d3Szrj struct re_registers *regs); 464*fae548d3Szrj 465*fae548d3Szrj 466*fae548d3Szrj /* Like `re_search', but search in the concatenation of STRING1 and 467*fae548d3Szrj STRING2. Also, stop searching at index START + STOP. */ 468*fae548d3Szrj extern int re_search_2 (struct re_pattern_buffer *buffer, const char *string1, 469*fae548d3Szrj int length1, const char *string2, int length2, 470*fae548d3Szrj int start, int range, struct re_registers *regs, 471*fae548d3Szrj int stop); 472*fae548d3Szrj 473*fae548d3Szrj 474*fae548d3Szrj /* Like `re_search', but return how many characters in STRING the regexp 475*fae548d3Szrj in BUFFER matched, starting at position START. */ 476*fae548d3Szrj extern int re_match (struct re_pattern_buffer *buffer, const char *string, 477*fae548d3Szrj int length, int start, struct re_registers *regs); 478*fae548d3Szrj 479*fae548d3Szrj 480*fae548d3Szrj /* Relates to `re_match' as `re_search_2' relates to `re_search'. */ 481*fae548d3Szrj extern int re_match_2 (struct re_pattern_buffer *buffer, const char *string1, 482*fae548d3Szrj int length1, const char *string2, int length2, 483*fae548d3Szrj int start, struct re_registers *regs, int stop); 484*fae548d3Szrj 485*fae548d3Szrj 486*fae548d3Szrj /* Set REGS to hold NUM_REGS registers, storing them in STARTS and 487*fae548d3Szrj ENDS. Subsequent matches using BUFFER and REGS will use this memory 488*fae548d3Szrj for recording register information. STARTS and ENDS must be 489*fae548d3Szrj allocated with malloc, and must each be at least `NUM_REGS * sizeof 490*fae548d3Szrj (regoff_t)' bytes long. 491*fae548d3Szrj 492*fae548d3Szrj If NUM_REGS == 0, then subsequent matches should allocate their own 493*fae548d3Szrj register data. 494*fae548d3Szrj 495*fae548d3Szrj Unless this function is called, the first search or match using 496*fae548d3Szrj PATTERN_BUFFER will allocate its own register data, without 497*fae548d3Szrj freeing the old data. */ 498*fae548d3Szrj extern void re_set_registers (struct re_pattern_buffer *buffer, 499*fae548d3Szrj struct re_registers *regs, 500*fae548d3Szrj unsigned num_regs, regoff_t *starts, 501*fae548d3Szrj regoff_t *ends); 502*fae548d3Szrj 503*fae548d3Szrj #if defined _REGEX_RE_COMP || defined _LIBC 504*fae548d3Szrj # ifndef _CRAY 505*fae548d3Szrj /* 4.2 bsd compatibility. */ 506*fae548d3Szrj extern char *re_comp (const char *); 507*fae548d3Szrj extern int re_exec (const char *); 508*fae548d3Szrj # endif 509*fae548d3Szrj #endif 510*fae548d3Szrj 511*fae548d3Szrj /* GCC 2.95 and later have "__restrict"; C99 compilers have 512*fae548d3Szrj "restrict", and "configure" may have defined "restrict". */ 513*fae548d3Szrj #ifndef __restrict 514*fae548d3Szrj # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) 515*fae548d3Szrj # if defined restrict || 199901L <= __STDC_VERSION__ 516*fae548d3Szrj # define __restrict restrict 517*fae548d3Szrj # else 518*fae548d3Szrj # define __restrict 519*fae548d3Szrj # endif 520*fae548d3Szrj # endif 521*fae548d3Szrj #endif 522*fae548d3Szrj 523*fae548d3Szrj /* GCC 3.1 and later support declaring arrays as non-overlapping 524*fae548d3Szrj using the syntax array_name[restrict] */ 525*fae548d3Szrj #ifndef __restrict_arr 526*fae548d3Szrj # if ! (3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) || defined (__GNUG__) 527*fae548d3Szrj # define __restrict_arr 528*fae548d3Szrj # else 529*fae548d3Szrj # define __restrict_arr __restrict 530*fae548d3Szrj # endif 531*fae548d3Szrj #endif 532*fae548d3Szrj 533*fae548d3Szrj /* POSIX compatibility. */ 534*fae548d3Szrj extern int regcomp (regex_t *__restrict __preg, 535*fae548d3Szrj const char *__restrict __pattern, 536*fae548d3Szrj int __cflags); 537*fae548d3Szrj 538*fae548d3Szrj #if (__GNUC__) 539*fae548d3Szrj __extension__ 540*fae548d3Szrj #endif 541*fae548d3Szrj extern int regexec (const regex_t *__restrict __preg, 542*fae548d3Szrj const char *__restrict __string, size_t __nmatch, 543*fae548d3Szrj regmatch_t __pmatch[__restrict_arr], 544*fae548d3Szrj int __eflags); 545*fae548d3Szrj 546*fae548d3Szrj extern size_t regerror (int __errcode, const regex_t *__preg, 547*fae548d3Szrj char *__errbuf, size_t __errbuf_size); 548*fae548d3Szrj 549*fae548d3Szrj extern void regfree (regex_t *__preg); 550*fae548d3Szrj 551*fae548d3Szrj 552*fae548d3Szrj #ifdef __cplusplus 553*fae548d3Szrj } 554*fae548d3Szrj #endif /* C++ */ 555*fae548d3Szrj 556*fae548d3Szrj #endif /* regex.h */ 557*fae548d3Szrj 558*fae548d3Szrj /* 559*fae548d3Szrj Local variables: 560*fae548d3Szrj make-backup-files: t 561*fae548d3Szrj version-control: t 562*fae548d3Szrj trim-versions-without-asking: nil 563*fae548d3Szrj End: 564*fae548d3Szrj */ 565