11e72d8d2Sderaadt /* Definitions for data structures and routines for the regular 21e72d8d2Sderaadt expression library, version 0.12. 31e72d8d2Sderaadt 4*e77048c1Stholo Copyright (C) 1985, 89, 90, 91, 92, 93, 95 Free Software Foundation, Inc. 51e72d8d2Sderaadt 61e72d8d2Sderaadt This program is free software; you can redistribute it and/or modify 71e72d8d2Sderaadt it under the terms of the GNU General Public License as published by 81e72d8d2Sderaadt the Free Software Foundation; either version 2, or (at your option) 91e72d8d2Sderaadt any later version. 101e72d8d2Sderaadt 111e72d8d2Sderaadt This program is distributed in the hope that it will be useful, 121e72d8d2Sderaadt but WITHOUT ANY WARRANTY; without even the implied warranty of 131e72d8d2Sderaadt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*e77048c1Stholo GNU General Public License for more details. 15*e77048c1Stholo 16*e77048c1Stholo You should have received a copy of the GNU General Public License 17*e77048c1Stholo along with this program; if not, write to the Free Software 18*e77048c1Stholo Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 19*e77048c1Stholo USA. */ 201e72d8d2Sderaadt 211e72d8d2Sderaadt #ifndef __REGEXP_LIBRARY_H__ 221e72d8d2Sderaadt #define __REGEXP_LIBRARY_H__ 231e72d8d2Sderaadt 241e72d8d2Sderaadt /* POSIX says that <sys/types.h> must be included (by the caller) before 251e72d8d2Sderaadt <regex.h>. */ 261e72d8d2Sderaadt 27*e77048c1Stholo #if !defined (_POSIX_C_SOURCE) && !defined (_POSIX_SOURCE) && defined (VMS) 281e72d8d2Sderaadt /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it 291e72d8d2Sderaadt should be there. */ 301e72d8d2Sderaadt #include <stddef.h> 311e72d8d2Sderaadt #endif 321e72d8d2Sderaadt 331e72d8d2Sderaadt 341e72d8d2Sderaadt /* The following bits are used to determine the regexp syntax we 351e72d8d2Sderaadt recognize. The set/not-set meanings are chosen so that Emacs syntax 361e72d8d2Sderaadt remains the value 0. The bits are given in alphabetical order, and 371e72d8d2Sderaadt the definitions shifted by one from the previous bit; thus, when we 381e72d8d2Sderaadt add or remove a bit, only one other definition need change. */ 391e72d8d2Sderaadt typedef unsigned reg_syntax_t; 401e72d8d2Sderaadt 411e72d8d2Sderaadt /* If this bit is not set, then \ inside a bracket expression is literal. 421e72d8d2Sderaadt If set, then such a \ quotes the following character. */ 431e72d8d2Sderaadt #define RE_BACKSLASH_ESCAPE_IN_LISTS (1) 441e72d8d2Sderaadt 451e72d8d2Sderaadt /* If this bit is not set, then + and ? are operators, and \+ and \? are 461e72d8d2Sderaadt literals. 471e72d8d2Sderaadt If set, then \+ and \? are operators and + and ? are literals. */ 481e72d8d2Sderaadt #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1) 491e72d8d2Sderaadt 501e72d8d2Sderaadt /* If this bit is set, then character classes are supported. They are: 511e72d8d2Sderaadt [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], 521e72d8d2Sderaadt [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. 531e72d8d2Sderaadt If not set, then character classes are not supported. */ 541e72d8d2Sderaadt #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1) 551e72d8d2Sderaadt 561e72d8d2Sderaadt /* If this bit is set, then ^ and $ are always anchors (outside bracket 571e72d8d2Sderaadt expressions, of course). 581e72d8d2Sderaadt If this bit is not set, then it depends: 591e72d8d2Sderaadt ^ is an anchor if it is at the beginning of a regular 601e72d8d2Sderaadt expression or after an open-group or an alternation operator; 611e72d8d2Sderaadt $ is an anchor if it is at the end of a regular expression, or 621e72d8d2Sderaadt before a close-group or an alternation operator. 631e72d8d2Sderaadt 641e72d8d2Sderaadt This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because 651e72d8d2Sderaadt POSIX draft 11.2 says that * etc. in leading positions is undefined. 661e72d8d2Sderaadt We already implemented a previous draft which made those constructs 671e72d8d2Sderaadt invalid, though, so we haven't changed the code back. */ 681e72d8d2Sderaadt #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1) 691e72d8d2Sderaadt 701e72d8d2Sderaadt /* If this bit is set, then special characters are always special 711e72d8d2Sderaadt regardless of where they are in the pattern. 721e72d8d2Sderaadt If this bit is not set, then special characters are special only in 731e72d8d2Sderaadt some contexts; otherwise they are ordinary. Specifically, 741e72d8d2Sderaadt * + ? and intervals are only special when not after the beginning, 751e72d8d2Sderaadt open-group, or alternation operator. */ 761e72d8d2Sderaadt #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1) 771e72d8d2Sderaadt 781e72d8d2Sderaadt /* If this bit is set, then *, +, ?, and { cannot be first in an re or 791e72d8d2Sderaadt immediately after an alternation or begin-group operator. */ 801e72d8d2Sderaadt #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1) 811e72d8d2Sderaadt 821e72d8d2Sderaadt /* If this bit is set, then . matches newline. 831e72d8d2Sderaadt If not set, then it doesn't. */ 841e72d8d2Sderaadt #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1) 851e72d8d2Sderaadt 861e72d8d2Sderaadt /* If this bit is set, then . doesn't match NUL. 871e72d8d2Sderaadt If not set, then it does. */ 881e72d8d2Sderaadt #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1) 891e72d8d2Sderaadt 901e72d8d2Sderaadt /* If this bit is set, nonmatching lists [^...] do not match newline. 911e72d8d2Sderaadt If not set, they do. */ 921e72d8d2Sderaadt #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1) 931e72d8d2Sderaadt 941e72d8d2Sderaadt /* If this bit is set, either \{...\} or {...} defines an 951e72d8d2Sderaadt interval, depending on RE_NO_BK_BRACES. 961e72d8d2Sderaadt If not set, \{, \}, {, and } are literals. */ 971e72d8d2Sderaadt #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1) 981e72d8d2Sderaadt 991e72d8d2Sderaadt /* If this bit is set, +, ? and | aren't recognized as operators. 1001e72d8d2Sderaadt If not set, they are. */ 1011e72d8d2Sderaadt #define RE_LIMITED_OPS (RE_INTERVALS << 1) 1021e72d8d2Sderaadt 1031e72d8d2Sderaadt /* If this bit is set, newline is an alternation operator. 1041e72d8d2Sderaadt If not set, newline is literal. */ 1051e72d8d2Sderaadt #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1) 1061e72d8d2Sderaadt 1071e72d8d2Sderaadt /* If this bit is set, then `{...}' defines an interval, and \{ and \} 1081e72d8d2Sderaadt are literals. 1091e72d8d2Sderaadt If not set, then `\{...\}' defines an interval. */ 1101e72d8d2Sderaadt #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1) 1111e72d8d2Sderaadt 1121e72d8d2Sderaadt /* If this bit is set, (...) defines a group, and \( and \) are literals. 1131e72d8d2Sderaadt If not set, \(...\) defines a group, and ( and ) are literals. */ 1141e72d8d2Sderaadt #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1) 1151e72d8d2Sderaadt 1161e72d8d2Sderaadt /* If this bit is set, then \<digit> matches <digit>. 1171e72d8d2Sderaadt If not set, then \<digit> is a back-reference. */ 1181e72d8d2Sderaadt #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1) 1191e72d8d2Sderaadt 1201e72d8d2Sderaadt /* If this bit is set, then | is an alternation operator, and \| is literal. 1211e72d8d2Sderaadt If not set, then \| is an alternation operator, and | is literal. */ 1221e72d8d2Sderaadt #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1) 1231e72d8d2Sderaadt 1241e72d8d2Sderaadt /* If this bit is set, then an ending range point collating higher 1251e72d8d2Sderaadt than the starting range point, as in [z-a], is invalid. 1261e72d8d2Sderaadt If not set, then when ending range point collates higher than the 1271e72d8d2Sderaadt starting range point, the range is ignored. */ 1281e72d8d2Sderaadt #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1) 1291e72d8d2Sderaadt 1301e72d8d2Sderaadt /* If this bit is set, then an unmatched ) is ordinary. 1311e72d8d2Sderaadt If not set, then an unmatched ) is invalid. */ 1321e72d8d2Sderaadt #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1) 1331e72d8d2Sderaadt 134*e77048c1Stholo /* If this bit is set, succeed as soon as we match the whole pattern, 135*e77048c1Stholo without further backtracking. */ 136*e77048c1Stholo #define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1) 137*e77048c1Stholo 1381e72d8d2Sderaadt /* This global variable defines the particular regexp syntax to use (for 1391e72d8d2Sderaadt some interfaces). When a regexp is compiled, the syntax used is 1401e72d8d2Sderaadt stored in the pattern buffer, so changing this does not affect 1411e72d8d2Sderaadt already-compiled regexps. */ 1421e72d8d2Sderaadt extern reg_syntax_t re_syntax_options; 143*e77048c1Stholo 144*e77048c1Stholo #ifdef emacs 145*e77048c1Stholo /* In Emacs, this is the string or buffer in which we 146*e77048c1Stholo are matching. It is used for looking up syntax properties. */ 147*e77048c1Stholo extern Lisp_Object re_match_object; 148*e77048c1Stholo #endif 149*e77048c1Stholo 1501e72d8d2Sderaadt 1511e72d8d2Sderaadt /* Define combinations of the above bits for the standard possibilities. 1521e72d8d2Sderaadt (The [[[ comments delimit what gets put into the Texinfo file, so 1531e72d8d2Sderaadt don't delete them!) */ 1541e72d8d2Sderaadt /* [[[begin syntaxes]]] */ 1551e72d8d2Sderaadt #define RE_SYNTAX_EMACS 0 1561e72d8d2Sderaadt 1571e72d8d2Sderaadt #define RE_SYNTAX_AWK \ 1581e72d8d2Sderaadt (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \ 1591e72d8d2Sderaadt | RE_NO_BK_PARENS | RE_NO_BK_REFS \ 1601e72d8d2Sderaadt | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \ 1611e72d8d2Sderaadt | RE_UNMATCHED_RIGHT_PAREN_ORD) 1621e72d8d2Sderaadt 1631e72d8d2Sderaadt #define RE_SYNTAX_POSIX_AWK \ 1641e72d8d2Sderaadt (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS) 1651e72d8d2Sderaadt 1661e72d8d2Sderaadt #define RE_SYNTAX_GREP \ 1671e72d8d2Sderaadt (RE_BK_PLUS_QM | RE_CHAR_CLASSES \ 1681e72d8d2Sderaadt | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \ 1691e72d8d2Sderaadt | RE_NEWLINE_ALT) 1701e72d8d2Sderaadt 1711e72d8d2Sderaadt #define RE_SYNTAX_EGREP \ 1721e72d8d2Sderaadt (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \ 1731e72d8d2Sderaadt | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \ 1741e72d8d2Sderaadt | RE_NEWLINE_ALT | RE_NO_BK_PARENS \ 1751e72d8d2Sderaadt | RE_NO_BK_VBAR) 1761e72d8d2Sderaadt 1771e72d8d2Sderaadt #define RE_SYNTAX_POSIX_EGREP \ 1781e72d8d2Sderaadt (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES) 1791e72d8d2Sderaadt 1801e72d8d2Sderaadt /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ 1811e72d8d2Sderaadt #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC 1821e72d8d2Sderaadt 1831e72d8d2Sderaadt #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC 1841e72d8d2Sderaadt 1851e72d8d2Sderaadt /* Syntax bits common to both basic and extended POSIX regex syntax. */ 1861e72d8d2Sderaadt #define _RE_SYNTAX_POSIX_COMMON \ 1871e72d8d2Sderaadt (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \ 1881e72d8d2Sderaadt | RE_INTERVALS | RE_NO_EMPTY_RANGES) 1891e72d8d2Sderaadt 1901e72d8d2Sderaadt #define RE_SYNTAX_POSIX_BASIC \ 1911e72d8d2Sderaadt (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) 1921e72d8d2Sderaadt 1931e72d8d2Sderaadt /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes 1941e72d8d2Sderaadt RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this 1951e72d8d2Sderaadt isn't minimal, since other operators, such as \`, aren't disabled. */ 1961e72d8d2Sderaadt #define RE_SYNTAX_POSIX_MINIMAL_BASIC \ 1971e72d8d2Sderaadt (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS) 1981e72d8d2Sderaadt 1991e72d8d2Sderaadt #define RE_SYNTAX_POSIX_EXTENDED \ 2001e72d8d2Sderaadt (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ 2011e72d8d2Sderaadt | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \ 2021e72d8d2Sderaadt | RE_NO_BK_PARENS | RE_NO_BK_VBAR \ 2031e72d8d2Sderaadt | RE_UNMATCHED_RIGHT_PAREN_ORD) 2041e72d8d2Sderaadt 2051e72d8d2Sderaadt /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INVALID_OPS 2061e72d8d2Sderaadt replaces RE_CONTEXT_INDEP_OPS and RE_NO_BK_REFS is added. */ 2071e72d8d2Sderaadt #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \ 2081e72d8d2Sderaadt (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \ 2091e72d8d2Sderaadt | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \ 2101e72d8d2Sderaadt | RE_NO_BK_PARENS | RE_NO_BK_REFS \ 2111e72d8d2Sderaadt | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD) 2121e72d8d2Sderaadt /* [[[end syntaxes]]] */ 2131e72d8d2Sderaadt 2141e72d8d2Sderaadt /* Maximum number of duplicates an interval can allow. Some systems 2151e72d8d2Sderaadt (erroneously) define this in other header files, but we want our 2161e72d8d2Sderaadt value, so remove any previous define. */ 2171e72d8d2Sderaadt #ifdef RE_DUP_MAX 2181e72d8d2Sderaadt #undef RE_DUP_MAX 2191e72d8d2Sderaadt #endif 2201e72d8d2Sderaadt #define RE_DUP_MAX ((1 << 15) - 1) 2211e72d8d2Sderaadt 2221e72d8d2Sderaadt 2231e72d8d2Sderaadt /* POSIX `cflags' bits (i.e., information for `regcomp'). */ 2241e72d8d2Sderaadt 2251e72d8d2Sderaadt /* If this bit is set, then use extended regular expression syntax. 2261e72d8d2Sderaadt If not set, then use basic regular expression syntax. */ 2271e72d8d2Sderaadt #define REG_EXTENDED 1 2281e72d8d2Sderaadt 2291e72d8d2Sderaadt /* If this bit is set, then ignore case when matching. 2301e72d8d2Sderaadt If not set, then case is significant. */ 2311e72d8d2Sderaadt #define REG_ICASE (REG_EXTENDED << 1) 2321e72d8d2Sderaadt 2331e72d8d2Sderaadt /* If this bit is set, then anchors do not match at newline 2341e72d8d2Sderaadt characters in the string. 2351e72d8d2Sderaadt If not set, then anchors do match at newlines. */ 2361e72d8d2Sderaadt #define REG_NEWLINE (REG_ICASE << 1) 2371e72d8d2Sderaadt 2381e72d8d2Sderaadt /* If this bit is set, then report only success or fail in regexec. 2391e72d8d2Sderaadt If not set, then returns differ between not matching and errors. */ 2401e72d8d2Sderaadt #define REG_NOSUB (REG_NEWLINE << 1) 2411e72d8d2Sderaadt 2421e72d8d2Sderaadt 2431e72d8d2Sderaadt /* POSIX `eflags' bits (i.e., information for regexec). */ 2441e72d8d2Sderaadt 2451e72d8d2Sderaadt /* If this bit is set, then the beginning-of-line operator doesn't match 2461e72d8d2Sderaadt the beginning of the string (presumably because it's not the 2471e72d8d2Sderaadt beginning of a line). 2481e72d8d2Sderaadt If not set, then the beginning-of-line operator does match the 2491e72d8d2Sderaadt beginning of the string. */ 2501e72d8d2Sderaadt #define REG_NOTBOL 1 2511e72d8d2Sderaadt 2521e72d8d2Sderaadt /* Like REG_NOTBOL, except for the end-of-line. */ 2531e72d8d2Sderaadt #define REG_NOTEOL (1 << 1) 2541e72d8d2Sderaadt 2551e72d8d2Sderaadt 2561e72d8d2Sderaadt /* If any error codes are removed, changed, or added, update the 2571e72d8d2Sderaadt `re_error_msg' table in regex.c. */ 2581e72d8d2Sderaadt typedef enum 2591e72d8d2Sderaadt { 2601e72d8d2Sderaadt REG_NOERROR = 0, /* Success. */ 2611e72d8d2Sderaadt REG_NOMATCH, /* Didn't find a match (for regexec). */ 2621e72d8d2Sderaadt 2631e72d8d2Sderaadt /* POSIX regcomp return error codes. (In the order listed in the 2641e72d8d2Sderaadt standard.) */ 2651e72d8d2Sderaadt REG_BADPAT, /* Invalid pattern. */ 2661e72d8d2Sderaadt REG_ECOLLATE, /* Not implemented. */ 2671e72d8d2Sderaadt REG_ECTYPE, /* Invalid character class name. */ 2681e72d8d2Sderaadt REG_EESCAPE, /* Trailing backslash. */ 2691e72d8d2Sderaadt REG_ESUBREG, /* Invalid back reference. */ 2701e72d8d2Sderaadt REG_EBRACK, /* Unmatched left bracket. */ 2711e72d8d2Sderaadt REG_EPAREN, /* Parenthesis imbalance. */ 2721e72d8d2Sderaadt REG_EBRACE, /* Unmatched \{. */ 2731e72d8d2Sderaadt REG_BADBR, /* Invalid contents of \{\}. */ 2741e72d8d2Sderaadt REG_ERANGE, /* Invalid range end. */ 2751e72d8d2Sderaadt REG_ESPACE, /* Ran out of memory. */ 2761e72d8d2Sderaadt REG_BADRPT, /* No preceding re for repetition op. */ 2771e72d8d2Sderaadt 2781e72d8d2Sderaadt /* Error codes we've added. */ 2791e72d8d2Sderaadt REG_EEND, /* Premature end. */ 2801e72d8d2Sderaadt REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ 2811e72d8d2Sderaadt REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ 2821e72d8d2Sderaadt } reg_errcode_t; 2831e72d8d2Sderaadt 2841e72d8d2Sderaadt /* This data structure represents a compiled pattern. Before calling 2851e72d8d2Sderaadt the pattern compiler, the fields `buffer', `allocated', `fastmap', 2861e72d8d2Sderaadt `translate', and `no_sub' can be set. After the pattern has been 2871e72d8d2Sderaadt compiled, the `re_nsub' field is available. All other fields are 2881e72d8d2Sderaadt private to the regex routines. */ 2891e72d8d2Sderaadt 290*e77048c1Stholo #ifndef RE_TRANSLATE_TYPE 291*e77048c1Stholo #define RE_TRANSLATE_TYPE char * 292*e77048c1Stholo #define RE_TRANSLATE(TBL, C) ((TBL)[C]) 293*e77048c1Stholo #define RE_TRANSLATE_P(TBL) (TBL) 294*e77048c1Stholo #endif 295*e77048c1Stholo 2961e72d8d2Sderaadt struct re_pattern_buffer 2971e72d8d2Sderaadt { 2981e72d8d2Sderaadt /* [[[begin pattern_buffer]]] */ 2991e72d8d2Sderaadt /* Space that holds the compiled pattern. It is declared as 3001e72d8d2Sderaadt `unsigned char *' because its elements are 3011e72d8d2Sderaadt sometimes used as array indexes. */ 3021e72d8d2Sderaadt unsigned char *buffer; 3031e72d8d2Sderaadt 3041e72d8d2Sderaadt /* Number of bytes to which `buffer' points. */ 3051e72d8d2Sderaadt unsigned long allocated; 3061e72d8d2Sderaadt 3071e72d8d2Sderaadt /* Number of bytes actually used in `buffer'. */ 3081e72d8d2Sderaadt unsigned long used; 3091e72d8d2Sderaadt 3101e72d8d2Sderaadt /* Syntax setting with which the pattern was compiled. */ 3111e72d8d2Sderaadt reg_syntax_t syntax; 3121e72d8d2Sderaadt 3131e72d8d2Sderaadt /* Pointer to a fastmap, if any, otherwise zero. re_search uses 3141e72d8d2Sderaadt the fastmap, if there is one, to skip over impossible 3151e72d8d2Sderaadt starting points for matches. */ 3161e72d8d2Sderaadt char *fastmap; 3171e72d8d2Sderaadt 3181e72d8d2Sderaadt /* Either a translate table to apply to all characters before 3191e72d8d2Sderaadt comparing them, or zero for no translation. The translation 3201e72d8d2Sderaadt is applied to a pattern when it is compiled and to a string 3211e72d8d2Sderaadt when it is matched. */ 322*e77048c1Stholo RE_TRANSLATE_TYPE translate; 3231e72d8d2Sderaadt 3241e72d8d2Sderaadt /* Number of subexpressions found by the compiler. */ 3251e72d8d2Sderaadt size_t re_nsub; 3261e72d8d2Sderaadt 3271e72d8d2Sderaadt /* Zero if this pattern cannot match the empty string, one else. 3281e72d8d2Sderaadt Well, in truth it's used only in `re_search_2', to see 3291e72d8d2Sderaadt whether or not we should use the fastmap, so we don't set 3301e72d8d2Sderaadt this absolutely perfectly; see `re_compile_fastmap' (the 3311e72d8d2Sderaadt `duplicate' case). */ 3321e72d8d2Sderaadt unsigned can_be_null : 1; 3331e72d8d2Sderaadt 3341e72d8d2Sderaadt /* If REGS_UNALLOCATED, allocate space in the `regs' structure 3351e72d8d2Sderaadt for `max (RE_NREGS, re_nsub + 1)' groups. 3361e72d8d2Sderaadt If REGS_REALLOCATE, reallocate space if necessary. 3371e72d8d2Sderaadt If REGS_FIXED, use what's there. */ 3381e72d8d2Sderaadt #define REGS_UNALLOCATED 0 3391e72d8d2Sderaadt #define REGS_REALLOCATE 1 3401e72d8d2Sderaadt #define REGS_FIXED 2 3411e72d8d2Sderaadt unsigned regs_allocated : 2; 3421e72d8d2Sderaadt 3431e72d8d2Sderaadt /* Set to zero when `regex_compile' compiles a pattern; set to one 3441e72d8d2Sderaadt by `re_compile_fastmap' if it updates the fastmap. */ 3451e72d8d2Sderaadt unsigned fastmap_accurate : 1; 3461e72d8d2Sderaadt 3471e72d8d2Sderaadt /* If set, `re_match_2' does not return information about 3481e72d8d2Sderaadt subexpressions. */ 3491e72d8d2Sderaadt unsigned no_sub : 1; 3501e72d8d2Sderaadt 3511e72d8d2Sderaadt /* If set, a beginning-of-line anchor doesn't match at the 3521e72d8d2Sderaadt beginning of the string. */ 3531e72d8d2Sderaadt unsigned not_bol : 1; 3541e72d8d2Sderaadt 3551e72d8d2Sderaadt /* Similarly for an end-of-line anchor. */ 3561e72d8d2Sderaadt unsigned not_eol : 1; 3571e72d8d2Sderaadt 3581e72d8d2Sderaadt /* If true, an anchor at a newline matches. */ 3591e72d8d2Sderaadt unsigned newline_anchor : 1; 3601e72d8d2Sderaadt 361*e77048c1Stholo /* If true, multi-byte form in the `buffer' should be recognized as a 362*e77048c1Stholo multibyte character. */ 363*e77048c1Stholo unsigned multibyte : 1; 364*e77048c1Stholo 3651e72d8d2Sderaadt /* [[[end pattern_buffer]]] */ 3661e72d8d2Sderaadt }; 3671e72d8d2Sderaadt 3681e72d8d2Sderaadt typedef struct re_pattern_buffer regex_t; 3691e72d8d2Sderaadt 3701e72d8d2Sderaadt /* Type for byte offsets within the string. POSIX mandates this. */ 3711e72d8d2Sderaadt typedef int regoff_t; 3721e72d8d2Sderaadt 3731e72d8d2Sderaadt 3741e72d8d2Sderaadt /* This is the structure we store register match data in. See 3751e72d8d2Sderaadt regex.texinfo for a full description of what registers match. */ 3761e72d8d2Sderaadt struct re_registers 3771e72d8d2Sderaadt { 3781e72d8d2Sderaadt unsigned num_regs; 3791e72d8d2Sderaadt regoff_t *start; 3801e72d8d2Sderaadt regoff_t *end; 3811e72d8d2Sderaadt }; 3821e72d8d2Sderaadt 3831e72d8d2Sderaadt 3841e72d8d2Sderaadt /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer, 3851e72d8d2Sderaadt `re_match_2' returns information about at least this many registers 3861e72d8d2Sderaadt the first time a `regs' structure is passed. */ 3871e72d8d2Sderaadt #ifndef RE_NREGS 3881e72d8d2Sderaadt #define RE_NREGS 30 3891e72d8d2Sderaadt #endif 3901e72d8d2Sderaadt 3911e72d8d2Sderaadt 3921e72d8d2Sderaadt /* POSIX specification for registers. Aside from the different names than 3931e72d8d2Sderaadt `re_registers', POSIX uses an array of structures, instead of a 3941e72d8d2Sderaadt structure of arrays. */ 3951e72d8d2Sderaadt typedef struct 3961e72d8d2Sderaadt { 3971e72d8d2Sderaadt regoff_t rm_so; /* Byte offset from string's start to substring's start. */ 3981e72d8d2Sderaadt regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ 3991e72d8d2Sderaadt } regmatch_t; 4001e72d8d2Sderaadt 4011e72d8d2Sderaadt /* Declarations for routines. */ 4021e72d8d2Sderaadt 4031e72d8d2Sderaadt /* To avoid duplicating every routine declaration -- once with a 4041e72d8d2Sderaadt prototype (if we are ANSI), and once without (if we aren't) -- we 4051e72d8d2Sderaadt use the following macro to declare argument types. This 4061e72d8d2Sderaadt unfortunately clutters up the declarations a bit, but I think it's 4071e72d8d2Sderaadt worth it. */ 4081e72d8d2Sderaadt 4091e72d8d2Sderaadt #if __STDC__ 4101e72d8d2Sderaadt 4111e72d8d2Sderaadt #define _RE_ARGS(args) args 4121e72d8d2Sderaadt 4131e72d8d2Sderaadt #else /* not __STDC__ */ 4141e72d8d2Sderaadt 4151e72d8d2Sderaadt #define _RE_ARGS(args) () 4161e72d8d2Sderaadt 4171e72d8d2Sderaadt #endif /* not __STDC__ */ 4181e72d8d2Sderaadt 4191e72d8d2Sderaadt /* Sets the current default syntax to SYNTAX, and return the old syntax. 4201e72d8d2Sderaadt You can also simply assign to the `re_syntax_options' variable. */ 4211e72d8d2Sderaadt extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); 4221e72d8d2Sderaadt 4231e72d8d2Sderaadt /* Compile the regular expression PATTERN, with length LENGTH 4241e72d8d2Sderaadt and syntax given by the global `re_syntax_options', into the buffer 4251e72d8d2Sderaadt BUFFER. Return NULL if successful, and an error string if not. */ 4261e72d8d2Sderaadt extern const char *re_compile_pattern 4271e72d8d2Sderaadt _RE_ARGS ((const char *pattern, int length, 4281e72d8d2Sderaadt struct re_pattern_buffer *buffer)); 4291e72d8d2Sderaadt 4301e72d8d2Sderaadt 4311e72d8d2Sderaadt /* Compile a fastmap for the compiled pattern in BUFFER; used to 4321e72d8d2Sderaadt accelerate searches. Return 0 if successful and -2 if was an 4331e72d8d2Sderaadt internal error. */ 4341e72d8d2Sderaadt extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); 4351e72d8d2Sderaadt 4361e72d8d2Sderaadt 4371e72d8d2Sderaadt /* Search in the string STRING (with length LENGTH) for the pattern 4381e72d8d2Sderaadt compiled into BUFFER. Start searching at position START, for RANGE 4391e72d8d2Sderaadt characters. Return the starting position of the match, -1 for no 4401e72d8d2Sderaadt match, or -2 for an internal error. Also return register 4411e72d8d2Sderaadt information in REGS (if REGS and BUFFER->no_sub are nonzero). */ 4421e72d8d2Sderaadt extern int re_search 4431e72d8d2Sderaadt _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, 4441e72d8d2Sderaadt int length, int start, int range, struct re_registers *regs)); 4451e72d8d2Sderaadt 4461e72d8d2Sderaadt 4471e72d8d2Sderaadt /* Like `re_search', but search in the concatenation of STRING1 and 4481e72d8d2Sderaadt STRING2. Also, stop searching at index START + STOP. */ 4491e72d8d2Sderaadt extern int re_search_2 4501e72d8d2Sderaadt _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, 4511e72d8d2Sderaadt int length1, const char *string2, int length2, 4521e72d8d2Sderaadt int start, int range, struct re_registers *regs, int stop)); 4531e72d8d2Sderaadt 4541e72d8d2Sderaadt 4551e72d8d2Sderaadt /* Like `re_search', but return how many characters in STRING the regexp 4561e72d8d2Sderaadt in BUFFER matched, starting at position START. */ 4571e72d8d2Sderaadt extern int re_match 4581e72d8d2Sderaadt _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, 4591e72d8d2Sderaadt int length, int start, struct re_registers *regs)); 4601e72d8d2Sderaadt 4611e72d8d2Sderaadt 4621e72d8d2Sderaadt /* Relates to `re_match' as `re_search_2' relates to `re_search'. */ 4631e72d8d2Sderaadt extern int re_match_2 4641e72d8d2Sderaadt _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, 4651e72d8d2Sderaadt int length1, const char *string2, int length2, 4661e72d8d2Sderaadt int start, struct re_registers *regs, int stop)); 4671e72d8d2Sderaadt 4681e72d8d2Sderaadt 4691e72d8d2Sderaadt /* Set REGS to hold NUM_REGS registers, storing them in STARTS and 4701e72d8d2Sderaadt ENDS. Subsequent matches using BUFFER and REGS will use this memory 4711e72d8d2Sderaadt for recording register information. STARTS and ENDS must be 4721e72d8d2Sderaadt allocated with malloc, and must each be at least `NUM_REGS * sizeof 4731e72d8d2Sderaadt (regoff_t)' bytes long. 4741e72d8d2Sderaadt 4751e72d8d2Sderaadt If NUM_REGS == 0, then subsequent matches should allocate their own 4761e72d8d2Sderaadt register data. 4771e72d8d2Sderaadt 4781e72d8d2Sderaadt Unless this function is called, the first search or match using 4791e72d8d2Sderaadt PATTERN_BUFFER will allocate its own register data, without 4801e72d8d2Sderaadt freeing the old data. */ 4811e72d8d2Sderaadt extern void re_set_registers 4821e72d8d2Sderaadt _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, 4831e72d8d2Sderaadt unsigned num_regs, regoff_t *starts, regoff_t *ends)); 4841e72d8d2Sderaadt 485*e77048c1Stholo #ifdef _REGEX_RE_COMP 486*e77048c1Stholo /* 4.2 bsd compatibility. */ 487*e77048c1Stholo /* CVS: don't use prototypes: they may conflict with system headers. */ 488*e77048c1Stholo extern char *re_comp _RE_ARGS (()); 489*e77048c1Stholo extern int re_exec _RE_ARGS (()); 490*e77048c1Stholo #endif 4911e72d8d2Sderaadt 4921e72d8d2Sderaadt /* POSIX compatibility. */ 4931e72d8d2Sderaadt extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags)); 4941e72d8d2Sderaadt extern int regexec 4951e72d8d2Sderaadt _RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch, 4961e72d8d2Sderaadt regmatch_t pmatch[], int eflags)); 4971e72d8d2Sderaadt extern size_t regerror 4981e72d8d2Sderaadt _RE_ARGS ((int errcode, const regex_t *preg, char *errbuf, 4991e72d8d2Sderaadt size_t errbuf_size)); 5001e72d8d2Sderaadt extern void regfree _RE_ARGS ((regex_t *preg)); 5011e72d8d2Sderaadt 5021e72d8d2Sderaadt #endif /* not __REGEXP_LIBRARY_H__ */ 5031e72d8d2Sderaadt 5041e72d8d2Sderaadt /* 5051e72d8d2Sderaadt Local variables: 5061e72d8d2Sderaadt make-backup-files: t 5071e72d8d2Sderaadt version-control: t 5081e72d8d2Sderaadt trim-versions-without-asking: nil 5091e72d8d2Sderaadt End: 5101e72d8d2Sderaadt */ 511