|
@@ -1,6 +1,6 @@
|
|
/* Definitions for data structures and routines for the regular
|
|
/* Definitions for data structures and routines for the regular
|
|
expression library.
|
|
expression library.
|
|
- Copyright (C) 1985,1989-93,1995-98,2000,2001,2002
|
|
+ Copyright (C) 1985,1989-93,1995-98,2000,2001,2002,2003,2005
|
|
Free Software Foundation, Inc.
|
|
Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
@@ -22,6 +22,8 @@
|
|
#ifndef _REGEX_H
|
|
#ifndef _REGEX_H
|
|
#define _REGEX_H 1
|
|
#define _REGEX_H 1
|
|
|
|
|
|
|
|
+#include <sys/types.h>
|
|
|
|
+
|
|
/* Allow the use in C++ code. */
|
|
/* Allow the use in C++ code. */
|
|
#ifdef __cplusplus
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
extern "C" {
|
|
@@ -168,6 +170,19 @@ typedef unsigned long int reg_syntax_t;
|
|
If not set, then case is significant. */
|
|
If not set, then case is significant. */
|
|
#define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
|
|
#define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
|
|
|
|
|
|
|
|
+/* This bit is used internally like RE_CONTEXT_INDEP_ANCHORS but only
|
|
|
|
+ for ^, because it is difficult to scan the regex backwards to find
|
|
|
|
+ whether ^ should be special. */
|
|
|
|
+#define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
|
|
|
|
+
|
|
|
|
+/* If this bit is set, then \{ cannot be first in an bre or
|
|
|
|
+ immediately after an alternation or begin-group operator. */
|
|
|
|
+#define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
|
|
|
|
+
|
|
|
|
+/* If this bit is set, then no_sub will be set to 1 during
|
|
|
|
+ re_compile_pattern. */
|
|
|
|
+#define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
|
|
|
|
+
|
|
/* This global variable defines the particular regexp syntax to use (for
|
|
/* This global variable defines the particular regexp syntax to use (for
|
|
some interfaces). When a regexp is compiled, the syntax used is
|
|
some interfaces). When a regexp is compiled, the syntax used is
|
|
stored in the pattern buffer, so changing this does not affect
|
|
stored in the pattern buffer, so changing this does not affect
|
|
@@ -192,7 +207,7 @@ extern reg_syntax_t re_syntax_options;
|
|
& ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
|
|
& ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
|
|
| RE_CONTEXT_INVALID_OPS ))
|
|
| RE_CONTEXT_INVALID_OPS ))
|
|
|
|
|
|
-#define RE_SYNTAX_POSIX_AWK \
|
|
+#define RE_SYNTAX_POSIX_AWK \
|
|
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
|
|
(RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
|
|
| RE_INTERVALS | RE_NO_GNU_OPS)
|
|
| RE_INTERVALS | RE_NO_GNU_OPS)
|
|
|
|
|
|
@@ -222,7 +237,7 @@ extern reg_syntax_t re_syntax_options;
|
|
| RE_INTERVALS | RE_NO_EMPTY_RANGES)
|
|
| RE_INTERVALS | RE_NO_EMPTY_RANGES)
|
|
|
|
|
|
#define RE_SYNTAX_POSIX_BASIC \
|
|
#define RE_SYNTAX_POSIX_BASIC \
|
|
- (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
|
|
+ (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
|
|
|
|
|
|
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
|
|
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
|
|
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
|
|
RE_LIMITED_OPS, i.e., \? \+ \| are not recognized. Actually, this
|
|
@@ -287,6 +302,10 @@ extern reg_syntax_t re_syntax_options;
|
|
/* Like REG_NOTBOL, except for the end-of-line. */
|
|
/* Like REG_NOTBOL, except for the end-of-line. */
|
|
#define REG_NOTEOL (1 << 1)
|
|
#define REG_NOTEOL (1 << 1)
|
|
|
|
|
|
|
|
+/* Use PMATCH[0] to delimit the start and end of the search in the
|
|
|
|
+ buffer. */
|
|
|
|
+#define REG_STARTEND (1 << 2)
|
|
|
|
+
|
|
|
|
|
|
/* If any error codes are removed, changed, or added, update the
|
|
/* If any error codes are removed, changed, or added, update the
|
|
`re_error_msg' table in regex.c. */
|
|
`re_error_msg' table in regex.c. */
|
|
@@ -302,7 +321,7 @@ typedef enum
|
|
/* POSIX regcomp return error codes. (In the order listed in the
|
|
/* POSIX regcomp return error codes. (In the order listed in the
|
|
standard.) */
|
|
standard.) */
|
|
REG_BADPAT, /* Invalid pattern. */
|
|
REG_BADPAT, /* Invalid pattern. */
|
|
- REG_ECOLLATE, /* Not implemented. */
|
|
+ REG_ECOLLATE, /* Invalid collating element. */
|
|
REG_ECTYPE, /* Invalid character class name. */
|
|
REG_ECTYPE, /* Invalid character class name. */
|
|
REG_EESCAPE, /* Trailing backslash. */
|
|
REG_EESCAPE, /* Trailing backslash. */
|
|
REG_ESUBREG, /* Invalid back reference. */
|
|
REG_ESUBREG, /* Invalid back reference. */
|
|
@@ -327,75 +346,71 @@ typedef enum
|
|
private to the regex routines. */
|
|
private to the regex routines. */
|
|
|
|
|
|
#ifndef RE_TRANSLATE_TYPE
|
|
#ifndef RE_TRANSLATE_TYPE
|
|
-# define RE_TRANSLATE_TYPE char *
|
|
+# define RE_TRANSLATE_TYPE unsigned char *
|
|
#endif
|
|
#endif
|
|
|
|
|
|
struct re_pattern_buffer
|
|
struct re_pattern_buffer
|
|
{
|
|
{
|
|
-/* [[[begin pattern_buffer]]] */
|
|
+ /* Space that holds the compiled pattern. It is declared as
|
|
- /* Space that holds the compiled pattern. It is declared as
|
|
+ `unsigned char *' because its elements are sometimes used as
|
|
- `unsigned char *' because its elements are
|
|
+ array indexes. */
|
|
- sometimes used as array indexes. */
|
|
|
|
unsigned char *buffer;
|
|
unsigned char *buffer;
|
|
|
|
|
|
- /* Number of bytes to which `buffer' points. */
|
|
+ /* Number of bytes to which `buffer' points. */
|
|
unsigned long int allocated;
|
|
unsigned long int allocated;
|
|
|
|
|
|
- /* Number of bytes actually used in `buffer'. */
|
|
+ /* Number of bytes actually used in `buffer'. */
|
|
unsigned long int used;
|
|
unsigned long int used;
|
|
|
|
|
|
- /* Syntax setting with which the pattern was compiled. */
|
|
+ /* Syntax setting with which the pattern was compiled. */
|
|
reg_syntax_t syntax;
|
|
reg_syntax_t syntax;
|
|
|
|
|
|
- /* Pointer to a fastmap, if any, otherwise zero. re_search uses
|
|
+ /* Pointer to a fastmap, if any, otherwise zero. re_search uses the
|
|
- the fastmap, if there is one, to skip over impossible
|
|
+ fastmap, if there is one, to skip over impossible starting points
|
|
- starting points for matches. */
|
|
+ for matches. */
|
|
char *fastmap;
|
|
char *fastmap;
|
|
|
|
|
|
- /* Either a translate table to apply to all characters before
|
|
+ /* Either a translate table to apply to all characters before
|
|
- comparing them, or zero for no translation. The translation
|
|
+ comparing them, or zero for no translation. The translation is
|
|
- is applied to a pattern when it is compiled and to a string
|
|
+ applied to a pattern when it is compiled and to a string when it
|
|
- when it is matched. */
|
|
+ is matched. */
|
|
RE_TRANSLATE_TYPE translate;
|
|
RE_TRANSLATE_TYPE translate;
|
|
|
|
|
|
- /* Number of subexpressions found by the compiler. */
|
|
+ /* Number of subexpressions found by the compiler. */
|
|
size_t re_nsub;
|
|
size_t re_nsub;
|
|
|
|
|
|
- /* Zero if this pattern cannot match the empty string, one else.
|
|
+ /* Zero if this pattern cannot match the empty string, one else.
|
|
- Well, in truth it's used only in `re_search_2', to see
|
|
+ Well, in truth it's used only in `re_search_2', to see whether or
|
|
- whether or not we should use the fastmap, so we don't set
|
|
+ not we should use the fastmap, so we don't set this absolutely
|
|
- this absolutely perfectly; see `re_compile_fastmap' (the
|
|
+ perfectly; see `re_compile_fastmap' (the `duplicate' case). */
|
|
- `duplicate' case). */
|
|
|
|
unsigned can_be_null : 1;
|
|
unsigned can_be_null : 1;
|
|
|
|
|
|
- /* If REGS_UNALLOCATED, allocate space in the `regs' structure
|
|
+ /* If REGS_UNALLOCATED, allocate space in the `regs' structure
|
|
- for `max (RE_NREGS, re_nsub + 1)' groups.
|
|
+ for `max (RE_NREGS, re_nsub + 1)' groups.
|
|
- If REGS_REALLOCATE, reallocate space if necessary.
|
|
+ If REGS_REALLOCATE, reallocate space if necessary.
|
|
- If REGS_FIXED, use what's there. */
|
|
+ If REGS_FIXED, use what's there. */
|
|
#define REGS_UNALLOCATED 0
|
|
#define REGS_UNALLOCATED 0
|
|
#define REGS_REALLOCATE 1
|
|
#define REGS_REALLOCATE 1
|
|
#define REGS_FIXED 2
|
|
#define REGS_FIXED 2
|
|
unsigned regs_allocated : 2;
|
|
unsigned regs_allocated : 2;
|
|
|
|
|
|
- /* Set to zero when `regex_compile' compiles a pattern; set to one
|
|
+ /* Set to zero when `regex_compile' compiles a pattern; set to one
|
|
- by `re_compile_fastmap' if it updates the fastmap. */
|
|
+ by `re_compile_fastmap' if it updates the fastmap. */
|
|
unsigned fastmap_accurate : 1;
|
|
unsigned fastmap_accurate : 1;
|
|
|
|
|
|
- /* If set, `re_match_2' does not return information about
|
|
+ /* If set, `re_match_2' does not return information about
|
|
- subexpressions. */
|
|
+ subexpressions. */
|
|
unsigned no_sub : 1;
|
|
unsigned no_sub : 1;
|
|
|
|
|
|
- /* If set, a beginning-of-line anchor doesn't match at the
|
|
+ /* If set, a beginning-of-line anchor doesn't match at the beginning
|
|
- beginning of the string. */
|
|
+ of the string. */
|
|
unsigned not_bol : 1;
|
|
unsigned not_bol : 1;
|
|
|
|
|
|
- /* Similarly for an end-of-line anchor. */
|
|
+ /* Similarly for an end-of-line anchor. */
|
|
unsigned not_eol : 1;
|
|
unsigned not_eol : 1;
|
|
|
|
|
|
- /* If true, an anchor at a newline matches. */
|
|
+ /* If true, an anchor at a newline matches. */
|
|
unsigned newline_anchor : 1;
|
|
unsigned newline_anchor : 1;
|
|
-
|
|
|
|
-/* [[[end pattern_buffer]]] */
|
|
|
|
};
|
|
};
|
|
|
|
|
|
typedef struct re_pattern_buffer regex_t;
|
|
typedef struct re_pattern_buffer regex_t;
|
|
@@ -451,20 +466,19 @@ typedef struct
|
|
|
|
|
|
/* Sets the current default syntax to SYNTAX, and return the old syntax.
|
|
/* Sets the current default syntax to SYNTAX, and return the old syntax.
|
|
You can also simply assign to the `re_syntax_options' variable. */
|
|
You can also simply assign to the `re_syntax_options' variable. */
|
|
-extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
|
|
+extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t __syntax));
|
|
|
|
|
|
/* Compile the regular expression PATTERN, with length LENGTH
|
|
/* Compile the regular expression PATTERN, with length LENGTH
|
|
and syntax given by the global `re_syntax_options', into the buffer
|
|
and syntax given by the global `re_syntax_options', into the buffer
|
|
BUFFER. Return NULL if successful, and an error string if not. */
|
|
BUFFER. Return NULL if successful, and an error string if not. */
|
|
-extern const char *re_compile_pattern
|
|
+extern const char *re_compile_pattern _RE_ARGS ((const char *__pattern, size_t __length,
|
|
- _RE_ARGS ((const char *pattern, size_t length,
|
|
+ struct re_pattern_buffer *__buffer));
|
|
- struct re_pattern_buffer *buffer));
|
|
|
|
|
|
|
|
|
|
|
|
/* Compile a fastmap for the compiled pattern in BUFFER; used to
|
|
/* Compile a fastmap for the compiled pattern in BUFFER; used to
|
|
accelerate searches. Return 0 if successful and -2 if was an
|
|
accelerate searches. Return 0 if successful and -2 if was an
|
|
internal error. */
|
|
internal error. */
|
|
-extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
|
|
+extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *__buffer));
|
|
|
|
|
|
|
|
|
|
/* Search in the string STRING (with length LENGTH) for the pattern
|
|
/* Search in the string STRING (with length LENGTH) for the pattern
|
|
@@ -472,31 +486,30 @@ extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
|
|
characters. Return the starting position of the match, -1 for no
|
|
characters. Return the starting position of the match, -1 for no
|
|
match, or -2 for an internal error. Also return register
|
|
match, or -2 for an internal error. Also return register
|
|
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
|
|
information in REGS (if REGS and BUFFER->no_sub are nonzero). */
|
|
-extern int re_search
|
|
+extern int re_search _RE_ARGS ((struct re_pattern_buffer *__buffer, const char *__string,
|
|
- _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
|
|
+ int __length, int __start, int __range,
|
|
- int length, int start, int range, struct re_registers *regs));
|
|
+ struct re_registers *__regs));
|
|
|
|
|
|
|
|
|
|
/* Like `re_search', but search in the concatenation of STRING1 and
|
|
/* Like `re_search', but search in the concatenation of STRING1 and
|
|
STRING2. Also, stop searching at index START + STOP. */
|
|
STRING2. Also, stop searching at index START + STOP. */
|
|
-extern int re_search_2
|
|
+extern int re_search_2 _RE_ARGS ((struct re_pattern_buffer *__buffer,
|
|
- _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
|
|
+ const char *__string1, int __length1,
|
|
- int length1, const char *string2, int length2,
|
|
+ const char *__string2, int __length2, int __start,
|
|
- int start, int range, struct re_registers *regs, int stop));
|
|
+ int __range, struct re_registers *__regs, int __stop));
|
|
|
|
|
|
|
|
|
|
/* Like `re_search', but return how many characters in STRING the regexp
|
|
/* Like `re_search', but return how many characters in STRING the regexp
|
|
in BUFFER matched, starting at position START. */
|
|
in BUFFER matched, starting at position START. */
|
|
-extern int re_match
|
|
+extern int re_match _RE_ARGS ((struct re_pattern_buffer *__buffer, const char *__string,
|
|
- _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
|
|
+ int __length, int __start, struct re_registers *__regs));
|
|
- int length, int start, struct re_registers *regs));
|
|
|
|
|
|
|
|
|
|
|
|
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
|
|
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */
|
|
-extern int re_match_2
|
|
+extern int re_match_2 _RE_ARGS ((struct re_pattern_buffer *__buffer,
|
|
- _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
|
|
+ const char *__string1, int __length1,
|
|
- int length1, const char *string2, int length2,
|
|
+ const char *__string2, int __length2, int __start,
|
|
- int start, struct re_registers *regs, int stop));
|
|
+ struct re_registers *__regs, int __stop));
|
|
|
|
|
|
|
|
|
|
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
|
|
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
|
|
@@ -511,9 +524,10 @@ extern int re_match_2
|
|
Unless this function is called, the first search or match using
|
|
Unless this function is called, the first search or match using
|
|
PATTERN_BUFFER will allocate its own register data, without
|
|
PATTERN_BUFFER will allocate its own register data, without
|
|
freeing the old data. */
|
|
freeing the old data. */
|
|
-extern void re_set_registers
|
|
+extern void re_set_registers _RE_ARGS ((struct re_pattern_buffer *__buffer,
|
|
- _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
|
|
+ struct re_registers *__regs,
|
|
- unsigned num_regs, regoff_t *starts, regoff_t *ends));
|
|
+ unsigned int __num_regs,
|
|
|
|
+ regoff_t *__starts, regoff_t *__ends));
|
|
|
|
|
|
#if defined _REGEX_RE_COMP || defined _LIBC
|
|
#if defined _REGEX_RE_COMP || defined _LIBC
|
|
# ifndef _CRAY
|
|
# ifndef _CRAY
|
|
@@ -545,16 +559,16 @@ extern int re_exec _RE_ARGS ((const char *));
|
|
|
|
|
|
/* POSIX compatibility. */
|
|
/* POSIX compatibility. */
|
|
extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
|
|
extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
|
|
- const char *__restrict __pattern,
|
|
+ const char *__restrict __pattern,
|
|
- int __cflags));
|
|
+ int __cflags));
|
|
|
|
|
|
extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
|
|
extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
|
|
- const char *__restrict __string, size_t __nmatch,
|
|
+ const char *__restrict __string, size_t __nmatch,
|
|
- regmatch_t __pmatch[__restrict_arr],
|
|
+ regmatch_t __pmatch[__restrict_arr],
|
|
- int __eflags));
|
|
+ int __eflags));
|
|
|
|
|
|
-extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
|
|
+extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__restrict __preg,
|
|
- char *__errbuf, size_t __errbuf_size));
|
|
+ char *__restrict __errbuf, size_t __errbuf_size));
|
|
|
|
|
|
extern void regfree _RE_ARGS ((regex_t *__preg));
|
|
extern void regfree _RE_ARGS ((regex_t *__preg));
|
|
|
|
|
|
@@ -564,11 +578,3 @@ extern void regfree _RE_ARGS ((regex_t *__preg));
|
|
#endif /* C++ */
|
|
#endif /* C++ */
|
|
|
|
|
|
#endif /* regex.h */
|
|
#endif /* regex.h */
|
|
-
|
|
|
|
-/*
|
|
|
|
-Local variables:
|
|
|
|
-make-backup-files: t
|
|
|
|
-version-control: t
|
|
|
|
-trim-versions-without-asking: nil
|
|
|
|
-End:
|
|
|
|
-*/
|
|
|