regex.h 25 KB

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