123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- #ifndef _REGEX_H
- #define _REGEX_H 1
- #include <sys/types.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS
- # include <stddef.h>
- #endif
- typedef long int s_reg_t;
- typedef unsigned long int active_reg_t;
- typedef unsigned long int reg_syntax_t;
- #define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
- #define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
- #define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
- #define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
- #define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
- #define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
- #define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
- #define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
- #define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
- #define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
- #define RE_LIMITED_OPS (RE_INTERVALS << 1)
- #define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
- #define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
- #define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
- #define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
- #define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
- #define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
- #define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
- #define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
- #define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
- #define RE_DEBUG (RE_NO_GNU_OPS << 1)
- #define RE_INVALID_INTERVAL_ORD (RE_DEBUG << 1)
- #define RE_ICASE (RE_INVALID_INTERVAL_ORD << 1)
- #define RE_CARET_ANCHORS_HERE (RE_ICASE << 1)
- #define RE_CONTEXT_INVALID_DUP (RE_CARET_ANCHORS_HERE << 1)
- #define RE_NO_SUB (RE_CONTEXT_INVALID_DUP << 1)
- extern reg_syntax_t re_syntax_options;
- #define RE_SYNTAX_EMACS 0
- #define RE_SYNTAX_AWK \
- (RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DOT_NOT_NULL \
- | RE_NO_BK_PARENS | RE_NO_BK_REFS \
- | RE_NO_BK_VBAR | RE_NO_EMPTY_RANGES \
- | RE_DOT_NEWLINE | RE_CONTEXT_INDEP_ANCHORS \
- | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
- #define RE_SYNTAX_GNU_AWK \
- ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG) \
- & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS \
- | RE_CONTEXT_INVALID_OPS ))
- #define RE_SYNTAX_POSIX_AWK \
- (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS \
- | RE_INTERVALS | RE_NO_GNU_OPS)
- #define RE_SYNTAX_GREP \
- (RE_BK_PLUS_QM | RE_CHAR_CLASSES \
- | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS \
- | RE_NEWLINE_ALT)
- #define RE_SYNTAX_EGREP \
- (RE_CHAR_CLASSES | RE_CONTEXT_INDEP_ANCHORS \
- | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE \
- | RE_NEWLINE_ALT | RE_NO_BK_PARENS \
- | RE_NO_BK_VBAR)
- #define RE_SYNTAX_POSIX_EGREP \
- (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES \
- | RE_INVALID_INTERVAL_ORD)
- #define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
- #define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
- #define _RE_SYNTAX_POSIX_COMMON \
- (RE_CHAR_CLASSES | RE_DOT_NEWLINE | RE_DOT_NOT_NULL \
- | RE_INTERVALS | RE_NO_EMPTY_RANGES)
- #define RE_SYNTAX_POSIX_BASIC \
- (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM | RE_CONTEXT_INVALID_DUP)
- #define RE_SYNTAX_POSIX_MINIMAL_BASIC \
- (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
- #define RE_SYNTAX_POSIX_EXTENDED \
- (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
- | RE_CONTEXT_INDEP_OPS | RE_NO_BK_BRACES \
- | RE_NO_BK_PARENS | RE_NO_BK_VBAR \
- | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
- #define RE_SYNTAX_POSIX_MINIMAL_EXTENDED \
- (_RE_SYNTAX_POSIX_COMMON | RE_CONTEXT_INDEP_ANCHORS \
- | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES \
- | RE_NO_BK_PARENS | RE_NO_BK_REFS \
- | RE_NO_BK_VBAR | RE_UNMATCHED_RIGHT_PAREN_ORD)
- #ifdef RE_DUP_MAX
- # undef RE_DUP_MAX
- #endif
- #define RE_DUP_MAX (0x7fff)
- #define REG_EXTENDED 1
- #define REG_ICASE (REG_EXTENDED << 1)
- #define REG_NEWLINE (REG_ICASE << 1)
- #define REG_NOSUB (REG_NEWLINE << 1)
- #define REG_NOTBOL 1
- #define REG_NOTEOL (1 << 1)
- #define REG_STARTEND (1 << 2)
- typedef enum
- {
- #ifdef _XOPEN_SOURCE
- REG_ENOSYS = -1,
- #endif
- REG_NOERROR = 0,
- REG_NOMATCH,
-
- REG_BADPAT,
- REG_ECOLLATE,
- REG_ECTYPE,
- REG_EESCAPE,
- REG_ESUBREG,
- REG_EBRACK,
- REG_EPAREN,
- REG_EBRACE,
- REG_BADBR,
- REG_ERANGE,
- REG_ESPACE,
- REG_BADRPT,
-
- REG_EEND,
- REG_ESIZE,
- REG_ERPAREN
- } reg_errcode_t;
- #ifndef RE_TRANSLATE_TYPE
- # define RE_TRANSLATE_TYPE unsigned char *
- #endif
- struct re_pattern_buffer
- {
-
- unsigned char *buffer;
-
- unsigned long int allocated;
-
- unsigned long int used;
-
- reg_syntax_t syntax;
-
- char *fastmap;
-
- RE_TRANSLATE_TYPE translate;
-
- size_t re_nsub;
-
- unsigned can_be_null : 1;
-
- #define REGS_UNALLOCATED 0
- #define REGS_REALLOCATE 1
- #define REGS_FIXED 2
- unsigned regs_allocated : 2;
-
- unsigned fastmap_accurate : 1;
-
- unsigned no_sub : 1;
-
- unsigned not_bol : 1;
-
- unsigned not_eol : 1;
-
- unsigned newline_anchor : 1;
- };
- typedef struct re_pattern_buffer regex_t;
- typedef int regoff_t;
- struct re_registers
- {
- unsigned num_regs;
- regoff_t *start;
- regoff_t *end;
- };
- #ifndef RE_NREGS
- # define RE_NREGS 30
- #endif
- typedef struct
- {
- regoff_t rm_so;
- regoff_t rm_eo;
- } regmatch_t;
- #if __STDC__
- # define _RE_ARGS(args) args
- #else
- # define _RE_ARGS(args) ()
- #endif
- extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t __syntax));
- extern const char *re_compile_pattern _RE_ARGS ((const char *__pattern, size_t __length,
- struct re_pattern_buffer *__buffer));
- extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *__buffer));
- extern int re_search _RE_ARGS ((struct re_pattern_buffer *__buffer, const char *__string,
- int __length, int __start, int __range,
- struct re_registers *__regs));
- extern int re_search_2 _RE_ARGS ((struct re_pattern_buffer *__buffer,
- const char *__string1, int __length1,
- const char *__string2, int __length2, int __start,
- int __range, struct re_registers *__regs, int __stop));
- extern int re_match _RE_ARGS ((struct re_pattern_buffer *__buffer, const char *__string,
- int __length, int __start, struct re_registers *__regs));
- extern int re_match_2 _RE_ARGS ((struct re_pattern_buffer *__buffer,
- const char *__string1, int __length1,
- const char *__string2, int __length2, int __start,
- struct re_registers *__regs, int __stop));
- extern void re_set_registers _RE_ARGS ((struct re_pattern_buffer *__buffer,
- struct re_registers *__regs,
- unsigned int __num_regs,
- regoff_t *__starts, regoff_t *__ends));
- #if defined _REGEX_RE_COMP || defined _LIBC
- # ifndef _CRAY
- extern char *re_comp _RE_ARGS ((const char *));
- extern int re_exec _RE_ARGS ((const char *));
- # endif
- #endif
- #ifndef __restrict
- # if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
- # if defined restrict || 199901L <= __STDC_VERSION__
- # define __restrict restrict
- # else
- # define __restrict
- # endif
- # endif
- #endif
- #ifndef __restrict_arr
- # if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
- # define __restrict_arr __restrict
- # else
- # define __restrict_arr
- # endif
- #endif
- extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
- const char *__restrict __pattern,
- int __cflags));
- extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
- const char *__restrict __string, size_t __nmatch,
- regmatch_t __pmatch[__restrict_arr],
- int __eflags));
- extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__restrict __preg,
- char *__restrict __errbuf, size_t __errbuf_size));
- extern void regfree _RE_ARGS ((regex_t *__preg));
- #ifdef __cplusplus
- }
- #endif
- #endif
|