regex.h 21 KB

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