2N/A/* Extended regular expression matching and search library. 2N/A Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free 2N/A Software Foundation, Inc. 2N/A Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. 2N/A This file is part of the GNU C Library. 2N/A Contributed by Isamu Hasegawa <isamu@yamato.ibm.com>. 2N/A This program is free software; you can redistribute it and/or modify 2N/A it under the terms of the GNU General Public License as published by 2N/A the Free Software Foundation; either version 3, or (at your option) 2N/A This program is distributed in the hope that it will be useful, 2N/A but WITHOUT ANY WARRANTY; without even the implied warranty of 2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2N/A GNU General Public License for more details. 2N/A You should have received a copy of the GNU General Public License along 2N/A with this program; if not, write to the Free Software Foundation, 2N/A Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
else /* not RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A/* This table gives an error message for each of the error codes listed 2N/A in regex.h. Obviously the order here has to be same as there. 2N/A POSIX doesn't require that we do anything for REG_NOERROR, 2N/A but why not be nice? */ 2N/A/* Entry points for GNU code. */ 2N/A/* re_compile_pattern is the GNU regular expression compiler: it 2N/A compiles PATTERN (of length LENGTH) and puts the result in BUFP. 2N/A Returns 0 if the pattern was valid, otherwise an error string. 2N/A Assumes the `allocated' (and perhaps `buffer') and `translate' fields 2N/A are set in BUFP on entry. */ 2N/A#
else /* size_t might promote */ 2N/A /* And GNU code determines whether or not to get register information 2N/A by passing null for the REGS argument to re_match, etc., not by 2N/A setting no_sub, unless RE_NO_SUB is set. */ 2N/A /* Match anchors at newline. */ 2N/A/* Set by `re_set_syntax' to the current regexp syntax to recognize. Can 2N/A also be assigned to arbitrarily: each pattern buffer stores its own 2N/A syntax, so it can be changed between regex compilations. */ 2N/A/* This has no initializer because initialized variables in Emacs 2N/A become read-only after dumping. */ 2N/A/* Specify the precise syntax of regexps for compilation. This provides 2N/A for compatibility for various utilities which historically have 2N/A different, incompatible syntaxes. 2N/A The argument SYNTAX is a bit mask comprised of the various bits 2N/A/* Helper function for re_compile_fastmap. 2N/A Compile fastmap for the initial_state INIT_STATE. */ 2N/A /* See if we have to try all bytes which start multiple collation 2N/A e.g. In da_DK, we want to catch 'a' since "aa" is a valid 2N/A collation element, and don't catch 'b' since 'b' is 2N/A the only collation element which starts from 'b' (and 2N/A it is caught by SIMPLE_BRACKET). */ 2N/A /* See if we have to start the match at all multibyte characters, 2N/A i.e. where we would not find an invalid sequence. This only 2N/A applies to multibyte character sets; for single byte character 2N/A sets, the SIMPLE_BRACKET again suffices. */ 2N/A unsigned char c = 0;
2N/A /* ... Else catch all bytes which can start the mbchars. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A/* Entry point for POSIX code. */ 2N/A/* regcomp takes a regular expression as a string and compiles it. 2N/A PREG is a regex_t *. We do not expect any fields to be initialized, 2N/A since POSIX says we shouldn't. Thus, we set 2N/A `buffer' to the compiled pattern; 2N/A `used' to the length of the compiled pattern; 2N/A `syntax' to RE_SYNTAX_POSIX_EXTENDED if the 2N/A REG_EXTENDED bit in CFLAGS is set; otherwise, to 2N/A RE_SYNTAX_POSIX_BASIC; 2N/A `newline_anchor' to REG_NEWLINE being set in CFLAGS; 2N/A `fastmap' to an allocated space for the fastmap; 2N/A `fastmap_accurate' to zero; 2N/A `re_nsub' to the number of subexpressions in PATTERN. 2N/A PATTERN is the address of the pattern string. 2N/A CFLAGS is a series of bits which affect compilation. 2N/A If REG_EXTENDED is set, we use POSIX extended syntax; otherwise, we 2N/A use POSIX basic syntax. 2N/A If REG_NEWLINE is set, then . and [^...] don't match newline. 2N/A Also, regexec will try a match beginning after every newline. 2N/A If REG_ICASE is set, then we considers upper- and lowercase 2N/A versions of letters to be equivalent when matching. 2N/A If REG_NOSUB is set, then when PREG is passed to regexec, that 2N/A routine will report only success or failure, and nothing about the 2N/A It returns 0 if it succeeds, nonzero if it doesn't. (See regex.h for 2N/A the return codes and their meanings.) */ 2N/A /* Try to allocate space for the fastmap. */ 2N/A /* If REG_NEWLINE is set, newlines are treated differently. */ 2N/A {
/* REG_NEWLINE implies neither . nor [^...] match newline. */ 2N/A /* It also changes the matching behavior. */ 2N/A /* POSIX doesn't distinguish between an unmatched open-group and an 2N/A unmatched close-group: both are REG_EPAREN. */ 2N/A /* We have already checked preg->fastmap != NULL. */ 2N/A /* Compute the fastmap now, since regexec cannot modify the pattern 2N/A buffer. This function never fails in this implementation. */ 2N/A /* Some error occurred while compiling the expression. */ 2N/A/* Returns a message corresponding to an error code, ERRCODE, returned 2N/A from either regcomp or regexec. We don't use PREG here. */ 2N/A#
else /* size_t might promote */ 2N/A /* Only error codes returned by the rest of the code should be passed 2N/A to this routine. If we are given anything else, or if other regex 2N/A code generates an invalid error code, then the program has a bug. 2N/A Dump core so we can fix it. */ 2N/A/* This static array is used for the map to single-byte characters when 2N/A UTF-8 is used. Otherwise we would allocate memory just to initialize 2N/A it the same all the time. UTF-8 is the preferred encoding so this is 2N/A a worthwhile optimization. */ 2N/A /* Set the first 128 bits. */ 2N/A#
error "bitset_word_t is narrower than 32 bits" 2N/A/* Free dynamically allocated space used by PREG. */ 2N/A/* Entry points compatible with 4.2 BSD regex library. We don't define 2N/A them unless specifically requested. */ 2N/A/* BSD has one and only one pattern buffer. */ 2N/A/* Make these definitions weak in libc, so POSIX programs can redefine 2N/A these names if they don't use our functions, and still use 2N/A return gettext (
"No previous regular expression");
2N/A /* Since `re_exec' always passes NULL for the `regs' argument, we 2N/A don't need to initialize the pattern buffer fields which affect it. */ 2N/A /* Match anchors at newlines. */ 2N/A /* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ 2N/A#
endif /* _REGEX_RE_COMP */ 2N/A/* Internal entry point. 2N/A Compile the regular expression PATTERN, whose length is LENGTH. 2N/A SYNTAX indicate regular expression's syntax. */ 2N/A /* Initialize the pattern buffer. */ 2N/A /* Initialize the dfa. */ 2N/A /* If zero allocated, but buffer is non-null, try to realloc 2N/A enough space. This loses if buffer's address is bogus, but 2N/A that is the user's responsibility. If ->buffer is NULL this 2N/A is a simple allocation. */ 2N/A /* Note: length+1 will not overflow since it is checked in init_dfa. */ 2N/A /* Parse the regular expression, and build a structure tree. */ 2N/A /* Analyze the tree and create the nfa. */ 2N/A /* If possible, do searching in single byte encoding to speed things up. */ 2N/A /* Then create the initial state of the dfa. */ 2N/A /* Release work areas. */ 2N/A/* Initialize DFA. We use the length of the regular expression PAT_LEN 2N/A as the initial length of some arrays. */ 2N/A /* Force allocation of str_tree_storage the first time. */ 2N/A /* Avoid overflows. The extra "/ 2" is for the table_size doubling 2N/A calculation below, and for similar doubling calculations 2N/A elsewhere. And it's <= rather than <, because some of the 2N/A doubling calculations add 1 afterwards. */ 2N/A /* table_size = 2 ^ ceil(log pat_len) */ 2N/A /* We check exhaustively in the loop below if this charset is a 2N/A superset of ASCII. */ 2N/A /* Set the bits corresponding to single byte chars. */ 2N/A/* Initialize WORD_CHAR table, which indicate which character is 2N/A "word". In this case "word" means that it is the word construction 2N/A character used by some operators like "\<", "\>", etc. */ 2N/A/* Free the work area which are only used while compiling. */ 2N/A/* Create initial states for all contexts. */ 2N/A /* Initial states have the epsilon closure of the node which is 2N/A the first node of the regular expression. */ 2N/A /* The back-references which are in initial states can epsilon transit, 2N/A since in this case all of the subexpressions can be null. 2N/A Then we add epsilon closures of the nodes which are the next nodes of 2N/A the back-references. */ 2N/A /* It must be the first time to invoke acquire_state. */ 2N/A /* We don't check ERR here, since the initial state must not be NULL. */ 2N/A/* If it is possible to do searching in single byte encoding instead of UTF-8 2N/A to speed things up, set dfa->mb_cur_max to 1, clear is_utf8 and change 2N/A DFA nodes where needed. */ 2N/A /* Word anchors etc. cannot be handled. It's okay to test 2N/A opr.ctx_type since constraints (for all DFA nodes) are 2N/A created by ORing one or more opr.ctx_type values. */ 2N/A /* Just double check. */ 2N/A /* The search can be in single byte locale. */ 2N/A/* Analyze the structure tree, and calculate "first", "next", "edest", 2N/A "eclosure", and "inveclosure". */ 2N/A /* Allocate arrays. */ 2N/A /* We only need this during the prune_impossible_nodes pass in regexec.c; 2N/A skip it if p_i_n will not run, as calc_inveclosure can be quadratic. */ 2N/A/* Our parse trees are very unbalanced, so we cannot use a stack to 2N/A implement parse tree visits. Instead, we use parent pointers and 2N/A some hairy code in these two functions. */ 2N/A /* Descend down the tree, preferably to the left (or to the right 2N/A if that's the only child). */ 2N/A /* Go up while we have a node that is reached from the right. */ 2N/A /* Go to the left node, or up and to the right. */ 2N/A/* Optimization pass: if a SUBEXP is entirely contained, strip it and tell 2N/A re_search_internal to map the inner one's opr.idx to this one's. Adjust 2N/A backreferences as well. Requires a preorder visit. */ 2N/A/* Lowering pass: Turn each SUBEXP node into the appropriate concatenation 2N/A of OP_OPEN_SUBEXP, the body of the SUBEXP (if any) and OP_CLOSE_SUBEXP. */ 2N/A /* We do not optimize empty subexpressions, because otherwise we may 2N/A have bad CONCAT nodes with NULL children. This is obviously not 2N/A very common, so we do not lose much. An example that triggers 2N/A this case is the sed "script" /\(\)/x. */ 2N/A /* Convert the SUBEXP node to the concatenation of an 2N/A OP_OPEN_SUBEXP, the contents, and an OP_CLOSE_SUBEXP. */ 2N/A/* Pass 1 in building the NFA: compute FIRST and create unlinked automaton 2N/A nodes. Requires a postorder visit. */ 2N/A/* Pass 2: compute NEXT on the tree. Preorder visit. */ 2N/A/* Pass 3: link all DFA nodes to their NEXT node (any order will do). */ 2N/A/* Duplicate the epsilon closure of the node ROOT_NODE. 2N/A Note that duplicated nodes have constraint INIT_CONSTRAINT in addition 2N/A to their own constraint. */ 2N/A /* If the back reference epsilon-transit, its destination must 2N/A also have the constraint. Then duplicate the epsilon closure 2N/A of the destination of the back reference, and store it in 2N/A edests of the back reference. */ 2N/A /* In case of the node can't epsilon-transit, don't duplicate the 2N/A destination and store the original destination as the 2N/A destination of the node. */ 2N/A /* In case of the node can epsilon-transit, and it has only one 2N/A /* If the node is root_node itself, it means the epsilon closure 2N/A has a loop. Then tie it to the destination of the root_node. */ 2N/A /* In case the node has another constraint, append it. */ 2N/A else /* dfa->edests[org_node].nelem == 2 */ 2N/A /* In case of the node can epsilon-transit, and it has two 2N/A destinations. In the bin_tree_t and DFA, that's '|' and '*'. */ 2N/A /* Search for a duplicated node which satisfies the constraint. */ 2N/A /* There is no such duplicated node, create a new one. */ 2N/A /* There is a duplicated node which satisfies the constraint, 2N/A use it to avoid infinite loop. */ 2N/A/* Search for a node which is duplicated from the node ORG_NODE, and 2N/A satisfies the constraint CONSTRAINT. */ 2N/A/* Duplicate the node whose index is ORG_IDX and set the constraint CONSTRAINT. 2N/A Return the index of the new node, or REG_MISSING if insufficient storage is 2N/A /* Store the index of the original node. */ 2N/A/* Calculate "eclosure" for all the node in DFA. */ 2N/A /* For each nodes, calculate epsilon closure. */ 2N/A /* If we have already calculated, skip it. */ 2N/A /* Calculate epsilon closure of `node_idx'. */ 2N/A/* Calculate epsilon closure of NODE. */ 2N/A /* This indicates that we are calculating this node now. 2N/A We reference this value to avoid infinite loop. */ 2N/A /* If the current node has constraints, duplicate all nodes 2N/A since they must inherit the constraints. */ 2N/A /* Expand each epsilon destination nodes. */ 2N/A /* If calculating the epsilon closure of `edest' is in progress, 2N/A return intermediate result. */ 2N/A /* If we haven't calculated the epsilon closure of `edest' yet, 2N/A calculate now. Otherwise use calculated epsilon closure. */ 2N/A /* Merge the epsilon closure of `edest'. */ 2N/A /* If the epsilon closure of `edest' is incomplete, 2N/A the epsilon closure of this node is also incomplete. */ 2N/A /* An epsilon closure includes itself. */ 2N/A/* Functions for token which are used in the parser. */ 2N/A/* Fetch a token from INPUT. 2N/A We must not use this function inside bracket expressions. */ 2N/A/* Peek a token from INPUT, and return the length of the token. 2N/A We must not use this function inside bracket expressions. */ 2N/A case '1':
case '2':
case '3':
case '4':
case '5':
2N/A case '6':
case '7':
case '8':
case '9':
2N/A/* Peek a token from INPUT, and return the length of the token. 2N/A We must not use this function out of bracket expressions. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A /* In this case, '\' escape a character. */ 2N/A if (c ==
'[')
/* '[' is a special char in a bracket exps. */ 2N/A /* else fall through. */ 2N/A/* Functions for parser. */ 2N/A/* Entry point of the parser. 2N/A Parse the regular expression REGEXP and return the structure tree. 2N/A If an error is occured, ERR is set by error code, and return NULL. 2N/A This function build the following tree, from regular expression <reg_exp>: 2N/A CAT means concatenation. 2N/A EOR means end of regular expression. */ 2N/A/* This function build the following tree, from regular expression 2N/A <branch1>|<branch2>: 2N/A ALT means alternative, which represents the operator `|'. */ 2N/A/* This function build the following tree, from regular expression 2N/A CAT means concatenation. */ 2N/A /* Otherwise expr == NULL, we don't need to create new tree. */ 2N/A/* This function build the following tree, from regular expression a*: 2N/A /* else fall through */ 2N/A /* else fall through */ 2N/A /* We treat it as a normal character. */ 2N/A /* Then we can these characters as normal characters. */ 2N/A /* mb_partial and word_char bits should be initialized already 2N/A /* We must return here, since ANCHORs can't be followed 2N/A by repetition operators. 2N/A eg. RE"^*" is invalid or "<ANCHOR(^)><CHAR(*)>", 2N/A it must not be "<ANCHOR(^)><REPEAT(*)>". */ 2N/A (
const unsigned char *)
"alnum",
2N/A (
const unsigned char *)
"_",
2N/A (
const unsigned char *)
"space",
2N/A (
const unsigned char *)
"",
2N/A /* Must not happen? */ 2N/A /* In BRE consecutive duplications are not allowed. */ 2N/A/* This function build the following tree, from regular expression 2N/A /* The subexpression may be a null string. */ 2N/A/* This function parse repetition operators like "*", "+", "{1,3}" etc. */ 2N/A start = 0;
/* We treat "{,m}" as "{0,m}". */ 2N/A /* We treat "{n}" as "{n,n}". */ 2N/A /* Invalid sequence. */ 2N/A /* If the syntax bit is set, rollback. */ 2N/A /* mb_partial and word_char bits should be already initialized by 2N/A /* First number greater than second. */ 2N/A /* Extract "<re>{n,m}" to "<re><re>...<re><re>{0,<m-n>}". */ 2N/A /* Duplicate ELEM before it is marked optional. */ 2N/A True if the arithmetic type T is signed. */ 2N/A /* This loop is actually executed only when end != REG_MISSING, 2N/A to rewrite <re>{0,n} as (<re>(<re>...<re>?)?)?... We have 2N/A already created the start+1-th copy. */ 2N/A I'm not sure, but maybe enough. */ 2N/A /* Local function for parse_bracket_exp only used in case of NOT _LIBC. 2N/A Build the range expression which starts from START_ELEM, and ends 2N/A at END_ELEM. The result are written to MBCSET and SBCSET. 2N/A RANGE_ALLOC is the allocated size of mbcset->range_starts, and 2N/A mbcset->range_ends, is a pointer argument sinse we may 2N/A#
else /* not RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A /* Equivalence Classes and Character Classes can't be a range start/end. */ 2N/A /* We can handle no multi character collating elements without libc 2N/A /* Got valid collation sequence values, add them as a new entry. 2N/A However, for !_LIBC we have no collation elements: if the 2N/A character set is single byte, the single byte character set 2N/A that we build below suffices. parse_bracket_exp passes 2N/A no MBCSET if dfa->mb_cur_max == 1. */ 2N/A /* Check the space of the arrays. */ 2N/A /* There is not enough space, need realloc. */ 2N/A /* +1 in case of mbcset->nranges is 0. */ 2N/A /* Use realloc since mbcset->range_starts and mbcset->range_ends 2N/A are NULL if *range_alloc == 0. */ 2N/A /* Build the table for single byte characters. */ 2N/A#
else /* not RE_ENABLE_I18N */ 2N/A /* Build the table for single byte characters. */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A#
endif /* not _LIBC */ 2N/A/* Helper function for parse_bracket_exp only used in case of NOT _LIBC.. 2N/A Build the collating element which is represented by NAME. 2N/A The result are written to MBCSET and SBCSET. 2N/A COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a 2N/A pointer argument since we may update it. */ 2N/A#
endif /* not _LIBC */ 2N/A/* This function parse bracket expression like "[abc]", "[a-c]", 2N/A /* Local function for parse_bracket_exp used in _LIBC environement. 2N/A Seek the collating symbol entry correspondings to NAME. 2N/A Return the index of the symbol in the SYMB_TABLE. */ 2N/A /* First compare the hashing value. */ 2N/A /* Compare the length of the name. */ 2N/A /* Compare the name. */ 2N/A /* Yep, this is the entry. */ 2N/A /* Local function for parse_bracket_exp used in _LIBC environment. 2N/A Look up the collation sequence value of BR_ELEM. 2N/A Return the value if succeeded, UINT_MAX otherwise. */ 2N/A auto inline unsigned int 2N/A if (MB_CUR_MAX == 1) 2N/A /* We found the entry. */ 2N/A /* Skip the name of collating element name. */ 2N/A /* Skip the byte sequence of the collating element. */ 2N/A /* Adjust for the alignment. */ 2N/A /* Skip the multibyte collation sequence value. */ 2N/A /* Skip the wide char sequence of the collating element. */ 2N/A idx +=
sizeof (
unsigned int) *
2N/A /* Return the collation sequence value. */ 2N/A /* No valid character. Match it as a single byte 2N/A /* Local function for parse_bracket_exp used in _LIBC environement. 2N/A Build the range expression which starts from START_ELEM, and ends 2N/A at END_ELEM. The result are written to MBCSET and SBCSET. 2N/A RANGE_ALLOC is the allocated size of mbcset->range_starts, and 2N/A mbcset->range_ends, is a pointer argument sinse we may 2N/A /* Equivalence Classes and Character Classes can't be a range 2N/A /* Got valid collation sequence values, add them as a new entry. 2N/A However, if we have no collation elements, and the character set 2N/A is single byte, the single byte character set that we 2N/A build below suffices. */ 2N/A /* Check the space of the arrays. */ 2N/A /* There is not enough space, need realloc. */ 2N/A /* +1 in case of mbcset->nranges is 0. */ 2N/A /* Build the table for single byte characters. */ 2N/A if (MB_CUR_MAX == 1) 2N/A /* Local function for parse_bracket_exp used in _LIBC environement. 2N/A Build the collating element which is represented by NAME. 2N/A The result are written to MBCSET and SBCSET. 2N/A COLL_SYM_ALLOC is the allocated size of mbcset->coll_sym, is a 2N/A pointer argument sinse we may update it. */ 2N/A /* We found the entry. */ 2N/A /* Skip the name of collating element name. */ 2N/A /* No valid character, treat it as a normal 2N/A /* Got valid collation sequence, add it as a new entry. */ 2N/A /* Check the space of the arrays. */ 2N/A /* Not enough, realloc it. */ 2N/A /* +1 in case of mbcset->ncoll_syms is 0. */ 2N/A /* Use realloc since mbcset->coll_syms is NULL 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A /* We treat the first ']' as a normal character. */ 2N/A /* Get information about the next token. We need it in any case. */ 2N/A /* Do not check for ranges if we know they are not allowed. */ 2N/A /* We treat the last '-' as a normal character. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A /* Check whether the array has enough space. */ 2N/A /* Not enough, realloc it. */ 2N/A /* +1 in case of mbcset->nmbchars is 0. */ 2N/A /* Use realloc since array is NULL if *alloc == 0. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A /* If it is non-matching list. */ 2N/A /* Ensure only single byte characters are set. */ 2N/A /* Build a tree for complex bracket. */ 2N/A /* If there are no bits set in sbcset, there is no point 2N/A of having both SIMPLE_BRACKET and COMPLEX_BRACKET. */ 2N/A /* Build a tree for simple bracket. */ 2N/A /* Then join them by ALT node. */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A /* Build a tree for simple bracket. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A/* Parse an element in the bracket expression. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A /* A '-' must only appear as anything but a range indicator before 2N/A the closing bracket. Everything else is an error. */ 2N/A /* The actual error value is not standardized since this whole 2N/A case is undefined. But ERANGE makes good sense. */ 2N/A/* Parse a bracket symbol in the bracket expression. Bracket symbols are 2N/A such as [:<character_class>:], [.<collating_element>.], and 2N/A [=<equivalent_class>=]. */ 2N/A /* Helper function for parse_bracket_exp. 2N/A Build the equivalence class which is represented by NAME. 2N/A The result are written to MBCSET and SBCSET. 2N/A EQUIV_CLASS_ALLOC is the allocated size of mbcset->equiv_classes, 2N/A is a pointer argument sinse we may update it. */ 2N/A#
else /* not RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A /* This #include defines a local function! */ 2N/A /* Calculate the index for equivalence class. */ 2N/A /* This isn't a valid character. */ 2N/A /* Build single byte matcing table for this equivalence class. */ 2N/A /* This isn't a valid character. */ 2N/A /* Compare only if the length matches and the collation rule 2N/A index is the same. */ 2N/A /* Check whether the array has enough space. */ 2N/A /* Not enough, realloc it. */ 2N/A /* +1 in case of mbcset->nequiv_classes is 0. */ 2N/A /* Use realloc since the array is NULL if *alloc == 0. */ 2N/A /* Helper function for parse_bracket_exp. 2N/A Build the character class which is represented by NAME. 2N/A The result are written to MBCSET and SBCSET. 2N/A CHAR_CLASS_ALLOC is the allocated size of mbcset->char_classes, 2N/A is a pointer argument sinse we may update it. */ 2N/A#
else /* not RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A /* In case of REG_ICASE "upper" and "lower" match the both of 2N/A upper and lower cases. */ 2N/A /* Check the space of the arrays. */ 2N/A /* Not enough, realloc it. */ 2N/A /* +1 in case of mbcset->nchar_classes is 0. */ 2N/A /* Use realloc since array is NULL if *alloc == 0. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
else /* not RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A /* We don't care the syntax in this case. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A /* \w match '_' also. */ 2N/A /* If it is non-matching list. */ 2N/A /* Ensure only single byte characters are set. */ 2N/A /* Build a tree for simple bracket. */ 2N/A /* Build a tree for complex bracket. */ 2N/A /* Then join them by ALT node. */ 2N/A#
else /* not RE_ENABLE_I18N */ 2N/A#
endif /* not RE_ENABLE_I18N */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A/* This is intended for the expressions like "a{1,3}". 2N/A Fetch a number from `input', and return the number. 2N/A Return REG_MISSING if the number field is empty like "{,1}". 2N/A Return REG_ERROR if an error occurred. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A/* Functions for binary tree operation. */ 2N/A/* Create a tree node. */ 2N/A/* Mark the tree SRC as an optional subexpression. 2N/A To be called from preorder or postorder. */ 2N/A/* Free the allocated memory inside NODE. */ 2N/A#
endif /* RE_ENABLE_I18N */ 2N/A/* Worker function for tree walking. Free the allocated memory inside NODE 2N/A and its children. */ 2N/A/* Duplicate the node SRC, and return new node. This is a preorder 2N/A visit similar to the one implemented by the generic visitor, but 2N/A we need more infrastructure to maintain two parallel trees --- so, 2N/A it's easier to duplicate. */ 2N/A /* Create a new tree and link it back to the current parent. */ 2N/A /* Go to the left node, or up and to the right. */