19588ddcfSespie /* Definitions for data structures and routines for the regular 29588ddcfSespie expression library, version 0.12. 3*20fce977Smiod 4*20fce977Smiod Copyright (C) 1985, 1989, 1990, 1991, 1992, 1993, 1995, 1996, 1997, 5*20fce977Smiod 1998, 2000, 2005 Free Software Foundation, Inc. 6*20fce977Smiod 79588ddcfSespie This file is part of the GNU C Library. Its master source is NOT part of 89588ddcfSespie the C library, however. The master source lives in /gd/gnu/lib. 99588ddcfSespie 109588ddcfSespie The GNU C Library is free software; you can redistribute it and/or 119588ddcfSespie modify it under the terms of the GNU Lesser General Public 129588ddcfSespie License as published by the Free Software Foundation; either 139588ddcfSespie version 2.1 of the License, or (at your option) any later version. 149588ddcfSespie 159588ddcfSespie The GNU C Library is distributed in the hope that it will be useful, 169588ddcfSespie but WITHOUT ANY WARRANTY; without even the implied warranty of 179588ddcfSespie MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 189588ddcfSespie Lesser General Public License for more details. 199588ddcfSespie 209588ddcfSespie You should have received a copy of the GNU Lesser General Public 219588ddcfSespie License along with the GNU C Library; if not, write to the Free 22*20fce977Smiod Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 23*20fce977Smiod 02110-1301 USA. */ 249588ddcfSespie 259588ddcfSespie #ifndef _REGEX_H 269588ddcfSespie #define _REGEX_H 1 279588ddcfSespie 289588ddcfSespie /* Allow the use in C++ code. */ 299588ddcfSespie #ifdef __cplusplus 309588ddcfSespie extern "C" { 319588ddcfSespie #endif 329588ddcfSespie 339588ddcfSespie /* POSIX says that <sys/types.h> must be included (by the caller) before 349588ddcfSespie <regex.h>. */ 359588ddcfSespie 369588ddcfSespie #if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS 379588ddcfSespie /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it 389588ddcfSespie should be there. */ 399588ddcfSespie # include <stddef.h> 409588ddcfSespie #endif 419588ddcfSespie 429588ddcfSespie /* The following two types have to be signed and unsigned integer type 439588ddcfSespie wide enough to hold a value of a pointer. For most ANSI compilers 449588ddcfSespie ptrdiff_t and size_t should be likely OK. Still size of these two 459588ddcfSespie types is 2 for Microsoft C. Ugh... */ 469588ddcfSespie typedef long int s_reg_t; 479588ddcfSespie typedef unsigned long int active_reg_t; 489588ddcfSespie 499588ddcfSespie /* The following bits are used to determine the regexp syntax we 509588ddcfSespie recognize. The set/not-set meanings are chosen so that Emacs syntax 519588ddcfSespie remains the value 0. The bits are given in alphabetical order, and 529588ddcfSespie the definitions shifted by one from the previous bit; thus, when we 539588ddcfSespie add or remove a bit, only one other definition need change. */ 549588ddcfSespie typedef unsigned long int reg_syntax_t; 559588ddcfSespie 569588ddcfSespie /* If this bit is not set, then \ inside a bracket expression is literal. 579588ddcfSespie If set, then such a \ quotes the following character. */ 589588ddcfSespie #define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1) 599588ddcfSespie 609588ddcfSespie /* If this bit is not set, then + and ? are operators, and \+ and \? are 619588ddcfSespie literals. 629588ddcfSespie If set, then \+ and \? are operators and + and ? are literals. */ 639588ddcfSespie #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) 649588ddcfSespie 659588ddcfSespie /* If this bit is set, then character classes are supported. They are: 669588ddcfSespie [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], 679588ddcfSespie [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. 689588ddcfSespie If not set, then character classes are not supported. */ 699588ddcfSespie #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) 709588ddcfSespie 719588ddcfSespie /* If this bit is set, then ^ and $ are always anchors (outside bracket 729588ddcfSespie expressions, of course). 739588ddcfSespie If this bit is not set, then it depends: 749588ddcfSespie ^ is an anchor if it is at the beginning of a regular 759588ddcfSespie expression or after an open-group or an alternation operator; 769588ddcfSespie $ is an anchor if it is at the end of a regular expression, or 779588ddcfSespie before a close-group or an alternation operator. 789588ddcfSespie 799588ddcfSespie This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because 809588ddcfSespie POSIX draft 11.2 says that * etc. in leading positions is undefined. 819588ddcfSespie We already implemented a previous draft which made those constructs 829588ddcfSespie invalid, though, so we haven't changed the code back. */ 839588ddcfSespie #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) 849588ddcfSespie 859588ddcfSespie /* If this bit is set, then special characters are always special 869588ddcfSespie regardless of where they are in the pattern. 879588ddcfSespie If this bit is not set, then special characters are special only in 889588ddcfSespie some contexts; otherwise they are ordinary. Specifically, 899588ddcfSespie * + ? and intervals are only special when not after the beginning, 909588ddcfSespie open-group, or alternation operator. */ 919588ddcfSespie #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) 929588ddcfSespie 939588ddcfSespie /* If this bit is set, then *, +, ?, and { cannot be first in an re or 949588ddcfSespie immediately after an alternation or begin-group operator. */ 959588ddcfSespie #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) 969588ddcfSespie 979588ddcfSespie /* If this bit is set, then . matches newline. 989588ddcfSespie If not set, then it doesn't. */ 999588ddcfSespie #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) 1009588ddcfSespie 1019588ddcfSespie /* If this bit is set, then . doesn't match NUL. 1029588ddcfSespie If not set, then it does. */ 1039588ddcfSespie #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) 1049588ddcfSespie 1059588ddcfSespie /* If this bit is set, nonmatching lists [^...] do not match newline. 1069588ddcfSespie If not set, they do. */ 1079588ddcfSespie #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) 1089588ddcfSespie 1099588ddcfSespie /* If this bit is set, either \{...\} or {...} defines an 1109588ddcfSespie interval, depending on RE_NO_BK_BRACES. 1119588ddcfSespie If not set, \{, \}, {, and } are literals. */ 1129588ddcfSespie #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) 1139588ddcfSespie 1149588ddcfSespie /* If this bit is set, +, ? and | aren't recognized as operators. 1159588ddcfSespie If not set, they are. */ 1169588ddcfSespie #define RE_LIMITED_OPS (RE_INTERVALS << 1) 1179588ddcfSespie 1189588ddcfSespie /* If this bit is set, newline is an alternation operator. 1199588ddcfSespie If not set, newline is literal. */ 1209588ddcfSespie #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) 1219588ddcfSespie 1229588ddcfSespie /* If this bit is set, then `{...}' defines an interval, and \{ and \} 1239588ddcfSespie are literals. 1249588ddcfSespie If not set, then `\{...\}' defines an interval. */ 1259588ddcfSespie #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) 1269588ddcfSespie 1279588ddcfSespie /* If this bit is set, (...) defines a group, and \( and \) are literals. 1289588ddcfSespie If not set, \(...\) defines a group, and ( and ) are literals. */ 1299588ddcfSespie #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) 1309588ddcfSespie 1319588ddcfSespie /* If this bit is set, then \<digit> matches <digit>. 1329588ddcfSespie If not set, then \<digit> is a back-reference. */ 1339588ddcfSespie #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) 1349588ddcfSespie 1359588ddcfSespie /* If this bit is set, then | is an alternation operator, and \| is literal. 1369588ddcfSespie If not set, then \| is an alternation operator, and | is literal. */ 1379588ddcfSespie #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) 1389588ddcfSespie 1399588ddcfSespie /* If this bit is set, then an ending range point collating higher 1409588ddcfSespie than the starting range point, as in [z-a], is invalid. 1419588ddcfSespie If not set, then when ending range point collates higher than the 1429588ddcfSespie starting range point, the range is ignored. */ 1439588ddcfSespie #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) 1449588ddcfSespie 1459588ddcfSespie /* If this bit is set, then an unmatched ) is ordinary. 1469588ddcfSespie If not set, then an unmatched ) is invalid. */ 1479588ddcfSespie #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) 1489588ddcfSespie 1499588ddcfSespie /* If this bit is set, succeed as soon as we match the whole pattern, 1509588ddcfSespie without further backtracking. */ 1519588ddcfSespie #define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) 1529588ddcfSespie 1539588ddcfSespie /* If this bit is set, do not process the GNU regex operators. 1549588ddcfSespie If not set, then the GNU regex operators are recognized. */ 1559588ddcfSespie #define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1) 1569588ddcfSespie 1579588ddcfSespie /* If this bit is set, turn on internal regex debugging. 1589588ddcfSespie If not set, and debugging was on, turn it off. 1599588ddcfSespie This only works if regex.c is compiled -DDEBUG. 1609588ddcfSespie We define this bit always, so that all that's needed to turn on 1619588ddcfSespie debugging is to recompile regex.c; the calling code can always have 1629588ddcfSespie this bit set, and it won't affect anything in the normal case. */ 1639588ddcfSespie #define RE_DEBUG (RE_NO_GNU_OPS << 1) 1649588ddcfSespie 1659588ddcfSespie /* If this bit is set, a syntactically invalid interval is treated as 1669588ddcfSespie a string of ordinary characters. For example, the ERE 'a{1' is 1679588ddcfSespie treated as 'a\{1'. */ 1689588ddcfSespie #define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1) 1699588ddcfSespie 1709588ddcfSespie /* This global variable defines the particular regexp syntax to use (for 1719588ddcfSespie some interfaces). When a regexp is compiled, the syntax used is 1729588ddcfSespie stored in the pattern buffer, so changing this does not affect 1739588ddcfSespie already-compiled regexps. */ 1749588ddcfSespie extern reg_syntax_t re_syntax_options; 1759588ddcfSespie 1769588ddcfSespie /* Define combinations of the above bits for the standard possibilities. 1779588ddcfSespie (The [[[ comments delimit what gets put into the Texinfo file, so 1789588ddcfSespie don't delete them!) */ 1799588ddcfSespie /* [[[begin syntaxes]]] */ 1809588ddcfSespie #define RE_SYNTAX_EMACS 0 1819588ddcfSespie 1829588ddcfSespie #define RE_SYNTAX_AWK \ 1839588ddcfSespie (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ 1849588ddcfSespie | RE_NO_BK_PARENS | RE_NO_BK_REFS \ 1859588ddcfSespie | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ 1869588ddcfSespie | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \ 1879588ddcfSespie | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS) 1889588ddcfSespie 1899588ddcfSespie #define RE_SYNTAX_GNU_AWK \ 1909588ddcfSespie ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \ 1919588ddcfSespie & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS)) 1929588ddcfSespie 1939588ddcfSespie #define RE_SYNTAX_POSIX_AWK \ 1949588ddcfSespie (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ 1959588ddcfSespie | RE_INTERVALS | RE_NO_GNU_OPS) 1969588ddcfSespie 1979588ddcfSespie #define RE_SYNTAX_GREP \ 1989588ddcfSespie (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ 1999588ddcfSespie | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ 2009588ddcfSespie | RE_NEWLINE_ALT) 2019588ddcfSespie 2029588ddcfSespie #define RE_SYNTAX_EGREP \ 2039588ddcfSespie (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ 2049588ddcfSespie | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ 2059588ddcfSespie | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ 2069588ddcfSespie | RE_NO_BK_VBAR) 2079588ddcfSespie 2089588ddcfSespie #define RE_SYNTAX_POSIX_EGREP \ 2099588ddcfSespie (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \ 2109588ddcfSespie | RE_INVALID_INTERVAL_ORD) 2119588ddcfSespie 2129588ddcfSespie /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ 2139588ddcfSespie #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC 2149588ddcfSespie 2159588ddcfSespie #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC 2169588ddcfSespie 2179588ddcfSespie /* Syntax bits common to both basic and extended POSIX regex syntax. */ 2189588ddcfSespie #define _RE_SYNTAX_POSIX_COMMON \ 2199588ddcfSespie (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ 2209588ddcfSespie | RE_INTERVALS | RE_NO_EMPTY_RANGES) 2219588ddcfSespie 2229588ddcfSespie #define RE_SYNTAX_POSIX_BASIC \ 2239588ddcfSespie (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) 2249588ddcfSespie 2259588ddcfSespie /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes 2269588ddcfSespie RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this 2279588ddcfSespie isn't minimal, since other operators, such as \`, aren't disabled. */ 2289588ddcfSespie #define RE_SYNTAX_POSIX_MINIMAL_BASIC \ 2299588ddcfSespie (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) 2309588ddcfSespie 2319588ddcfSespie #define RE_SYNTAX_POSIX_EXTENDED \ 2329588ddcfSespie (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ 2339588ddcfSespie | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ 2349588ddcfSespie | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 2359588ddcfSespie | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD) 2369588ddcfSespie 2379588ddcfSespie /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is 2389588ddcfSespie removed and RE_NO_BK_REFS is added. */ 2399588ddcfSespie #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ 2409588ddcfSespie (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ 2419588ddcfSespie | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ 2429588ddcfSespie | RE_NO_BK_PARENS | RE_NO_BK_REFS \ 2439588ddcfSespie | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) 2449588ddcfSespie /* [[[end syntaxes]]] */ 2459588ddcfSespie 2469588ddcfSespie /* Maximum number of duplicates an interval can allow. Some systems 2479588ddcfSespie (erroneously) define this in other header files, but we want our 2489588ddcfSespie value, so remove any previous define. */ 2499588ddcfSespie #ifdef RE_DUP_MAX 2509588ddcfSespie # undef RE_DUP_MAX 2519588ddcfSespie #endif 2529588ddcfSespie /* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */ 2539588ddcfSespie #define RE_DUP_MAX (0x7fff) 2549588ddcfSespie 2559588ddcfSespie 2569588ddcfSespie /* POSIX `cflags' bits (i.e., information for `regcomp'). */ 2579588ddcfSespie 2589588ddcfSespie /* If this bit is set, then use extended regular expression syntax. 2599588ddcfSespie If not set, then use basic regular expression syntax. */ 2609588ddcfSespie #define REG_EXTENDED 1 2619588ddcfSespie 2629588ddcfSespie /* If this bit is set, then ignore case when matching. 2639588ddcfSespie If not set, then case is significant. */ 2649588ddcfSespie #define REG_ICASE (REG_EXTENDED << 1) 2659588ddcfSespie 2669588ddcfSespie /* If this bit is set, then anchors do not match at newline 2679588ddcfSespie characters in the string. 2689588ddcfSespie If not set, then anchors do match at newlines. */ 2699588ddcfSespie #define REG_NEWLINE (REG_ICASE << 1) 2709588ddcfSespie 2719588ddcfSespie /* If this bit is set, then report only success or fail in regexec. 2729588ddcfSespie If not set, then returns differ between not matching and errors. */ 2739588ddcfSespie #define REG_NOSUB (REG_NEWLINE << 1) 2749588ddcfSespie 2759588ddcfSespie 2769588ddcfSespie /* POSIX `eflags' bits (i.e., information for regexec). */ 2779588ddcfSespie 2789588ddcfSespie /* If this bit is set, then the beginning-of-line operator doesn't match 2799588ddcfSespie the beginning of the string (presumably because it's not the 2809588ddcfSespie beginning of a line). 2819588ddcfSespie If not set, then the beginning-of-line operator does match the 2829588ddcfSespie beginning of the string. */ 2839588ddcfSespie #define REG_NOTBOL 1 2849588ddcfSespie 2859588ddcfSespie /* Like REG_NOTBOL, except for the end-of-line. */ 2869588ddcfSespie #define REG_NOTEOL (1 << 1) 2879588ddcfSespie 2889588ddcfSespie 2899588ddcfSespie /* If any error codes are removed, changed, or added, update the 2909588ddcfSespie `re_error_msg' table in regex.c. */ 2919588ddcfSespie typedef enum 2929588ddcfSespie { 2939588ddcfSespie #ifdef _XOPEN_SOURCE 2949588ddcfSespie REG_ENOSYS = -1, /* This will never happen for this implementation. */ 2959588ddcfSespie #endif 2969588ddcfSespie 2979588ddcfSespie REG_NOERROR = 0, /* Success. */ 2989588ddcfSespie REG_NOMATCH, /* Didn't find a match (for regexec). */ 2999588ddcfSespie 3009588ddcfSespie /* POSIX regcomp return error codes. (In the order listed in the 3019588ddcfSespie standard.) */ 3029588ddcfSespie REG_BADPAT, /* Invalid pattern. */ 3039588ddcfSespie REG_ECOLLATE, /* Not implemented. */ 3049588ddcfSespie REG_ECTYPE, /* Invalid character class name. */ 3059588ddcfSespie REG_EESCAPE, /* Trailing backslash. */ 3069588ddcfSespie REG_ESUBREG, /* Invalid back reference. */ 3079588ddcfSespie REG_EBRACK, /* Unmatched left bracket. */ 3089588ddcfSespie REG_EPAREN, /* Parenthesis imbalance. */ 3099588ddcfSespie REG_EBRACE, /* Unmatched \{. */ 3109588ddcfSespie REG_BADBR, /* Invalid contents of \{\}. */ 3119588ddcfSespie REG_ERANGE, /* Invalid range end. */ 3129588ddcfSespie REG_ESPACE, /* Ran out of memory. */ 3139588ddcfSespie REG_BADRPT, /* No preceding re for repetition op. */ 3149588ddcfSespie 3159588ddcfSespie /* Error codes we've added. */ 3169588ddcfSespie REG_EEND, /* Premature end. */ 3179588ddcfSespie REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ 3189588ddcfSespie REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ 3199588ddcfSespie } reg_errcode_t; 3209588ddcfSespie 3219588ddcfSespie /* This data structure represents a compiled pattern. Before calling 3229588ddcfSespie the pattern compiler, the fields `buffer', `allocated', `fastmap', 3239588ddcfSespie `translate', and `no_sub' can be set. After the pattern has been 3249588ddcfSespie compiled, the `re_nsub' field is available. All other fields are 3259588ddcfSespie private to the regex routines. */ 3269588ddcfSespie 3279588ddcfSespie #ifndef RE_TRANSLATE_TYPE 3289588ddcfSespie # define RE_TRANSLATE_TYPE char * 3299588ddcfSespie #endif 3309588ddcfSespie 3319588ddcfSespie struct re_pattern_buffer 3329588ddcfSespie { 3339588ddcfSespie /* [[[begin pattern_buffer]]] */ 3349588ddcfSespie /* Space that holds the compiled pattern. It is declared as 3359588ddcfSespie `unsigned char *' because its elements are 3369588ddcfSespie sometimes used as array indexes. */ 3379588ddcfSespie unsigned char *buffer; 3389588ddcfSespie 3399588ddcfSespie /* Number of bytes to which `buffer' points. */ 3409588ddcfSespie unsigned long int allocated; 3419588ddcfSespie 3429588ddcfSespie /* Number of bytes actually used in `buffer'. */ 3439588ddcfSespie unsigned long int used; 3449588ddcfSespie 3459588ddcfSespie /* Syntax setting with which the pattern was compiled. */ 3469588ddcfSespie reg_syntax_t syntax; 3479588ddcfSespie 3489588ddcfSespie /* Pointer to a fastmap, if any, otherwise zero. re_search uses 3499588ddcfSespie the fastmap, if there is one, to skip over impossible 3509588ddcfSespie starting points for matches. */ 3519588ddcfSespie char *fastmap; 3529588ddcfSespie 3539588ddcfSespie /* Either a translate table to apply to all characters before 3549588ddcfSespie comparing them, or zero for no translation. The translation 3559588ddcfSespie is applied to a pattern when it is compiled and to a string 3569588ddcfSespie when it is matched. */ 3579588ddcfSespie RE_TRANSLATE_TYPE translate; 3589588ddcfSespie 3599588ddcfSespie /* Number of subexpressions found by the compiler. */ 3609588ddcfSespie size_t re_nsub; 3619588ddcfSespie 3629588ddcfSespie /* Zero if this pattern cannot match the empty string, one else. 3639588ddcfSespie Well, in truth it's used only in `re_search_2', to see 3649588ddcfSespie whether or not we should use the fastmap, so we don't set 3659588ddcfSespie this absolutely perfectly; see `re_compile_fastmap' (the 3669588ddcfSespie `duplicate' case). */ 3679588ddcfSespie unsigned can_be_null : 1; 3689588ddcfSespie 3699588ddcfSespie /* If REGS_UNALLOCATED, allocate space in the `regs' structure 3709588ddcfSespie for `max (RE_NREGS, re_nsub + 1)' groups. 3719588ddcfSespie If REGS_REALLOCATE, reallocate space if necessary. 3729588ddcfSespie If REGS_FIXED, use what's there. */ 3739588ddcfSespie #define REGS_UNALLOCATED 0 3749588ddcfSespie #define REGS_REALLOCATE 1 3759588ddcfSespie #define REGS_FIXED 2 3769588ddcfSespie unsigned regs_allocated : 2; 3779588ddcfSespie 3789588ddcfSespie /* Set to zero when `regex_compile' compiles a pattern; set to one 3799588ddcfSespie by `re_compile_fastmap' if it updates the fastmap. */ 3809588ddcfSespie unsigned fastmap_accurate : 1; 3819588ddcfSespie 3829588ddcfSespie /* If set, `re_match_2' does not return information about 3839588ddcfSespie subexpressions. */ 3849588ddcfSespie unsigned no_sub : 1; 3859588ddcfSespie 3869588ddcfSespie /* If set, a beginning-of-line anchor doesn't match at the 3879588ddcfSespie beginning of the string. */ 3889588ddcfSespie unsigned not_bol : 1; 3899588ddcfSespie 3909588ddcfSespie /* Similarly for an end-of-line anchor. */ 3919588ddcfSespie unsigned not_eol : 1; 3929588ddcfSespie 3939588ddcfSespie /* If true, an anchor at a newline matches. */ 3949588ddcfSespie unsigned newline_anchor : 1; 3959588ddcfSespie 3969588ddcfSespie /* [[[end pattern_buffer]]] */ 3979588ddcfSespie }; 3989588ddcfSespie 3999588ddcfSespie typedef struct re_pattern_buffer regex_t; 4009588ddcfSespie 4019588ddcfSespie /* Type for byte offsets within the string. POSIX mandates this. */ 4029588ddcfSespie typedef int regoff_t; 4039588ddcfSespie 4049588ddcfSespie 4059588ddcfSespie /* This is the structure we store register match data in. See 4069588ddcfSespie regex.texinfo for a full description of what registers match. */ 4079588ddcfSespie struct re_registers 4089588ddcfSespie { 4099588ddcfSespie unsigned num_regs; 4109588ddcfSespie regoff_t *start; 4119588ddcfSespie regoff_t *end; 4129588ddcfSespie }; 4139588ddcfSespie 4149588ddcfSespie 4159588ddcfSespie /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, 4169588ddcfSespie `re_match_2' returns information about at least this many registers 4179588ddcfSespie the first time a `regs' structure is passed. */ 4189588ddcfSespie #ifndef RE_NREGS 4199588ddcfSespie # define RE_NREGS 30 4209588ddcfSespie #endif 4219588ddcfSespie 4229588ddcfSespie 4239588ddcfSespie /* POSIX specification for registers. Aside from the different names than 4249588ddcfSespie `re_registers', POSIX uses an array of structures, instead of a 4259588ddcfSespie structure of arrays. */ 4269588ddcfSespie typedef struct 4279588ddcfSespie { 4289588ddcfSespie regoff_t rm_so; /* Byte offset from string's start to substring's start. */ 4299588ddcfSespie regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ 4309588ddcfSespie } regmatch_t; 4319588ddcfSespie 4329588ddcfSespie /* Declarations for routines. */ 4339588ddcfSespie 4349588ddcfSespie /* To avoid duplicating every routine declaration -- once with a 4359588ddcfSespie prototype (if we are ANSI), and once without (if we aren't) -- we 4369588ddcfSespie use the following macro to declare argument types. This 4379588ddcfSespie unfortunately clutters up the declarations a bit, but I think it's 4389588ddcfSespie worth it. */ 4399588ddcfSespie 4409588ddcfSespie /* Sets the current default syntax to SYNTAX, and return the old syntax. 4419588ddcfSespie You can also simply assign to the `re_syntax_options' variable. */ 442*20fce977Smiod extern reg_syntax_t re_set_syntax (reg_syntax_t syntax); 4439588ddcfSespie 4449588ddcfSespie /* Compile the regular expression PATTERN, with length LENGTH 4459588ddcfSespie and syntax given by the global `re_syntax_options', into the buffer 4469588ddcfSespie BUFFER. Return NULL if successful, and an error string if not. */ 447*20fce977Smiod extern const char *re_compile_pattern (const char *pattern, size_t length, 448*20fce977Smiod struct re_pattern_buffer *buffer); 4499588ddcfSespie 4509588ddcfSespie 4519588ddcfSespie /* Compile a fastmap for the compiled pattern in BUFFER; used to 4529588ddcfSespie accelerate searches. Return 0 if successful and -2 if was an 4539588ddcfSespie internal error. */ 454*20fce977Smiod extern int re_compile_fastmap (struct re_pattern_buffer *buffer); 4559588ddcfSespie 4569588ddcfSespie 4579588ddcfSespie /* Search in the string STRING (with length LENGTH) for the pattern 4589588ddcfSespie compiled into BUFFER. Start searching at position START, for RANGE 4599588ddcfSespie characters. Return the starting position of the match, -1 for no 4609588ddcfSespie match, or -2 for an internal error. Also return register 4619588ddcfSespie information in REGS (if REGS and BUFFER->no_sub are nonzero). */ 462*20fce977Smiod extern int re_search (struct re_pattern_buffer *buffer, const char *string, 463*20fce977Smiod int length, int start, int range, 464*20fce977Smiod struct re_registers *regs); 4659588ddcfSespie 4669588ddcfSespie 4679588ddcfSespie /* Like `re_search', but search in the concatenation of STRING1 and 4689588ddcfSespie STRING2. Also, stop searching at index START + STOP. */ 469*20fce977Smiod extern int re_search_2 (struct re_pattern_buffer *buffer, const char *string1, 4709588ddcfSespie int length1, const char *string2, int length2, 471*20fce977Smiod int start, int range, struct re_registers *regs, 472*20fce977Smiod int stop); 4739588ddcfSespie 4749588ddcfSespie 4759588ddcfSespie /* Like `re_search', but return how many characters in STRING the regexp 4769588ddcfSespie in BUFFER matched, starting at position START. */ 477*20fce977Smiod extern int re_match (struct re_pattern_buffer *buffer, const char *string, 478*20fce977Smiod int length, int start, struct re_registers *regs); 4799588ddcfSespie 4809588ddcfSespie 4819588ddcfSespie /* Relates to `re_match' as `re_search_2' relates to `re_search'. */ 482*20fce977Smiod extern int re_match_2 (struct re_pattern_buffer *buffer, const char *string1, 4839588ddcfSespie int length1, const char *string2, int length2, 484*20fce977Smiod int start, struct re_registers *regs, int stop); 4859588ddcfSespie 4869588ddcfSespie 4879588ddcfSespie /* Set REGS to hold NUM_REGS registers, storing them in STARTS and 4889588ddcfSespie ENDS. Subsequent matches using BUFFER and REGS will use this memory 4899588ddcfSespie for recording register information. STARTS and ENDS must be 4909588ddcfSespie allocated with malloc, and must each be at least `NUM_REGS * sizeof 4919588ddcfSespie (regoff_t)' bytes long. 4929588ddcfSespie 4939588ddcfSespie If NUM_REGS == 0, then subsequent matches should allocate their own 4949588ddcfSespie register data. 4959588ddcfSespie 4969588ddcfSespie Unless this function is called, the first search or match using 4979588ddcfSespie PATTERN_BUFFER will allocate its own register data, without 4989588ddcfSespie freeing the old data. */ 499*20fce977Smiod extern void re_set_registers (struct re_pattern_buffer *buffer, 500*20fce977Smiod struct re_registers *regs, 501*20fce977Smiod unsigned num_regs, regoff_t *starts, 502*20fce977Smiod regoff_t *ends); 5039588ddcfSespie 5049588ddcfSespie #if defined _REGEX_RE_COMP || defined _LIBC 5059588ddcfSespie # ifndef _CRAY 5069588ddcfSespie /* 4.2 bsd compatibility. */ 507*20fce977Smiod extern char *re_comp (const char *); 508*20fce977Smiod extern int re_exec (const char *); 5099588ddcfSespie # endif 5109588ddcfSespie #endif 5119588ddcfSespie 5129588ddcfSespie /* GCC 2.95 and later have "__restrict"; C99 compilers have 5139588ddcfSespie "restrict", and "configure" may have defined "restrict". */ 5149588ddcfSespie #ifndef __restrict 5159588ddcfSespie # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) 5169588ddcfSespie # if defined restrict || 199901L <= __STDC_VERSION__ 5179588ddcfSespie # define __restrict restrict 5189588ddcfSespie # else 5199588ddcfSespie # define __restrict 5209588ddcfSespie # endif 5219588ddcfSespie # endif 5229588ddcfSespie #endif 5239588ddcfSespie 5249588ddcfSespie /* GCC 3.1 and later support declaring arrays as non-overlapping 5259588ddcfSespie using the syntax array_name[restrict] */ 5269588ddcfSespie #ifndef __restrict_arr 5279588ddcfSespie # if ! (3 < __GNUC__ || (3 == __GNUC__ && 1 <= __GNUC_MINOR__)) || defined (__GNUG__) 5289588ddcfSespie # define __restrict_arr 5299588ddcfSespie # else 5309588ddcfSespie # define __restrict_arr __restrict 5319588ddcfSespie # endif 5329588ddcfSespie #endif 5339588ddcfSespie 5349588ddcfSespie /* POSIX compatibility. */ 535*20fce977Smiod extern int regcomp (regex_t *__restrict __preg, 5369588ddcfSespie const char *__restrict __pattern, 537*20fce977Smiod int __cflags); 5389588ddcfSespie 539*20fce977Smiod #if (__GNUC__) 540*20fce977Smiod __extension__ 541*20fce977Smiod #endif 542*20fce977Smiod extern int regexec (const regex_t *__restrict __preg, 5439588ddcfSespie const char *__restrict __string, size_t __nmatch, 5449588ddcfSespie regmatch_t __pmatch[__restrict_arr], 545*20fce977Smiod int __eflags); 5469588ddcfSespie 547*20fce977Smiod extern size_t regerror (int __errcode, const regex_t *__preg, 548*20fce977Smiod char *__errbuf, size_t __errbuf_size); 5499588ddcfSespie 550*20fce977Smiod extern void regfree (regex_t *__preg); 5519588ddcfSespie 5529588ddcfSespie 5539588ddcfSespie #ifdef __cplusplus 5549588ddcfSespie } 5559588ddcfSespie #endif /* C++ */ 5569588ddcfSespie 5579588ddcfSespie #endif /* regex.h */ 5589588ddcfSespie 5599588ddcfSespie /* 5609588ddcfSespie Local variables: 5619588ddcfSespie make-backup-files: t 5629588ddcfSespie version-control: t 5639588ddcfSespie trim-versions-without-asking: nil 5649588ddcfSespie End: 5659588ddcfSespie */ 566