regex.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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,2006,2008
  4. Free Software Foundation, Inc.
  5. This file is part of the GNU C Library.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Lesser General Public
  8. License as published by the Free Software Foundation; either
  9. version 2.1 of the License, or (at your option) any later version.
  10. The GNU C Library 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 GNU
  13. Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with the GNU C Library; if not, see
  16. <http://www.gnu.org/licenses/>. */
  17. #ifndef _REGEX_H
  18. #define _REGEX_H 1
  19. #include <sys/types.h>
  20. __BEGIN_DECLS
  21. /* The following two types have to be signed and unsigned integer type
  22. wide enough to hold a value of a pointer. For most ANSI compilers
  23. ptrdiff_t and size_t should be likely OK. Still size of these two
  24. types is 2 for Microsoft C. Ugh... */
  25. typedef long int s_reg_t;
  26. typedef unsigned long int active_reg_t;
  27. /* The following bits are used to determine the regexp syntax we
  28. recognize. The set/not-set meanings are chosen so that Emacs syntax
  29. remains the value 0. The bits are given in alphabetical order, and
  30. the definitions shifted by one from the previous bit; thus, when we
  31. add or remove a bit, only one other definition need change. */
  32. typedef unsigned long int reg_syntax_t;
  33. #ifdef __USE_GNU
  34. /* If this bit is not set, then \ inside a bracket expression is literal.
  35. If set, then such a \ quotes the following character. */
  36. # define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
  37. /* If this bit is not set, then + and ? are operators, and \+ and \? are
  38. literals.
  39. If set, then \+ and \? are operators and + and ? are literals. */
  40. # define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
  41. /* If this bit is set, then character classes are supported. They are:
  42. [:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
  43. [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
  44. If not set, then character classes are not supported. */
  45. # define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
  46. /* If this bit is set, then ^ and $ are always anchors (outside bracket
  47. expressions, of course).
  48. If this bit is not set, then it depends:
  49. ^ is an anchor if it is at the beginning of a regular
  50. expression or after an open-group or an alternation operator;
  51. $ is an anchor if it is at the end of a regular expression, or
  52. before a close-group or an alternation operator.
  53. This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
  54. POSIX draft 11.2 says that * etc. in leading positions is undefined.
  55. We already implemented a previous draft which made those constructs
  56. invalid, though, so we haven't changed the code back. */
  57. # define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
  58. /* If this bit is set, then special characters are always special
  59. regardless of where they are in the pattern.
  60. If this bit is not set, then special characters are special only in
  61. some contexts; otherwise they are ordinary. Specifically,
  62. * + ? and intervals are only special when not after the beginning,
  63. open-group, or alternation operator. */
  64. # define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
  65. /* If this bit is set, then *, +, ?, and { cannot be first in an re or
  66. immediately after an alternation or begin-group operator. */
  67. # define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
  68. /* If this bit is set, then . matches newline.
  69. If not set, then it doesn't. */
  70. # define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
  71. /* If this bit is set, then . doesn't match NUL.
  72. If not set, then it does. */
  73. # define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
  74. /* If this bit is set, nonmatching lists [^...] do not match newline.
  75. If not set, they do. */
  76. # define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
  77. /* If this bit is set, either \{...\} or {...} defines an
  78. interval, depending on RE_NO_BK_BRACES.
  79. If not set, \{, \}, {, and } are literals. */
  80. # define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
  81. /* If this bit is set, +, ? and | aren't recognized as operators.
  82. If not set, they are. */
  83. # define RE_LIMITED_OPS (RE_INTERVALS << 1)
  84. /* If this bit is set, newline is an alternation operator.
  85. If not set, newline is literal. */
  86. # define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
  87. /* If this bit is set, then `{...}' defines an interval, and \{ and \}
  88. are literals.
  89. If not set, then `\{...\}' defines an interval. */
  90. # define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
  91. /* If this bit is set, (...) defines a group, and \( and \) are literals.
  92. If not set, \(...\) defines a group, and ( and ) are literals. */
  93. # define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
  94. /* If this bit is set, then \<digit> matches <digit>.
  95. If not set, then \<digit> is a back-reference. */
  96. # define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
  97. /* If this bit is set, then | is an alternation operator, and \| is literal.
  98. If not set, then \| is an alternation operator, and | is literal. */
  99. # define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
  100. /* If this bit is set, then an ending range point collating higher
  101. than the starting range point, as in [z-a], is invalid.
  102. If not set, then when ending range point collates higher than the
  103. starting range point, the range is ignored. */
  104. # define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
  105. /* If this bit is set, then an unmatched ) is ordinary.
  106. If not set, then an unmatched ) is invalid. */
  107. # define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
  108. /* If this bit is set, succeed as soon as we match the whole pattern,
  109. without further backtracking. */
  110. # define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
  111. /* If this bit is set, do not process the GNU regex operators.
  112. If not set, then the GNU regex operators are recognized. */
  113. # define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
  114. /* If this bit is set, turn on internal regex debugging.
  115. If not set, and debugging was on, turn it off.
  116. This only works if regex.c is compiled -DDEBUG.
  117. We define this bit always, so that all that's needed to turn on
  118. debugging is to recompile regex.c; the calling code can always have
  119. this bit set, and it won't affect anything in the normal case. */
  120. # define RE_DEBUG (RE_NO_GNU_OPS << 1)
  121. /* If this bit is set, a syntactically invalid interval is treated as
  122. a string of ordinary characters. For example, the ERE 'a{1' is
  123. treated as 'a\{1'. */
  124. # define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
  125. /* If this bit is set, then ignore case when matching.
  126. If not set, then case is significant. */
  127. # define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
  128. /* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
  129. for ^, because it is difficult to scan the regex backwards to find
  130. whether ^ should be special. */
  131. # define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
  132. /* If this bit is set, then \{ cannot be first in an bre or
  133. immediately after an alternation or begin-group operator. */
  134. # define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
  135. /* If this bit is set, then no_sub will be set to 1 during
  136. re_compile_pattern. */
  137. # define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
  138. #endif
  139. /* This global variable defines the particular regexp syntax to use (for
  140. some interfaces). When a regexp is compiled, the syntax used is
  141. stored in the pattern buffer, so changing this does not affect
  142. already-compiled regexps. */
  143. extern reg_syntax_t re_syntax_options;
  144. #ifdef __USE_GNU
  145. /* Define combinations of the above bits for the standard possibilities.
  146. (The [[[ comments delimit what gets put into the Texinfo file, so
  147. don't delete them!) */
  148. /* [[[begin syntaxes]]] */
  149. #define RE_SYNTAX_EMACS 0
  150. #define RE_SYNTAX_AWK \
  151. (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
  152. | RE_NO_BK_PARENS | RE_NO_BK_REFS \
  153. | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
  154. | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
  155. | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
  156. #define RE_SYNTAX_GNU_AWK \
  157. ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
  158. & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
  159. | RE_CONTEXT_INVALID_OPS ))
  160. #define RE_SYNTAX_POSIX_AWK \
  161. (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
  162. | RE_INTERVALS | RE_NO_GNU_OPS)
  163. #define RE_SYNTAX_GREP \
  164. (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
  165. | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
  166. | RE_NEWLINE_ALT)
  167. #define RE_SYNTAX_EGREP \
  168. (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
  169. | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
  170. | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
  171. | RE_NO_BK_VBAR)
  172. #define RE_SYNTAX_POSIX_EGREP \
  173. (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
  174. | RE_INVALID_INTERVAL_ORD)
  175. /* P1003.2/D11.2, section 4.20.7.1, lines 5078ff. */
  176. #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
  177. #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
  178. /* Syntax bits common to both basic and extended POSIX regex syntax. */
  179. #define _RE_SYNTAX_POSIX_COMMON \
  180. (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
  181. | RE_INTERVALS | RE_NO_EMPTY_RANGES)
  182. #define RE_SYNTAX_POSIX_BASIC \
  183. (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
  184. /* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
  185. RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
  186. isn't minimal, since other operators, such as \`, aren't disabled. */
  187. #define RE_SYNTAX_POSIX_MINIMAL_BASIC \
  188. (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
  189. #define RE_SYNTAX_POSIX_EXTENDED \
  190. (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
  191. | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
  192. | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
  193. | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
  194. /* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
  195. removed and RE_NO_BK_REFS is added. */
  196. #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
  197. (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
  198. | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
  199. | RE_NO_BK_PARENS | RE_NO_BK_REFS \
  200. | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
  201. /* [[[end syntaxes]]] */
  202. /* Maximum number of duplicates an interval can allow. Some systems
  203. (erroneously) define this in other header files, but we want our
  204. value, so remove any previous define. */
  205. # ifdef RE_DUP_MAX
  206. # undef RE_DUP_MAX
  207. # endif
  208. /* If sizeof(int) == 2, then ((1 << 15) - 1) overflows. */
  209. # define RE_DUP_MAX (0x7fff)
  210. #endif
  211. /* POSIX `cflags' bits (i.e., information for `regcomp'). */
  212. /* If this bit is set, then use extended regular expression syntax.
  213. If not set, then use basic regular expression syntax. */
  214. #define REG_EXTENDED 1
  215. /* If this bit is set, then ignore case when matching.
  216. If not set, then case is significant. */
  217. #define REG_ICASE (REG_EXTENDED << 1)
  218. /* If this bit is set, then anchors do not match at newline
  219. characters in the string.
  220. If not set, then anchors do match at newlines. */
  221. #define REG_NEWLINE (REG_ICASE << 1)
  222. /* If this bit is set, then report only success or fail in regexec.
  223. If not set, then returns differ between not matching and errors. */
  224. #define REG_NOSUB (REG_NEWLINE << 1)
  225. /* POSIX `eflags' bits (i.e., information for regexec). */
  226. /* If this bit is set, then the beginning-of-line operator doesn't match
  227. the beginning of the string (presumably because it's not the
  228. beginning of a line).
  229. If not set, then the beginning-of-line operator does match the
  230. beginning of the string. */
  231. #define REG_NOTBOL 1
  232. /* Like REG_NOTBOL, except for the end-of-line. */
  233. #define REG_NOTEOL (1 << 1)
  234. /* Use PMATCH[0] to delimit the start and end of the search in the
  235. buffer. */
  236. #define REG_STARTEND (1 << 2)
  237. /* If any error codes are removed, changed, or added, update the
  238. `re_error_msg' table in regex.c. */
  239. typedef enum
  240. {
  241. #if defined _XOPEN_SOURCE || defined __USE_XOPEN2K
  242. REG_ENOSYS = -1, /* This will never happen for this implementation. */
  243. #endif
  244. REG_NOERROR = 0, /* Success. */
  245. REG_NOMATCH, /* Didn't find a match (for regexec). */
  246. /* POSIX regcomp return error codes. (In the order listed in the
  247. standard.) */
  248. REG_BADPAT, /* Invalid pattern. */
  249. REG_ECOLLATE, /* Invalid collating element. */
  250. REG_ECTYPE, /* Invalid character class name. */
  251. REG_EESCAPE, /* Trailing backslash. */
  252. REG_ESUBREG, /* Invalid back reference. */
  253. REG_EBRACK, /* Unmatched left bracket. */
  254. REG_EPAREN, /* Parenthesis imbalance. */
  255. REG_EBRACE, /* Unmatched \{. */
  256. REG_BADBR, /* Invalid contents of \{\}. */
  257. REG_ERANGE, /* Invalid range end. */
  258. REG_ESPACE, /* Ran out of memory. */
  259. REG_BADRPT, /* No preceding re for repetition op. */
  260. /* Error codes we've added. */
  261. REG_EEND, /* Premature end. */
  262. REG_ESIZE, /* Compiled pattern bigger than 2^16 bytes. */
  263. REG_ERPAREN /* Unmatched ) or \); not returned from regcomp. */
  264. } reg_errcode_t;
  265. /* This data structure represents a compiled pattern. Before calling
  266. the pattern compiler, the fields `buffer', `allocated', `fastmap',
  267. `translate', and `no_sub' can be set. After the pattern has been
  268. compiled, the `re_nsub' field is available. All other fields are
  269. private to the regex routines. */
  270. #ifndef RE_TRANSLATE_TYPE
  271. # define __RE_TRANSLATE_TYPE unsigned char *
  272. # ifdef __USE_GNU
  273. # define RE_TRANSLATE_TYPE __RE_TRANSLATE_TYPE
  274. # endif
  275. #endif
  276. #ifdef __USE_GNU
  277. # define __REPB_PREFIX(name) name
  278. #else
  279. # define __REPB_PREFIX(name) __##name
  280. #endif
  281. struct re_pattern_buffer
  282. {
  283. /* Space that holds the compiled pattern. It is declared as
  284. `unsigned char *' because its elements are sometimes used as
  285. array indexes. */
  286. unsigned char *__REPB_PREFIX(buffer);
  287. /* Number of bytes to which `buffer' points. */
  288. unsigned long int __REPB_PREFIX(allocated);
  289. /* Number of bytes actually used in `buffer'. */
  290. unsigned long int __REPB_PREFIX(used);
  291. /* Syntax setting with which the pattern was compiled. */
  292. reg_syntax_t __REPB_PREFIX(syntax);
  293. /* Pointer to a fastmap, if any, otherwise zero. re_search uses the
  294. fastmap, if there is one, to skip over impossible starting points
  295. for matches. */
  296. char *__REPB_PREFIX(fastmap);
  297. /* Either a translate table to apply to all characters before
  298. comparing them, or zero for no translation. The translation is
  299. applied to a pattern when it is compiled and to a string when it
  300. is matched. */
  301. __RE_TRANSLATE_TYPE __REPB_PREFIX(translate);
  302. /* Number of subexpressions found by the compiler. */
  303. size_t re_nsub;
  304. /* Zero if this pattern cannot match the empty string, one else.
  305. Well, in truth it's used only in `re_search_2', to see whether or
  306. not we should use the fastmap, so we don't set this absolutely
  307. perfectly; see `re_compile_fastmap' (the `duplicate' case). */
  308. unsigned __REPB_PREFIX(can_be_null) : 1;
  309. /* If REGS_UNALLOCATED, allocate space in the `regs' structure
  310. for `max (RE_NREGS, re_nsub + 1)' groups.
  311. If REGS_REALLOCATE, reallocate space if necessary.
  312. If REGS_FIXED, use what's there. */
  313. #ifdef __USE_GNU
  314. # define REGS_UNALLOCATED 0
  315. # define REGS_REALLOCATE 1
  316. # define REGS_FIXED 2
  317. #endif
  318. unsigned __REPB_PREFIX(regs_allocated) : 2;
  319. /* Set to zero when `regex_compile' compiles a pattern; set to one
  320. by `re_compile_fastmap' if it updates the fastmap. */
  321. unsigned __REPB_PREFIX(fastmap_accurate) : 1;
  322. /* If set, `re_match_2' does not return information about
  323. subexpressions. */
  324. unsigned __REPB_PREFIX(no_sub) : 1;
  325. /* If set, a beginning-of-line anchor doesn't match at the beginning
  326. of the string. */
  327. unsigned __REPB_PREFIX(not_bol) : 1;
  328. /* Similarly for an end-of-line anchor. */
  329. unsigned __REPB_PREFIX(not_eol) : 1;
  330. /* If true, an anchor at a newline matches. */
  331. unsigned __REPB_PREFIX(newline_anchor) : 1;
  332. };
  333. typedef struct re_pattern_buffer regex_t;
  334. /* Type for byte offsets within the string. POSIX mandates this. */
  335. typedef int regoff_t;
  336. #ifdef __USE_GNU
  337. /* This is the structure we store register match data in. See
  338. regex.texinfo for a full description of what registers match. */
  339. struct re_registers
  340. {
  341. unsigned num_regs;
  342. regoff_t *start;
  343. regoff_t *end;
  344. };
  345. /* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
  346. `re_match_2' returns information about at least this many registers
  347. the first time a `regs' structure is passed. */
  348. # ifndef RE_NREGS
  349. # define RE_NREGS 30
  350. # endif
  351. #endif
  352. /* POSIX specification for registers. Aside from the different names than
  353. `re_registers', POSIX uses an array of structures, instead of a
  354. structure of arrays. */
  355. typedef struct
  356. {
  357. regoff_t rm_so; /* Byte offset from string's start to substring's start. */
  358. regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
  359. } regmatch_t;
  360. /* Declarations for routines. */
  361. #ifdef __USE_GNU
  362. /* Sets the current default syntax to SYNTAX, and return the old syntax.
  363. You can also simply assign to the `re_syntax_options' variable. */
  364. extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax);
  365. /* Compile the regular expression PATTERN, with length LENGTH
  366. and syntax given by the global `re_syntax_options', into the buffer
  367. BUFFER. Return NULL if successful, and an error string if not. */
  368. extern const char *re_compile_pattern (const char *__pattern, size_t __length,
  369. struct re_pattern_buffer *__buffer);
  370. /* Compile a fastmap for the compiled pattern in BUFFER; used to
  371. accelerate searches. Return 0 if successful and -2 if was an
  372. internal error. */
  373. extern int re_compile_fastmap (struct re_pattern_buffer *__buffer);
  374. libc_hidden_proto(re_compile_fastmap)
  375. /* Search in the string STRING (with length LENGTH) for the pattern
  376. compiled into BUFFER. Start searching at position START, for RANGE
  377. characters. Return the starting position of the match, -1 for no
  378. match, or -2 for an internal error. Also return register
  379. information in REGS (if REGS and BUFFER->no_sub are nonzero). */
  380. extern int re_search (struct re_pattern_buffer *__buffer, const char *__string,
  381. int __length, int __start, int __range,
  382. struct re_registers *__regs);
  383. libc_hidden_proto(re_search)
  384. /* Like `re_search', but search in the concatenation of STRING1 and
  385. STRING2. Also, stop searching at index START + STOP. */
  386. extern int re_search_2 (struct re_pattern_buffer *__buffer,
  387. const char *__string1, int __length1,
  388. const char *__string2, int __length2, int __start,
  389. int __range, struct re_registers *__regs, int __stop);
  390. libc_hidden_proto(re_search_2)
  391. /* Like `re_search', but return how many characters in STRING the regexp
  392. in BUFFER matched, starting at position START. */
  393. extern int re_match (struct re_pattern_buffer *__buffer, const char *__string,
  394. int __length, int __start, struct re_registers *__regs);
  395. /* Relates to `re_match' as `re_search_2' relates to `re_search'. */
  396. extern int re_match_2 (struct re_pattern_buffer *__buffer,
  397. const char *__string1, int __length1,
  398. const char *__string2, int __length2, int __start,
  399. struct re_registers *__regs, int __stop);
  400. /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
  401. ENDS. Subsequent matches using BUFFER and REGS will use this memory
  402. for recording register information. STARTS and ENDS must be
  403. allocated with malloc, and must each be at least `NUM_REGS * sizeof
  404. (regoff_t)' bytes long.
  405. If NUM_REGS == 0, then subsequent matches should allocate their own
  406. register data.
  407. Unless this function is called, the first search or match using
  408. PATTERN_BUFFER will allocate its own register data, without
  409. freeing the old data. */
  410. extern void re_set_registers (struct re_pattern_buffer *__buffer,
  411. struct re_registers *__regs,
  412. unsigned int __num_regs,
  413. regoff_t *__starts, regoff_t *__ends);
  414. #endif /* Use GNU */
  415. #if defined _REGEX_RE_COMP || (defined _LIBC && defined __USE_BSD)
  416. # ifndef _CRAY
  417. /* 4.2 bsd compatibility. */
  418. extern char *re_comp (const char *);
  419. extern int re_exec (const char *);
  420. # endif
  421. #endif
  422. /* GCC 2.95 and later have "__restrict"; C99 compilers have
  423. "restrict", and "configure" may have defined "restrict". */
  424. #ifndef __restrict
  425. # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
  426. # if defined restrict || 199901L <= __STDC_VERSION__
  427. # define __restrict restrict
  428. # else
  429. # define __restrict
  430. # endif
  431. # endif
  432. #endif
  433. /* gcc 3.1 and up support the [restrict] syntax. */
  434. #ifndef __restrict_arr
  435. # if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) \
  436. && !defined __GNUG__
  437. # define __restrict_arr __restrict
  438. # else
  439. # define __restrict_arr
  440. # endif
  441. #endif
  442. /* POSIX compatibility. */
  443. extern int regcomp (regex_t *__restrict __preg,
  444. const char *__restrict __pattern,
  445. int __cflags);
  446. extern int regexec (const regex_t *__restrict __preg,
  447. const char *__restrict __string, size_t __nmatch,
  448. regmatch_t __pmatch[__restrict_arr],
  449. int __eflags);
  450. libc_hidden_proto(regexec)
  451. extern size_t regerror (int __errcode, const regex_t *__restrict __preg,
  452. char *__restrict __errbuf, size_t __errbuf_size);
  453. extern void regfree (regex_t *__preg);
  454. libc_hidden_proto(regfree)
  455. __END_DECLS
  456. #endif /* regex.h */