16 |
|
|
17 |
You should have received a copy of the GNU General Public License along |
You should have received a copy of the GNU General Public License along |
18 |
with this program; if not, write to the Free Software Foundation, |
with this program; if not, write to the Free Software Foundation, |
19 |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
20 |
|
|
21 |
#ifndef _REGEX_H |
#ifndef _REGEX_H |
22 |
#define _REGEX_H 1 |
#define _REGEX_H 1 |
169 |
If not set, then case is significant. */ |
If not set, then case is significant. */ |
170 |
#define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) |
#define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1) |
171 |
|
|
172 |
|
/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only |
173 |
|
for ^, because it is difficult to scan the regex backwards to find |
174 |
|
whether ^ should be special. */ |
175 |
|
#define RE_CARET_ANCHORS_HERE (RE_ICASE << 1) |
176 |
|
|
177 |
|
/* If this bit is set, then \{ cannot be first in an bre or |
178 |
|
immediately after an alternation or begin-group operator. */ |
179 |
|
#define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1) |
180 |
|
|
181 |
|
/* If this bit is set, then no_sub will be set to 1 during |
182 |
|
re_compile_pattern. */ |
183 |
|
#define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1) |
184 |
|
|
185 |
/* This global variable defines the particular regexp syntax to use (for |
/* This global variable defines the particular regexp syntax to use (for |
186 |
some interfaces). When a regexp is compiled, the syntax used is |
some interfaces). When a regexp is compiled, the syntax used is |
187 |
stored in the pattern buffer, so changing this does not affect |
stored in the pattern buffer, so changing this does not affect |
206 |
& ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \ |
& ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \ |
207 |
| RE_CONTEXT_INVALID_OPS )) |
| RE_CONTEXT_INVALID_OPS )) |
208 |
|
|
209 |
#define RE_SYNTAX_POSIX_AWK \ |
#define RE_SYNTAX_POSIX_AWK \ |
210 |
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ |
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \ |
211 |
| RE_INTERVALS | RE_NO_GNU_OPS) |
| RE_INTERVALS | RE_NO_GNU_OPS) |
212 |
|
|
236 |
| RE_INTERVALS | RE_NO_EMPTY_RANGES) |
| RE_INTERVALS | RE_NO_EMPTY_RANGES) |
237 |
|
|
238 |
#define RE_SYNTAX_POSIX_BASIC \ |
#define RE_SYNTAX_POSIX_BASIC \ |
239 |
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM) |
(_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP) |
240 |
|
|
241 |
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes |
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes |
242 |
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this |
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this |
301 |
/* Like REG_NOTBOL, except for the end-of-line. */ |
/* Like REG_NOTBOL, except for the end-of-line. */ |
302 |
#define REG_NOTEOL (1 << 1) |
#define REG_NOTEOL (1 << 1) |
303 |
|
|
304 |
|
/* Use PMATCH[0] to delimit the start and end of the search in the |
305 |
|
buffer. */ |
306 |
|
#define REG_STARTEND (1 << 2) |
307 |
|
|
308 |
|
|
309 |
/* If any error codes are removed, changed, or added, update the |
/* If any error codes are removed, changed, or added, update the |
310 |
`re_error_msg' table in regex.c. */ |
`re_error_msg' table in regex.c. */ |
320 |
/* POSIX regcomp return error codes. (In the order listed in the |
/* POSIX regcomp return error codes. (In the order listed in the |
321 |
standard.) */ |
standard.) */ |
322 |
REG_BADPAT, /* Invalid pattern. */ |
REG_BADPAT, /* Invalid pattern. */ |
323 |
REG_ECOLLATE, /* Not implemented. */ |
REG_ECOLLATE, /* Inalid collating element. */ |
324 |
REG_ECTYPE, /* Invalid character class name. */ |
REG_ECTYPE, /* Invalid character class name. */ |
325 |
REG_EESCAPE, /* Trailing backslash. */ |
REG_EESCAPE, /* Trailing backslash. */ |
326 |
REG_ESUBREG, /* Invalid back reference. */ |
REG_ESUBREG, /* Invalid back reference. */ |
451 |
|
|
452 |
/* Declarations for routines. */ |
/* Declarations for routines. */ |
453 |
|
|
454 |
|
/* To avoid duplicating every routine declaration -- once with a |
455 |
|
prototype (if we are ANSI), and once without (if we aren't) -- we |
456 |
|
use the following macro to declare argument types. This |
457 |
|
unfortunately clutters up the declarations a bit, but I think it's |
458 |
|
worth it. */ |
459 |
|
|
460 |
|
#if __STDC__ |
461 |
|
|
462 |
|
# define _RE_ARGS(args) args |
463 |
|
|
464 |
|
#else /* not __STDC__ */ |
465 |
|
|
466 |
|
# define _RE_ARGS(args) () |
467 |
|
|
468 |
|
#endif /* not __STDC__ */ |
469 |
|
|
470 |
/* Sets the current default syntax to SYNTAX, and return the old syntax. |
/* Sets the current default syntax to SYNTAX, and return the old syntax. |
471 |
You can also simply assign to the `re_syntax_options' variable. */ |
You can also simply assign to the `re_syntax_options' variable. */ |
472 |
extern reg_syntax_t re_set_syntax (reg_syntax_t syntax); |
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); |
473 |
|
|
474 |
/* Compile the regular expression PATTERN, with length LENGTH |
/* Compile the regular expression PATTERN, with length LENGTH |
475 |
and syntax given by the global `re_syntax_options', into the buffer |
and syntax given by the global `re_syntax_options', into the buffer |
476 |
BUFFER. Return NULL if successful, and an error string if not. */ |
BUFFER. Return NULL if successful, and an error string if not. */ |
477 |
extern const char *re_compile_pattern (const char *pattern, size_t length, |
extern const char *re_compile_pattern |
478 |
struct re_pattern_buffer *buffer); |
_RE_ARGS ((const char *pattern, size_t length, |
479 |
|
struct re_pattern_buffer *buffer)); |
480 |
|
|
481 |
|
|
482 |
/* Compile a fastmap for the compiled pattern in BUFFER; used to |
/* Compile a fastmap for the compiled pattern in BUFFER; used to |
483 |
accelerate searches. Return 0 if successful and -2 if was an |
accelerate searches. Return 0 if successful and -2 if was an |
484 |
internal error. */ |
internal error. */ |
485 |
extern int re_compile_fastmap (struct re_pattern_buffer *buffer); |
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); |
486 |
|
|
487 |
|
|
488 |
/* Search in the string STRING (with length LENGTH) for the pattern |
/* Search in the string STRING (with length LENGTH) for the pattern |
490 |
characters. Return the starting position of the match, -1 for no |
characters. Return the starting position of the match, -1 for no |
491 |
match, or -2 for an internal error. Also return register |
match, or -2 for an internal error. Also return register |
492 |
information in REGS (if REGS and BUFFER->no_sub are nonzero). */ |
information in REGS (if REGS and BUFFER->no_sub are nonzero). */ |
493 |
extern int re_search (struct re_pattern_buffer *buffer, const char *string, |
extern int re_search |
494 |
int length, int start, int range, |
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, |
495 |
struct re_registers *regs); |
int length, int start, int range, struct re_registers *regs)); |
496 |
|
|
497 |
|
|
498 |
/* Like `re_search', but search in the concatenation of STRING1 and |
/* Like `re_search', but search in the concatenation of STRING1 and |
499 |
STRING2. Also, stop searching at index START + STOP. */ |
STRING2. Also, stop searching at index START + STOP. */ |
500 |
extern int re_search_2 (struct re_pattern_buffer *buffer, const char *string1, |
extern int re_search_2 |
501 |
int length1, const char *string2, int length2, |
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, |
502 |
int start, int range, struct re_registers *regs, |
int length1, const char *string2, int length2, |
503 |
int stop); |
int start, int range, struct re_registers *regs, int stop)); |
504 |
|
|
505 |
|
|
506 |
/* Like `re_search', but return how many characters in STRING the regexp |
/* Like `re_search', but return how many characters in STRING the regexp |
507 |
in BUFFER matched, starting at position START. */ |
in BUFFER matched, starting at position START. */ |
508 |
extern int re_match (struct re_pattern_buffer *buffer, const char *string, |
extern int re_match |
509 |
int length, int start, struct re_registers *regs); |
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, |
510 |
|
int length, int start, struct re_registers *regs)); |
511 |
|
|
512 |
|
|
513 |
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ |
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ |
514 |
extern int re_match_2 (struct re_pattern_buffer *buffer, const char *string1, |
extern int re_match_2 |
515 |
int length1, const char *string2, int length2, |
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, |
516 |
int start, struct re_registers *regs, int stop); |
int length1, const char *string2, int length2, |
517 |
|
int start, struct re_registers *regs, int stop)); |
518 |
|
|
519 |
|
|
520 |
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and |
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and |
529 |
Unless this function is called, the first search or match using |
Unless this function is called, the first search or match using |
530 |
PATTERN_BUFFER will allocate its own register data, without |
PATTERN_BUFFER will allocate its own register data, without |
531 |
freeing the old data. */ |
freeing the old data. */ |
532 |
extern void re_set_registers (struct re_pattern_buffer *buffer, |
extern void re_set_registers |
533 |
struct re_registers *regs, unsigned num_regs, |
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, |
534 |
regoff_t *starts, regoff_t *ends); |
unsigned num_regs, regoff_t *starts, regoff_t *ends)); |
535 |
|
|
536 |
#if defined _REGEX_RE_COMP || defined _LIBC |
#if defined _REGEX_RE_COMP || defined _LIBC |
537 |
# ifndef _CRAY |
# ifndef _CRAY |
538 |
/* 4.2 bsd compatibility. */ |
/* 4.2 bsd compatibility. */ |
539 |
extern char *re_comp (const char *); |
extern char *re_comp _RE_ARGS ((const char *)); |
540 |
extern int re_exec (const char *); |
extern int re_exec _RE_ARGS ((const char *)); |
541 |
# endif |
# endif |
542 |
#endif |
#endif |
543 |
|
|
562 |
#endif |
#endif |
563 |
|
|
564 |
/* POSIX compatibility. */ |
/* POSIX compatibility. */ |
565 |
extern int regcomp (regex_t *__restrict __preg, |
extern int regcomp _RE_ARGS ((regex_t *__restrict __preg, |
566 |
const char *__restrict __pattern, |
const char *__restrict __pattern, |
567 |
int __cflags); |
int __cflags)); |
568 |
|
|
569 |
extern int regexec (const regex_t *__restrict __preg, |
extern int regexec _RE_ARGS ((const regex_t *__restrict __preg, |
570 |
const char *__restrict __string, size_t __nmatch, |
const char *__restrict __string, size_t __nmatch, |
571 |
regmatch_t __pmatch[__restrict_arr], |
regmatch_t __pmatch[__restrict_arr], |
572 |
int __eflags); |
int __eflags)); |
573 |
|
|
574 |
extern size_t regerror (int __errcode, const regex_t *__preg, |
extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg, |
575 |
char *__errbuf, size_t __errbuf_size); |
char *__errbuf, size_t __errbuf_size)); |
576 |
|
|
577 |
extern void regfree (regex_t *__preg); |
extern void regfree _RE_ARGS ((regex_t *__preg)); |
578 |
|
|
579 |
|
|
580 |
#ifdef __cplusplus |
#ifdef __cplusplus |