regex.h 28 KB

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