regex.h 21 KB

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