Mercurial > hg > octave-nkf > gnulib-hg
annotate lib/regex.h @ 6184:f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
old glibc regex code mishandles strings longer than 2**31 bytes.
This patch fixes this when the regex code is used in gnulib
(i.e., outside glibc).
* lib/regex.h (_REGEX_LARGE_OFFSETS): New feature-test macro,
governing whether the rest of this patch is active. By default,
the macro is disabled and the patch has no effect.
(regoff_t) [defined _REGEX_LARGE_OFFSETS]: Define to off_t, not int.
(__re_idx_t, __re_size_t, __re_long_size_t): New types.
(struct re_pattern_buffer, re_search, re_search_2, re_match):
(re_match_2, re_set_registers): Use the new types.
* lib/regex_internal.h (Idx, re_hashval_t): New types.
(REG_MISSING, REG_ERROR, REG_VALID_INDEX, REG_VALID_NONZERO_INDEX):
New macros.
(re_node_set, re_charset_t, re_token_t, re_string_realloc_buffers):
(re_string_context_at, bin_tree_t, re_dfastate_t):
(struct re_state_table_entry, state_array_t, re_sub_match_last_t):
(re_sub_match_top_t, re_match_context_t, re_sift_context_t):
(struct re_fail_stack_ent_t, struct re_fail_stack_t, struct re_dfa_t):
(re_string_char_size_at, re_string_wchar_at):
(re_string_elem_size_at):
Use the new types and macros to port to 64-bit hosts.
Use unsigned types for internal values, so that the code
mostly works even for arrays larger than SSIZE_MAX.
* lib/regcomp.c (re_compile_internal, init_dfa, duplicate_node):
(search_duplicated_node, calc_eclosure_iter, fetch_number):
(parse_reg_exp, parse_branch, parse_expression, parse_sub_exp):
(build_equiv_class, build_charclass, re_compile_fastmap_iter):
(free_dfa_content, create_initial_state, optimize_utf8, analyze):
(optimize_subexps, calc_first, link_nfa_nodes, duplicate_node_closure):
(calc_inveclosure, parse_dup_op, build_range_exp):
(build_collating_symbol, parse_bracket_exp, build_charclass_op):
(fetch_number, create_token_tree, mark_opt_subexp):
Likewise.
* lib/regex_internal.c
(re_string_construct_common, create_ci_newstate):
(create_cd_newstate, re_string_allocate, re_string_construct):
(re_string_realloc_buffers, build_wcs_upper_buffer):
(re_string_skip_chars, build_upper_buffer, re_string_translate_buffer):
(re_string_reconstruct, re_string_peek_byte_case):
(re_string_fetch_byte_case, re_string_context_at):
(re_node_set_alloc, re_node_set_init_1, re_node_set_init_2):
(re_node_set_init_copy, re_node_set_add_intersect):
(re_node_set_init_union, re_node_set_merge, re_node_set_insert):
(re_node_set_insert_last, re_node_set_compare, re_node_set_contains):
(re_node_set_remove_at, re_dfa_add_node, calc_state_hash):
(re_acquire_state, re_acquire_state_context, register_state):
Likewise.
* lib/regex.c
(match_ctx_init, match_ctx_add_entry, search_cur_bkref_entry):
(match_ctx_add_subtop, match_ctx_add_sublast, sift_ctx_init):
(re_search_internal, re_search_2_stub, re_search_stub)
(re_copy_regs, check_matching, check_halt_state_context, update_regs):
(push_fail_stack, sift_states_iter_mb, build_sifted_states):
(update_cur_sifted_state, check_dst_limits):
(check_dst_limits_calc_pos_1, check_dst_limits_calc_pos):
(check_subexp_limits, sift_states_bkref, merge_state_array):
(check_subexp_matching_top, get_subexp, get_subexp_sub):
(find_subexp_node, check_arrival, check_arrival_add_next_nodes):
(check_arrival_expand_ecl, check_arrival_expand_ecl_sub):
(expand_bkref_cache, check_node_accept_bytes):
(group_nodes_into_DFAstates, check_node_accept, regexec, re_match):
(re_search, re_match_2, re_search_2, prune_impossible_nodes):
(acquire_init_state_context, check_halt_node_context):
(proceed_next_node, pop_fail_stack, set_regs, free_fail_stack_return):
(sift_states_backward, clean_state_log_if_needed):
(sub_epsilon_src_nodes, add_epsilone_src_nodes, merge_state_with_log):
(find_recover_state, transit_state_sb, transit_state_mb):
(transit_state_bkref, build_trtable, match_ctx_clean):
Likewise.
* lib/regcomp.c (parse_dup_op): Add an extra test if Idx is unsigned,
to work around an assumption that REG_MISSING is negative.
* m4/regex.m4 (gl_REGEX): Require AC_SYS_LARGEFILE, Define
_REGEX_LARGE_OFFSETS). Test for regoff_t/off_t bug in 64-bit
and large-file glibc and in 32-bit large-file Solaris.
* config/srclist.txt: Add glibc bug 1281.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 31 Aug 2005 22:51:09 +0000 |
parents | 1e308ce32c4c |
children | d0a48e08c98d |
rev | line source |
---|---|
14 | 1 /* Definitions for data structures and routines for the regular |
4020 | 2 expression library. |
6076
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
3 Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005 |
4020 | 4 Free Software Foundation, Inc. |
5 This file is part of the GNU C Library. | |
1283 | 6 |
4020 | 7 This program is free software; you can redistribute it and/or modify |
8 it under the terms of the GNU General Public License as published by | |
9 the Free Software Foundation; either version 2, or (at your option) | |
10 any later version. | |
14 | 11 |
4020 | 12 This program is distributed in the hope that it will be useful, |
1283 | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
4020 | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | |
14 | 16 |
4020 | 17 You should have received a copy of the GNU General Public License along |
18 with this program; if not, write to the Free Software Foundation, | |
5968
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
14 | 20 |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
21 #ifndef _REGEX_H |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
22 #define _REGEX_H 1 |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
23 |
4304 | 24 #include <sys/types.h> |
25 | |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
26 /* Allow the use in C++ code. */ |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
27 #ifdef __cplusplus |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
28 extern "C" { |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
29 #endif |
14 | 30 |
6099 | 31 /* Define _REGEX_SOURCE to get definitions that are incompatible with |
32 POSIX. */ | |
33 #if (!defined _REGEX_SOURCE \ | |
34 && (defined _GNU_SOURCE \ | |
35 || (!defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE \ | |
36 && !defined _XOPEN_SOURCE))) | |
37 # define _REGEX_SOURCE 1 | |
38 #endif | |
389 | 39 |
6099 | 40 #if defined _REGEX_SOURCE && defined VMS |
389 | 41 /* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it |
42 should be there. */ | |
1283 | 43 # include <stddef.h> |
389 | 44 #endif |
45 | |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
46 #ifdef _REGEX_LARGE_OFFSETS |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
47 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
48 /* Use types and values that are wide enough to represent signed and |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
49 unsigned byte offsets in memory. This currently works only when |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
50 the regex code is used outside of the GNU C library; it is not yet |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
51 supported within glibc itself, and glibc users should not define |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
52 _REGEX_LARGE_OFFSETS. */ |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
53 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
54 /* The type of the offset of a byte within a string. |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
55 For historical reasons POSIX 1003.1-2004 requires that regoff_t be |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
56 at least as wide as off_t. This is a bit odd (and many common |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
57 POSIX platforms set it to the more-sensible ssize_t) but we might |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
58 as well conform. We don't know of any hosts where ssize_t is wider |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
59 than off_t, so off_t is safe. */ |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
60 typedef off_t regoff_t; |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
61 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
62 /* The type of nonnegative object indexes. Traditionally, GNU regex |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
63 uses 'int' for these. Code that uses __re_idx_t should work |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
64 regardless of whether the type is signed. */ |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
65 typedef size_t __re_idx_t; |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
66 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
67 /* The type of object sizes. */ |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
68 typedef size_t __re_size_t; |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
69 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
70 /* The type of object sizes, in places where the traditional code |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
71 uses unsigned long int. */ |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
72 typedef size_t __re_long_size_t; |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
73 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
74 #else |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
75 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
76 /* Use types that are binary-compatible with the traditional GNU regex |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
77 implementation, which mishandles strings longer than INT_MAX. */ |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
78 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
79 typedef int regoff_t; |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
80 typedef int __re_idx_t; |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
81 typedef unsigned int __re_size_t; |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
82 typedef unsigned long int __re_long_size_t; |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
83 |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
84 #endif |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
85 |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
86 /* The following two types have to be signed and unsigned integer type |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
87 wide enough to hold a value of a pointer. For most ANSI compilers |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
88 ptrdiff_t and size_t should be likely OK. Still size of these two |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
89 types is 2 for Microsoft C. Ugh... */ |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
90 typedef long int s_reg_t; |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
91 typedef unsigned long int active_reg_t; |
14 | 92 |
93 /* The following bits are used to determine the regexp syntax we | |
94 recognize. The set/not-set meanings are chosen so that Emacs syntax | |
95 remains the value 0. The bits are given in alphabetical order, and | |
96 the definitions shifted by one from the previous bit; thus, when we | |
97 add or remove a bit, only one other definition need change. */ | |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
98 typedef unsigned long int reg_syntax_t; |
14 | 99 |
100 /* If this bit is not set, then \ inside a bracket expression is literal. | |
101 If set, then such a \ quotes the following character. */ | |
6099 | 102 #define REG_BACKSLASH_ESCAPE_IN_LISTS 1ul |
14 | 103 |
104 /* If this bit is not set, then + and ? are operators, and \+ and \? are | |
649
89f4c1937ac7
update FSF address in copyright and remove any trailing blanks
Jim Meyering <jim@meyering.net>
parents:
502
diff
changeset
|
105 literals. |
14 | 106 If set, then \+ and \? are operators and + and ? are literals. */ |
6099 | 107 #define REG_BK_PLUS_QM (1ul << 1) |
14 | 108 |
109 /* If this bit is set, then character classes are supported. They are: | |
110 [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:], | |
111 [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:]. | |
112 If not set, then character classes are not supported. */ | |
6099 | 113 #define REG_CHAR_CLASSES (1ul << 2) |
14 | 114 |
115 /* If this bit is set, then ^ and $ are always anchors (outside bracket | |
116 expressions, of course). | |
117 If this bit is not set, then it depends: | |
118 ^ is an anchor if it is at the beginning of a regular | |
119 expression or after an open-group or an alternation operator; | |
120 $ is an anchor if it is at the end of a regular expression, or | |
649
89f4c1937ac7
update FSF address in copyright and remove any trailing blanks
Jim Meyering <jim@meyering.net>
parents:
502
diff
changeset
|
121 before a close-group or an alternation operator. |
14 | 122 |
6099 | 123 This bit could be (re)combined with REG_CONTEXT_INDEP_OPS, because |
14 | 124 POSIX draft 11.2 says that * etc. in leading positions is undefined. |
125 We already implemented a previous draft which made those constructs | |
126 invalid, though, so we haven't changed the code back. */ | |
6099 | 127 #define REG_CONTEXT_INDEP_ANCHORS (1ul << 3) |
14 | 128 |
129 /* If this bit is set, then special characters are always special | |
130 regardless of where they are in the pattern. | |
131 If this bit is not set, then special characters are special only in | |
649
89f4c1937ac7
update FSF address in copyright and remove any trailing blanks
Jim Meyering <jim@meyering.net>
parents:
502
diff
changeset
|
132 some contexts; otherwise they are ordinary. Specifically, |
14 | 133 * + ? and intervals are only special when not after the beginning, |
134 open-group, or alternation operator. */ | |
6099 | 135 #define REG_CONTEXT_INDEP_OPS (1ul << 4) |
14 | 136 |
137 /* If this bit is set, then *, +, ?, and { cannot be first in an re or | |
138 immediately after an alternation or begin-group operator. */ | |
6099 | 139 #define REG_CONTEXT_INVALID_OPS (1ul << 5) |
14 | 140 |
141 /* If this bit is set, then . matches newline. | |
142 If not set, then it doesn't. */ | |
6099 | 143 #define REG_DOT_NEWLINE (1ul << 6) |
14 | 144 |
145 /* If this bit is set, then . doesn't match NUL. | |
146 If not set, then it does. */ | |
6099 | 147 #define REG_DOT_NOT_NULL (1ul << 7) |
14 | 148 |
149 /* If this bit is set, nonmatching lists [^...] do not match newline. | |
150 If not set, they do. */ | |
6099 | 151 #define REG_HAT_LISTS_NOT_NEWLINE (1ul << 8) |
14 | 152 |
153 /* If this bit is set, either \{...\} or {...} defines an | |
6099 | 154 interval, depending on REG_NO_BK_BRACES. |
14 | 155 If not set, \{, \}, {, and } are literals. */ |
6099 | 156 #define REG_INTERVALS (1ul << 9) |
14 | 157 |
158 /* If this bit is set, +, ? and | aren't recognized as operators. | |
159 If not set, they are. */ | |
6099 | 160 #define REG_LIMITED_OPS (1ul << 10) |
14 | 161 |
162 /* If this bit is set, newline is an alternation operator. | |
163 If not set, newline is literal. */ | |
6099 | 164 #define REG_NEWLINE_ALT (1ul << 11) |
14 | 165 |
166 /* If this bit is set, then `{...}' defines an interval, and \{ and \} | |
167 are literals. | |
168 If not set, then `\{...\}' defines an interval. */ | |
6099 | 169 #define REG_NO_BK_BRACES (1ul << 12) |
14 | 170 |
171 /* If this bit is set, (...) defines a group, and \( and \) are literals. | |
172 If not set, \(...\) defines a group, and ( and ) are literals. */ | |
6099 | 173 #define REG_NO_BK_PARENS (1ul << 13) |
14 | 174 |
175 /* If this bit is set, then \<digit> matches <digit>. | |
176 If not set, then \<digit> is a back-reference. */ | |
6099 | 177 #define REG_NO_BK_REFS (1ul << 14) |
14 | 178 |
649
89f4c1937ac7
update FSF address in copyright and remove any trailing blanks
Jim Meyering <jim@meyering.net>
parents:
502
diff
changeset
|
179 /* If this bit is set, then | is an alternation operator, and \| is literal. |
14 | 180 If not set, then \| is an alternation operator, and | is literal. */ |
6099 | 181 #define REG_NO_BK_VBAR (1ul << 15) |
14 | 182 |
183 /* If this bit is set, then an ending range point collating higher | |
184 than the starting range point, as in [z-a], is invalid. | |
6085
d7b1b7dd9bf8
* config/srclist.txt: Add glibc bug 1232.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6076
diff
changeset
|
185 If not set, the containing range is empty and does not match any string. */ |
6099 | 186 #define REG_NO_EMPTY_RANGES (1ul << 16) |
14 | 187 |
188 /* If this bit is set, then an unmatched ) is ordinary. | |
189 If not set, then an unmatched ) is invalid. */ | |
6099 | 190 #define REG_UNMATCHED_RIGHT_PAREN_ORD (1ul << 17) |
14 | 191 |
389 | 192 /* If this bit is set, succeed as soon as we match the whole pattern, |
193 without further backtracking. */ | |
6099 | 194 #define REG_NO_POSIX_BACKTRACKING (1ul << 18) |
389 | 195 |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
196 /* If this bit is set, do not process the GNU regex operators. |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
197 If not set, then the GNU regex operators are recognized. */ |
6099 | 198 #define REG_NO_GNU_OPS (1ul << 19) |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
199 |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
200 /* If this bit is set, turn on internal regex debugging. |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
201 If not set, and debugging was on, turn it off. |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
202 This only works if regex.c is compiled -DDEBUG. |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
203 We define this bit always, so that all that's needed to turn on |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
204 debugging is to recompile regex.c; the calling code can always have |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
205 this bit set, and it won't affect anything in the normal case. */ |
6099 | 206 #define REG_DEBUG (1ul << 20) |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
207 |
3227 | 208 /* If this bit is set, a syntactically invalid interval is treated as |
209 a string of ordinary characters. For example, the ERE 'a{1' is | |
210 treated as 'a\{1'. */ | |
6099 | 211 #define REG_INVALID_INTERVAL_ORD (1ul << 21) |
3227 | 212 |
4020 | 213 /* If this bit is set, then ignore case when matching. |
214 If not set, then case is significant. */ | |
6099 | 215 #define REG_IGNORE_CASE (1ul << 22) |
4020 | 216 |
6099 | 217 /* This bit is used internally like REG_CONTEXT_INDEP_ANCHORS but only |
5968
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
218 for ^, because it is difficult to scan the regex backwards to find |
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
219 whether ^ should be special. */ |
6099 | 220 #define REG_CARET_ANCHORS_HERE (1ul << 23) |
5968
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
221 |
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
222 /* If this bit is set, then \{ cannot be first in an bre or |
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
223 immediately after an alternation or begin-group operator. */ |
6099 | 224 #define REG_CONTEXT_INVALID_DUP (1ul << 24) |
5968
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
225 |
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
226 /* If this bit is set, then no_sub will be set to 1 during |
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
227 re_compile_pattern. */ |
6099 | 228 #define REG_NO_SUB (1ul << 25) |
5968
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
229 |
14 | 230 /* This global variable defines the particular regexp syntax to use (for |
231 some interfaces). When a regexp is compiled, the syntax used is | |
232 stored in the pattern buffer, so changing this does not affect | |
233 already-compiled regexps. */ | |
234 extern reg_syntax_t re_syntax_options; | |
235 | |
236 /* Define combinations of the above bits for the standard possibilities. | |
237 (The [[[ comments delimit what gets put into the Texinfo file, so | |
649
89f4c1937ac7
update FSF address in copyright and remove any trailing blanks
Jim Meyering <jim@meyering.net>
parents:
502
diff
changeset
|
238 don't delete them!) */ |
14 | 239 /* [[[begin syntaxes]]] */ |
6099 | 240 #define REG_SYNTAX_EMACS 0 |
14 | 241 |
6099 | 242 #define REG_SYNTAX_AWK \ |
243 (REG_BACKSLASH_ESCAPE_IN_LISTS | REG_DOT_NOT_NULL \ | |
244 | REG_NO_BK_PARENS | REG_NO_BK_REFS \ | |
245 | REG_NO_BK_VBAR | REG_NO_EMPTY_RANGES \ | |
246 | REG_DOT_NEWLINE | REG_CONTEXT_INDEP_ANCHORS \ | |
247 | REG_UNMATCHED_RIGHT_PAREN_ORD | REG_NO_GNU_OPS) | |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
248 |
6099 | 249 #define REG_SYNTAX_GNU_AWK \ |
250 ((REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \ | |
251 | REG_DEBUG) \ | |
252 & ~(REG_DOT_NOT_NULL | REG_INTERVALS | REG_CONTEXT_INDEP_OPS \ | |
253 | REG_CONTEXT_INVALID_OPS )) | |
14 | 254 |
6099 | 255 #define REG_SYNTAX_POSIX_AWK \ |
256 (REG_SYNTAX_POSIX_EXTENDED | REG_BACKSLASH_ESCAPE_IN_LISTS \ | |
257 | REG_INTERVALS | REG_NO_GNU_OPS) | |
14 | 258 |
6099 | 259 #define REG_SYNTAX_GREP \ |
260 (REG_BK_PLUS_QM | REG_CHAR_CLASSES \ | |
261 | REG_HAT_LISTS_NOT_NEWLINE | REG_INTERVALS \ | |
262 | REG_NEWLINE_ALT) | |
14 | 263 |
6099 | 264 #define REG_SYNTAX_EGREP \ |
265 (REG_CHAR_CLASSES | REG_CONTEXT_INDEP_ANCHORS \ | |
266 | REG_CONTEXT_INDEP_OPS | REG_HAT_LISTS_NOT_NEWLINE \ | |
267 | REG_NEWLINE_ALT | REG_NO_BK_PARENS \ | |
268 | REG_NO_BK_VBAR) | |
14 | 269 |
6099 | 270 #define REG_SYNTAX_POSIX_EGREP \ |
271 (REG_SYNTAX_EGREP | REG_INTERVALS | REG_NO_BK_BRACES \ | |
272 | REG_INVALID_INTERVAL_ORD) | |
14 | 273 |
389 | 274 /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */ |
6099 | 275 #define REG_SYNTAX_ED REG_SYNTAX_POSIX_BASIC |
389 | 276 |
6099 | 277 #define REG_SYNTAX_SED REG_SYNTAX_POSIX_BASIC |
14 | 278 |
279 /* Syntax bits common to both basic and extended POSIX regex syntax. */ | |
6099 | 280 #define _REG_SYNTAX_POSIX_COMMON \ |
281 (REG_CHAR_CLASSES | REG_DOT_NEWLINE | REG_DOT_NOT_NULL \ | |
282 | REG_INTERVALS | REG_NO_EMPTY_RANGES) | |
14 | 283 |
6099 | 284 #define REG_SYNTAX_POSIX_BASIC \ |
285 (_REG_SYNTAX_POSIX_COMMON | REG_BK_PLUS_QM | REG_CONTEXT_INVALID_DUP) | |
14 | 286 |
6099 | 287 /* Differs from ..._POSIX_BASIC only in that REG_BK_PLUS_QM becomes |
288 REG_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this | |
14 | 289 isn't minimal, since other operators, such as \`, aren't disabled. */ |
6099 | 290 #define REG_SYNTAX_POSIX_MINIMAL_BASIC \ |
291 (_REG_SYNTAX_POSIX_COMMON | REG_LIMITED_OPS) | |
14 | 292 |
6099 | 293 #define REG_SYNTAX_POSIX_EXTENDED \ |
294 (_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \ | |
295 | REG_CONTEXT_INDEP_OPS | REG_NO_BK_BRACES \ | |
296 | REG_NO_BK_PARENS | REG_NO_BK_VBAR \ | |
297 | REG_CONTEXT_INVALID_OPS | REG_UNMATCHED_RIGHT_PAREN_ORD) | |
14 | 298 |
6099 | 299 /* Differs from ..._POSIX_EXTENDED in that REG_CONTEXT_INDEP_OPS is |
300 removed and REG_NO_BK_REFS is added. */ | |
301 #define REG_SYNTAX_POSIX_MINIMAL_EXTENDED \ | |
302 (_REG_SYNTAX_POSIX_COMMON | REG_CONTEXT_INDEP_ANCHORS \ | |
303 | REG_CONTEXT_INVALID_OPS | REG_NO_BK_BRACES \ | |
304 | REG_NO_BK_PARENS | REG_NO_BK_REFS \ | |
305 | REG_NO_BK_VBAR | REG_UNMATCHED_RIGHT_PAREN_ORD) | |
14 | 306 /* [[[end syntaxes]]] */ |
307 | |
6099 | 308 /* Maximum number of duplicates an interval can allow. This is |
309 distinct from RE_DUP_MAX, to conform to POSIX name space rules and | |
310 to avoid collisions with <limits.h>. */ | |
311 #define REG_DUP_MAX 32767 | |
14 | 312 |
313 | |
314 /* POSIX `cflags' bits (i.e., information for `regcomp'). */ | |
315 | |
316 /* If this bit is set, then use extended regular expression syntax. | |
317 If not set, then use basic regular expression syntax. */ | |
318 #define REG_EXTENDED 1 | |
319 | |
320 /* If this bit is set, then ignore case when matching. | |
321 If not set, then case is significant. */ | |
6099 | 322 #define REG_ICASE (1 << 1) |
649
89f4c1937ac7
update FSF address in copyright and remove any trailing blanks
Jim Meyering <jim@meyering.net>
parents:
502
diff
changeset
|
323 |
14 | 324 /* If this bit is set, then anchors do not match at newline |
325 characters in the string. | |
326 If not set, then anchors do match at newlines. */ | |
6099 | 327 #define REG_NEWLINE (1 << 2) |
14 | 328 |
329 /* If this bit is set, then report only success or fail in regexec. | |
330 If not set, then returns differ between not matching and errors. */ | |
6099 | 331 #define REG_NOSUB (1 << 3) |
14 | 332 |
333 | |
334 /* POSIX `eflags' bits (i.e., information for regexec). */ | |
335 | |
336 /* If this bit is set, then the beginning-of-line operator doesn't match | |
337 the beginning of the string (presumably because it's not the | |
338 beginning of a line). | |
339 If not set, then the beginning-of-line operator does match the | |
340 beginning of the string. */ | |
341 #define REG_NOTBOL 1 | |
342 | |
343 /* Like REG_NOTBOL, except for the end-of-line. */ | |
344 #define REG_NOTEOL (1 << 1) | |
345 | |
5968
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
346 /* Use PMATCH[0] to delimit the start and end of the search in the |
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
347 buffer. */ |
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
348 #define REG_STARTEND (1 << 2) |
541fed6ae301
* modules/regex (Files): Add lib/regex_internal.c,
Paul Eggert <eggert@cs.ucla.edu>
parents:
5851
diff
changeset
|
349 |
14 | 350 |
351 /* If any error codes are removed, changed, or added, update the | |
6099 | 352 `__re_error_msgid' table in regcomp.c. */ |
353 | |
14 | 354 typedef enum |
355 { | |
6099 | 356 _REG_ENOSYS = -1, /* This will never happen for this implementation. */ |
357 #define REG_ENOSYS _REG_ENOSYS | |
1283 | 358 |
6099 | 359 _REG_NOERROR, /* Success. */ |
360 #define REG_NOERROR _REG_NOERROR | |
361 | |
362 _REG_NOMATCH, /* Didn't find a match (for regexec). */ | |
363 #define REG_NOMATCH _REG_NOMATCH | |
14 | 364 |
365 /* POSIX regcomp return error codes. (In the order listed in the | |
366 standard.) */ | |
6099 | 367 |
368 _REG_BADPAT, /* Invalid pattern. */ | |
369 #define REG_BADPAT _REG_BADPAT | |
370 | |
371 _REG_ECOLLATE, /* Inalid collating element. */ | |
372 #define REG_ECOLLATE _REG_ECOLLATE | |
373 | |
374 _REG_ECTYPE, /* Invalid character class name. */ | |
375 #define REG_ECTYPE _REG_ECTYPE | |
376 | |
377 _REG_EESCAPE, /* Trailing backslash. */ | |
378 #define REG_EESCAPE _REG_EESCAPE | |
379 | |
380 _REG_ESUBREG, /* Invalid back reference. */ | |
381 #define REG_ESUBREG _REG_ESUBREG | |
382 | |
383 _REG_EBRACK, /* Unmatched left bracket. */ | |
384 #define REG_EBRACK _REG_EBRACK | |
385 | |
386 _REG_EPAREN, /* Parenthesis imbalance. */ | |
387 #define REG_EPAREN _REG_EPAREN | |
388 | |
389 _REG_EBRACE, /* Unmatched \{. */ | |
390 #define REG_EBRACE _REG_EBRACE | |
391 | |
392 _REG_BADBR, /* Invalid contents of \{\}. */ | |
393 #define REG_BADBR _REG_BADBR | |
394 | |
395 _REG_ERANGE, /* Invalid range end. */ | |
396 #define REG_ERANGE _REG_ERANGE | |
397 | |
398 _REG_ESPACE, /* Ran out of memory. */ | |
399 #define REG_ESPACE _REG_ESPACE | |
400 | |
401 _REG_BADRPT, /* No preceding re for repetition op. */ | |
402 #define REG_BADRPT _REG_BADRPT | |
14 | 403 |
404 /* Error codes we've added. */ | |
6099 | 405 |
406 _REG_EEND, /* Premature end. */ | |
407 #define REG_EEND _REG_EEND | |
408 | |
409 _REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */ | |
410 #define REG_ESIZE _REG_ESIZE | |
411 | |
412 _REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */ | |
413 #define REG_ERPAREN _REG_ERPAREN | |
414 | |
14 | 415 } reg_errcode_t; |
416 | |
6099 | 417 /* In the traditional GNU implementation, regex.h defined member names |
418 like `buffer' that POSIX does not allow. These members now have | |
419 names with leading `re_' (e.g., `re_buffer'). Support the old | |
420 names only if _REGEX_SOURCE is defined. New programs should use | |
421 the new names. */ | |
422 #ifdef _REGEX_SOURCE | |
423 # define _REG_RE_NAME(id) id | |
424 # define _REG_RM_NAME(id) id | |
425 #else | |
426 # define _REG_RE_NAME(id) re_##id | |
427 # define _REG_RM_NAME(id) rm_##id | |
428 #endif | |
429 | |
430 /* The user can specify the type of the re_translate member by | |
431 defining the macro REG_TRANSLATE_TYPE. In the traditional GNU | |
432 implementation, this macro was named RE_TRANSLATE_TYPE, but POSIX | |
433 does not allow this. Support the old name only if _REGEX_SOURCE | |
434 and if the new name is not defined. New programs should use the new | |
435 name. */ | |
436 #ifndef REG_TRANSLATE_TYPE | |
437 # if defined _REGEX_SOURCE && defined RE_TRANSLATE_TYPE | |
438 # define REG_TRANSLATE_TYPE RE_TRANSLATE_TYPE | |
439 # else | |
440 # define REG_TRANSLATE_TYPE char * | |
441 # endif | |
442 #endif | |
443 | |
14 | 444 /* This data structure represents a compiled pattern. Before calling |
6099 | 445 the pattern compiler), the fields `re_buffer', `re_allocated', `re_fastmap', |
446 `re_translate', and `re_no_sub' can be set. After the pattern has been | |
14 | 447 compiled, the `re_nsub' field is available. All other fields are |
448 private to the regex routines. */ | |
449 | |
450 struct re_pattern_buffer | |
451 { | |
452 /* [[[begin pattern_buffer]]] */ | |
453 /* Space that holds the compiled pattern. It is declared as | |
454 `unsigned char *' because its elements are | |
455 sometimes used as array indexes. */ | |
6099 | 456 unsigned char *_REG_RE_NAME (buffer); |
14 | 457 |
6099 | 458 /* Number of bytes to which `re_buffer' points. */ |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
459 __re_long_size_t _REG_RE_NAME (allocated); |
14 | 460 |
6099 | 461 /* Number of bytes actually used in `re_buffer'. */ |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
462 __re_long_size_t _REG_RE_NAME (used); |
14 | 463 |
464 /* Syntax setting with which the pattern was compiled. */ | |
6099 | 465 reg_syntax_t _REG_RE_NAME (syntax); |
14 | 466 |
467 /* Pointer to a fastmap, if any, otherwise zero. re_search uses | |
468 the fastmap, if there is one, to skip over impossible | |
469 starting points for matches. */ | |
6099 | 470 char *_REG_RE_NAME (fastmap); |
14 | 471 |
472 /* Either a translate table to apply to all characters before | |
473 comparing them, or zero for no translation. The translation | |
474 is applied to a pattern when it is compiled and to a string | |
475 when it is matched. */ | |
6099 | 476 REG_TRANSLATE_TYPE _REG_RE_NAME (translate); |
14 | 477 |
478 /* Number of subexpressions found by the compiler. */ | |
479 size_t re_nsub; | |
480 | |
481 /* Zero if this pattern cannot match the empty string, one else. | |
482 Well, in truth it's used only in `re_search_2', to see | |
483 whether or not we should use the fastmap, so we don't set | |
484 this absolutely perfectly; see `re_compile_fastmap' (the | |
485 `duplicate' case). */ | |
6099 | 486 unsigned int _REG_RE_NAME (can_be_null) : 1; |
14 | 487 |
6099 | 488 /* If REG_UNALLOCATED, allocate space in the `regs' structure |
489 for `max (REG_NREGS, re_nsub + 1)' groups. | |
490 If REG_REALLOCATE, reallocate space if necessary. | |
491 If REG_FIXED, use what's there. */ | |
492 #define REG_UNALLOCATED 0 | |
493 #define REG_REALLOCATE 1 | |
494 #define REG_FIXED 2 | |
495 unsigned int _REG_RE_NAME (regs_allocated) : 2; | |
14 | 496 |
389 | 497 /* Set to zero when `regex_compile' compiles a pattern; set to one |
498 by `re_compile_fastmap' if it updates the fastmap. */ | |
6099 | 499 unsigned int _REG_RE_NAME (fastmap_accurate) : 1; |
14 | 500 |
389 | 501 /* If set, `re_match_2' does not return information about |
502 subexpressions. */ | |
6099 | 503 unsigned int _REG_RE_NAME (no_sub) : 1; |
14 | 504 |
505 /* If set, a beginning-of-line anchor doesn't match at the | |
649
89f4c1937ac7
update FSF address in copyright and remove any trailing blanks
Jim Meyering <jim@meyering.net>
parents:
502
diff
changeset
|
506 beginning of the string. */ |
6099 | 507 unsigned int _REG_RE_NAME (not_bol) : 1; |
14 | 508 |
509 /* Similarly for an end-of-line anchor. */ | |
6099 | 510 unsigned int _REG_RE_NAME (not_eol) : 1; |
14 | 511 |
512 /* If true, an anchor at a newline matches. */ | |
6099 | 513 unsigned int _REG_RE_NAME (newline_anchor) : 1; |
14 | 514 |
515 /* [[[end pattern_buffer]]] */ | |
516 }; | |
517 | |
518 typedef struct re_pattern_buffer regex_t; | |
519 | |
520 /* This is the structure we store register match data in. See | |
521 regex.texinfo for a full description of what registers match. */ | |
522 struct re_registers | |
523 { | |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
524 __re_size_t _REG_RM_NAME (num_regs); |
6099 | 525 regoff_t *_REG_RM_NAME (start); |
526 regoff_t *_REG_RM_NAME (end); | |
14 | 527 }; |
528 | |
529 | |
6099 | 530 /* If `regs_allocated' is REG_UNALLOCATED in the pattern buffer, |
14 | 531 `re_match_2' returns information about at least this many registers |
532 the first time a `regs' structure is passed. */ | |
6099 | 533 #ifndef REG_NREGS |
534 # define REG_NREGS 30 | |
14 | 535 #endif |
536 | |
537 | |
538 /* POSIX specification for registers. Aside from the different names than | |
539 `re_registers', POSIX uses an array of structures, instead of a | |
540 structure of arrays. */ | |
541 typedef struct | |
542 { | |
543 regoff_t rm_so; /* Byte offset from string's start to substring's start. */ | |
544 regoff_t rm_eo; /* Byte offset from string's start to substring's end. */ | |
545 } regmatch_t; | |
546 | |
547 /* Declarations for routines. */ | |
548 | |
549 /* Sets the current default syntax to SYNTAX, and return the old syntax. | |
550 You can also simply assign to the `re_syntax_options' variable. */ | |
6099 | 551 extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); |
14 | 552 |
553 /* Compile the regular expression PATTERN, with length LENGTH | |
554 and syntax given by the global `re_syntax_options', into the buffer | |
555 BUFFER. Return NULL if successful, and an error string if not. */ | |
6099 | 556 extern const char *re_compile_pattern (const char *__pattern, size_t __length, |
557 struct re_pattern_buffer *__buffer); | |
14 | 558 |
559 | |
560 /* Compile a fastmap for the compiled pattern in BUFFER; used to | |
561 accelerate searches. Return 0 if successful and -2 if was an | |
562 internal error. */ | |
6099 | 563 extern int re_compile_fastmap (struct re_pattern_buffer *__buffer); |
14 | 564 |
565 | |
566 /* Search in the string STRING (with length LENGTH) for the pattern | |
567 compiled into BUFFER. Start searching at position START, for RANGE | |
568 characters. Return the starting position of the match, -1 for no | |
569 match, or -2 for an internal error. Also return register | |
6099 | 570 information in REGS (if REGS and BUFFER->re_no_sub are nonzero). */ |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
571 extern regoff_t re_search (struct re_pattern_buffer *__buffer, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
572 const char *__string, __re_idx_t __length, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
573 __re_idx_t __start, regoff_t __range, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
574 struct re_registers *__regs); |
14 | 575 |
576 | |
577 /* Like `re_search', but search in the concatenation of STRING1 and | |
578 STRING2. Also, stop searching at index START + STOP. */ | |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
579 extern regoff_t re_search_2 (struct re_pattern_buffer *__buffer, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
580 const char *__string1, __re_idx_t __length1, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
581 const char *__string2, __re_idx_t __length2, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
582 __re_idx_t __start, regoff_t __range, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
583 struct re_registers *__regs, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
584 __re_idx_t __stop); |
14 | 585 |
586 | |
587 /* Like `re_search', but return how many characters in STRING the regexp | |
588 in BUFFER matched, starting at position START. */ | |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
589 extern regoff_t re_match (struct re_pattern_buffer *__buffer, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
590 const char *__string, __re_idx_t __length, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
591 __re_idx_t __start, struct re_registers *__regs); |
14 | 592 |
593 | |
594 /* Relates to `re_match' as `re_search_2' relates to `re_search'. */ | |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
595 extern regoff_t re_match_2 (struct re_pattern_buffer *__buffer, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
596 const char *__string1, __re_idx_t __length1, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
597 const char *__string2, __re_idx_t __length2, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
598 __re_idx_t __start, struct re_registers *__regs, |
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
599 __re_idx_t __stop); |
14 | 600 |
601 | |
602 /* Set REGS to hold NUM_REGS registers, storing them in STARTS and | |
603 ENDS. Subsequent matches using BUFFER and REGS will use this memory | |
604 for recording register information. STARTS and ENDS must be | |
605 allocated with malloc, and must each be at least `NUM_REGS * sizeof | |
606 (regoff_t)' bytes long. | |
607 | |
608 If NUM_REGS == 0, then subsequent matches should allocate their own | |
609 register data. | |
610 | |
611 Unless this function is called, the first search or match using | |
612 PATTERN_BUFFER will allocate its own register data, without | |
613 freeing the old data. */ | |
6099 | 614 extern void re_set_registers (struct re_pattern_buffer *__buffer, |
615 struct re_registers *__regs, | |
6184
f1728546eca4
On 64-bit hosts (where size_t is 64 bits and int is 32 bits), the
Paul Eggert <eggert@cs.ucla.edu>
parents:
6104
diff
changeset
|
616 __re_size_t __num_regs, |
6099 | 617 regoff_t *__starts, regoff_t *__ends); |
14 | 618 |
1639 | 619 #if defined _REGEX_RE_COMP || defined _LIBC |
1283 | 620 # ifndef _CRAY |
14 | 621 /* 4.2 bsd compatibility. */ |
6076
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
622 extern char *re_comp (const char *); |
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
623 extern int re_exec (const char *); |
1283 | 624 # endif |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
625 #endif |
14 | 626 |
2927 | 627 /* GCC 2.95 and later have "__restrict"; C99 compilers have |
628 "restrict", and "configure" may have defined "restrict". */ | |
629 #ifndef __restrict | |
630 # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__)) | |
631 # if defined restrict || 199901L <= __STDC_VERSION__ | |
632 # define __restrict restrict | |
633 # else | |
634 # define __restrict | |
635 # endif | |
636 # endif | |
2940
c7143052abca
(__restrict_arr): Move definition out of #ifndef block.
Jim Meyering <jim@meyering.net>
parents:
2927
diff
changeset
|
637 #endif |
6041
05710fe33bb1
* config/srclist.txt: Comment out $LIBCSRC/posix/regex.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5968
diff
changeset
|
638 /* gcc 3.1 and up support the [restrict] syntax, but g++ doesn't. */ |
3684
c8ed84e015e6
(__restrict_arr): Update from libc.
Jim Meyering <jim@meyering.net>
parents:
3336
diff
changeset
|
639 #ifndef __restrict_arr |
6041
05710fe33bb1
* config/srclist.txt: Comment out $LIBCSRC/posix/regex.h.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5968
diff
changeset
|
640 # if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) && !defined __cplusplus |
3684
c8ed84e015e6
(__restrict_arr): Update from libc.
Jim Meyering <jim@meyering.net>
parents:
3336
diff
changeset
|
641 # define __restrict_arr __restrict |
c8ed84e015e6
(__restrict_arr): Update from libc.
Jim Meyering <jim@meyering.net>
parents:
3336
diff
changeset
|
642 # else |
c8ed84e015e6
(__restrict_arr): Update from libc.
Jim Meyering <jim@meyering.net>
parents:
3336
diff
changeset
|
643 # define __restrict_arr |
c8ed84e015e6
(__restrict_arr): Update from libc.
Jim Meyering <jim@meyering.net>
parents:
3336
diff
changeset
|
644 # endif |
c8ed84e015e6
(__restrict_arr): Update from libc.
Jim Meyering <jim@meyering.net>
parents:
3336
diff
changeset
|
645 #endif |
2927 | 646 |
14 | 647 /* POSIX compatibility. */ |
6076
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
648 extern int regcomp (regex_t *__restrict __preg, |
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
649 const char *__restrict __pattern, |
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
650 int __cflags); |
1466 | 651 |
6076
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
652 extern int regexec (const regex_t *__restrict __preg, |
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
653 const char *__restrict __string, size_t __nmatch, |
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
654 regmatch_t __pmatch[__restrict_arr], |
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
655 int __eflags); |
1466 | 656 |
6104
1e308ce32c4c
* config/srclist.txt: Add glibc bug 1240.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6100
diff
changeset
|
657 extern size_t regerror (int __errcode, const regex_t *__restrict __preg, |
1e308ce32c4c
* config/srclist.txt: Add glibc bug 1240.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6100
diff
changeset
|
658 char *__restrict __errbuf, size_t __errbuf_size); |
1466 | 659 |
6076
e2dd51f6e259
* config/srclist.txt: Add glibc bugs 1220, 1221, 1222.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6059
diff
changeset
|
660 extern void regfree (regex_t *__preg); |
14 | 661 |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
662 |
6099 | 663 #ifdef _REGEX_SOURCE |
664 | |
665 /* Define the POSIX-compatible member names in terms of the | |
666 incompatible (and deprecated) names established by _REG_RE_NAME. | |
667 New programs should use the re_* names. */ | |
668 | |
669 # define re_allocated allocated | |
670 # define re_buffer buffer | |
671 # define re_can_be_null can_be_null | |
672 # define re_fastmap fastmap | |
6100
b4fe67182e68
[_REGEX_SOURCE]: Define re_fastmap_accurate too; this was
Paul Eggert <eggert@cs.ucla.edu>
parents:
6099
diff
changeset
|
673 # define re_fastmap_accurate fastmap_accurate |
6099 | 674 # define re_newline_anchor newline_anchor |
675 # define re_no_sub no_sub | |
676 # define re_not_bol not_bol | |
677 # define re_not_eol not_eol | |
678 # define re_regs_allocated regs_allocated | |
679 # define re_syntax syntax | |
680 # define re_translate translate | |
681 # define re_used used | |
682 | |
683 /* Similarly for _REG_RM_NAME. */ | |
684 | |
685 # define rm_end end | |
686 # define rm_num_regs num_regs | |
687 # define rm_start start | |
688 | |
689 /* Undef RE_DUP_MAX first, in case the user has already included a | |
690 <limits.h> with an incompatible definition. | |
691 | |
692 On GNU systems, the most common spelling for RE_DUP_MAX's value in | |
693 <limits.h> is (0x7ffff), so define RE_DUP_MAX to that, not to | |
694 REG_DUP_MAX. This avoid some duplicate-macro-definition warnings | |
695 with programs that include <limits.h> after this file. | |
696 | |
697 New programs should not assume that regex.h defines RE_DUP_MAX; to | |
698 get the value of RE_DUP_MAX, they should instead include <limits.h> | |
699 and possibly invoke the sysconf function. */ | |
700 | |
701 # undef RE_DUP_MAX | |
702 # define RE_DUP_MAX (0x7fff) | |
703 | |
704 /* Define the following symbols for backward source compatibility. | |
705 These symbols violate the POSIX name space rules, and new programs | |
706 should avoid them. */ | |
707 | |
708 # define REGS_FIXED REG_FIXED | |
709 # define REGS_REALLOCATE REG_REALLOCATE | |
710 # define REGS_UNALLOCATED REG_UNALLOCATED | |
711 # define RE_BACKSLASH_ESCAPE_IN_LISTS REG_BACKSLASH_ESCAPE_IN_LISTS | |
712 # define RE_BK_PLUS_QM REG_BK_PLUS_QM | |
713 # define RE_CARET_ANCHORS_HERE REG_CARET_ANCHORS_HERE | |
714 # define RE_CHAR_CLASSES REG_CHAR_CLASSES | |
715 # define RE_CONTEXT_INDEP_ANCHORS REG_CONTEXT_INDEP_ANCHORS | |
716 # define RE_CONTEXT_INDEP_OPS REG_CONTEXT_INDEP_OPS | |
717 # define RE_CONTEXT_INVALID_DUP REG_CONTEXT_INVALID_DUP | |
718 # define RE_CONTEXT_INVALID_OPS REG_CONTEXT_INVALID_OPS | |
719 # define RE_DEBUG REG_DEBUG | |
720 # define RE_DOT_NEWLINE REG_DOT_NEWLINE | |
721 # define RE_DOT_NOT_NULL REG_DOT_NOT_NULL | |
722 # define RE_HAT_LISTS_NOT_NEWLINE REG_HAT_LISTS_NOT_NEWLINE | |
723 # define RE_ICASE REG_IGNORE_CASE /* avoid collision with REG_ICASE */ | |
724 # define RE_INTERVALS REG_INTERVALS | |
725 # define RE_INVALID_INTERVAL_ORD REG_INVALID_INTERVAL_ORD | |
726 # define RE_LIMITED_OPS REG_LIMITED_OPS | |
727 # define RE_NEWLINE_ALT REG_NEWLINE_ALT | |
728 # define RE_NO_BK_BRACES REG_NO_BK_BRACES | |
729 # define RE_NO_BK_PARENS REG_NO_BK_PARENS | |
730 # define RE_NO_BK_REFS REG_NO_BK_REFS | |
731 # define RE_NO_BK_VBAR REG_NO_BK_VBAR | |
732 # define RE_NO_EMPTY_RANGES REG_NO_EMPTY_RANGES | |
733 # define RE_NO_GNU_OPS REG_NO_GNU_OPS | |
734 # define RE_NO_POSIX_BACKTRACKING REG_NO_POSIX_BACKTRACKING | |
735 # define RE_NO_SUB REG_NO_SUB | |
736 # define RE_NREGS REG_NREGS | |
737 # define RE_SYNTAX_AWK REG_SYNTAX_AWK | |
738 # define RE_SYNTAX_ED REG_SYNTAX_ED | |
739 # define RE_SYNTAX_EGREP REG_SYNTAX_EGREP | |
740 # define RE_SYNTAX_EMACS REG_SYNTAX_EMACS | |
741 # define RE_SYNTAX_GNU_AWK REG_SYNTAX_GNU_AWK | |
742 # define RE_SYNTAX_GREP REG_SYNTAX_GREP | |
743 # define RE_SYNTAX_POSIX_AWK REG_SYNTAX_POSIX_AWK | |
744 # define RE_SYNTAX_POSIX_BASIC REG_SYNTAX_POSIX_BASIC | |
745 # define RE_SYNTAX_POSIX_EGREP REG_SYNTAX_POSIX_EGREP | |
746 # define RE_SYNTAX_POSIX_EXTENDED REG_SYNTAX_POSIX_EXTENDED | |
747 # define RE_SYNTAX_POSIX_MINIMAL_BASIC REG_SYNTAX_POSIX_MINIMAL_BASIC | |
748 # define RE_SYNTAX_POSIX_MINIMAL_EXTENDED REG_SYNTAX_POSIX_MINIMAL_EXTENDED | |
749 # define RE_SYNTAX_SED REG_SYNTAX_SED | |
750 # define RE_UNMATCHED_RIGHT_PAREN_ORD REG_UNMATCHED_RIGHT_PAREN_ORD | |
751 # ifndef RE_TRANSLATE_TYPE | |
752 # define RE_TRANSLATE_TYPE REG_TRANSLATE_TYPE | |
753 # endif | |
754 | |
755 #endif /* defined _REGEX_SOURCE */ | |
756 | |
988
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
757 #ifdef __cplusplus |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
758 } |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
759 #endif /* C++ */ |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
760 |
ba13cef00d11
replace with new version from libc
Jim Meyering <jim@meyering.net>
parents:
649
diff
changeset
|
761 #endif /* regex.h */ |
14 | 762 |
763 /* | |
764 Local variables: | |
765 make-backup-files: t | |
766 version-control: t | |
767 trim-versions-without-asking: nil | |
768 End: | |
769 */ |