#pragma prototyped
#ifndef _REGLIB_H
#define _REGLIB_H
#define REG_VERSION_EXEC 20020509L
#define REG_VERSION_MAP 20030916L
#define re_info env
#define alloc _reg_alloc
#define classfun _reg_classfun
#define drop _reg_drop
#define fatal _reg_fatal
#define state _reg_state
typedef struct regsubop_s
{
int op;
int off;
int len;
} regsubop_t;
#define _REG_SUB_PRIVATE_ \
char* re_cur; \
char* re_end; \
regsubop_t* re_ops; \
char re_rhs[1];
#include <ast.h>
#include <cdt.h>
#include <stk.h>
#include "regex.h"
#include <ctype.h>
#include <errno.h>
#define MBSIZE(p) ((ast.tmp_int=mbsize(p))>0?ast.tmp_int:1)
#undef RE_DUP_MAX
#define RE_DUP_MAX (INT_MAX/2-1)
#define RE_DUP_INF (RE_DUP_MAX+1)
#define BACK_REF_MAX 9
#define REG_COMP (REG_DELIMITED|REG_ESCAPE|REG_EXTENDED|REG_FIRST|REG_ICASE|REG_NOSUB|REG_NEWLINE|REG_SHELL|REG_AUGMENTED|REG_LEFT|REG_LITERAL|REG_MINIMAL|REG_NULL|REG_RIGHT|REG_LENIENT|REG_MUSTDELIM)
#define REG_EXEC (REG_ADVANCE|REG_INVERT|REG_NOTBOL|REG_NOTEOL|REG_STARTEND)
#define REX_NULL 0
#define REX_ALT 1
#define REX_ALT_CATCH 2
#define REX_BACK 3
#define REX_BEG 4
#define REX_BEG_STR 5
#define REX_BM 6
#define REX_CAT 7
#define REX_CLASS 8
#define REX_COLL_CLASS 9
#define REX_CONJ 10
#define REX_CONJ_LEFT 11
#define REX_CONJ_RIGHT 12
#define REX_DONE 13
#define REX_DOT 14
#define REX_END 15
#define REX_END_STR 16
#define REX_EXEC 17
#define REX_FIN_STR 18
#define REX_GROUP 19
#define REX_GROUP_CATCH 20
#define REX_GROUP_AHEAD 21
#define REX_GROUP_AHEAD_CATCH 22
#define REX_GROUP_AHEAD_NOT 23
#define REX_GROUP_BEHIND 24
#define REX_GROUP_BEHIND_CATCH 25
#define REX_GROUP_BEHIND_NOT 26
#define REX_GROUP_BEHIND_NOT_CATCH 27
#define REX_GROUP_COND 28
#define REX_GROUP_COND_CATCH 29
#define REX_GROUP_CUT 30
#define REX_GROUP_CUT_CATCH 31
#define REX_KMP 32
#define REX_NEG 33
#define REX_NEG_CATCH 34
#define REX_NEST 35
#define REX_ONECHAR 36
#define REX_REP 37
#define REX_REP_CATCH 38
#define REX_STRING 39
#define REX_TRIE 40
#define REX_WBEG 41
#define REX_WEND 42
#define REX_WORD 43
#define REX_WORD_NOT 44
#define T_META ((int)UCHAR_MAX+1)
#define T_STAR (T_META+0)
#define T_PLUS (T_META+1)
#define T_QUES (T_META+2)
#define T_BANG (T_META+3)
#define T_AT (T_META+4)
#define T_TILDE (T_META+5)
#define T_PERCENT (T_META+6)
#define T_LEFT (T_META+7)
#define T_OPEN (T_META+8)
#define T_CLOSE (T_OPEN+1)
#define T_RIGHT (T_OPEN+2)
#define T_CFLX (T_OPEN+3)
#define T_DOT (T_OPEN+4)
#define T_DOTSTAR (T_OPEN+5)
#define T_END (T_OPEN+6)
#define T_BAD (T_OPEN+7)
#define T_DOLL (T_OPEN+8)
#define T_BRA (T_OPEN+9)
#define T_BAR (T_OPEN+10)
#define T_AND (T_OPEN+11)
#define T_LT (T_OPEN+12)
#define T_GT (T_OPEN+13)
#define T_SLASHPLUS (T_OPEN+14)
#define T_GROUP (T_OPEN+15)
#define T_WORD (T_OPEN+16)
#define T_WORD_NOT (T_WORD+1)
#define T_BEG_STR (T_WORD+2)
#define T_END_STR (T_WORD+3)
#define T_FIN_STR (T_WORD+4)
#define T_ESCAPE (T_WORD+5)
#define T_ALNUM (T_WORD+6)
#define T_ALNUM_NOT (T_ALNUM+1)
#define T_DIGIT (T_ALNUM+2)
#define T_DIGIT_NOT (T_ALNUM+3)
#define T_SPACE (T_ALNUM+4)
#define T_SPACE_NOT (T_ALNUM+5)
#define T_BACK (T_ALNUM+6)
#define BRE 0
#define ERE 3
#define ARE 6
#define SRE 9
#define KRE 12
#define HIT SSIZE_MAX
#define bitclr(p,c) ((p)[((c)>>3)&037]&=(~(1<<((c)&07))))
#define bitset(p,c) ((p)[((c)>>3)&037]|=(1<<((c)&07)))
#define bittst(p,c) ((p)[((c)>>3)&037]&(1<<((c)&07)))
#define setadd(p,c) bitset((p)->bits,c)
#define setclr(p,c) bitclr((p)->bits,c)
#define settst(p,c) bittst((p)->bits,c)
#if _hdr_wchar && _lib_wctype && _lib_iswctype
#include <stdio.h>
#include <wchar.h>
#if _hdr_wctype
#include <wctype.h>
#endif
#if !defined(iswblank) && !_lib_iswblank
#define _need_iswblank 1
#define iswblank(x) _reg_iswblank(x)
extern int _reg_iswblank(wint_t);
#endif
#if !defined(towupper) && !_lib_towupper
#define towupper(x) toupper(x)
#endif
#if !defined(towlower) && !_lib_towlower
#define towlower(x) tolower(x)
#endif
#else
#undef _lib_wctype
#ifndef iswalnum
#define iswalnum(x) isalnum(x)
#endif
#ifndef iswalpha
#define iswalpha(x) isalpha(x)
#endif
#ifndef iswcntrl
#define iswcntrl(x) iscntrl(x)
#endif
#ifndef iswdigit
#define iswdigit(x) isdigit(x)
#endif
#ifndef iswgraph
#define iswgraph(x) isgraph(x)
#endif
#ifndef iswlower
#define iswlower(x) islower(x)
#endif
#ifndef iswprint
#define iswprint(x) isprint(x)
#endif
#ifndef iswpunct
#define iswpunct(x) ispunct(x)
#endif
#ifndef iswspace
#define iswspace(x) isspace(x)
#endif
#ifndef iswupper
#define iswupper(x) isupper(x)
#endif
#ifndef iswxdigit
#define iswxdigit(x) isxdigit(x)
#endif
#ifndef towlower
#define towlower(x) tolower(x)
#endif
#ifndef towupper
#define towupper(x) toupper(x)
#endif
#endif
#ifndef iswblank
#define iswblank(x) ((x)==' '||(x)=='\t')
#endif
#ifndef iswgraph
#define iswgraph(x) (iswprint(x)&&!iswblank(x))
#endif
#define isword(x) (isalnum(x)||(x)=='_')
#define COLL_KEY_MAX 15
#if COLL_KEY_MAX < MB_LEN_MAX
#undef COLL_KEY_MAX
#define COLL_KEY_MAX MB_LEN_MAX
#endif
typedef unsigned char Ckey_t[COLL_KEY_MAX+1];
#define COLL_end 0
#define COLL_call 1
#define COLL_char 2
#define COLL_range 3
#define COLL_range_lc 4
#define COLL_range_uc 5
typedef struct Celt_s
{
short typ;
short min;
short max;
regclass_t fun;
Ckey_t beg;
Ckey_t end;
} Celt_t;
typedef struct Stk_pos_s
{
off_t offset;
char* base;
} Stk_pos_t;
typedef struct Vector_s
{
Stk_t* stk;
char* vec;
int inc;
int siz;
int max;
int cur;
} Vector_t;
typedef struct Cond_s
{
unsigned char* beg;
struct Rex_s* next[2];
struct Rex_s* cont;
int yes;
} Cond_t;
typedef struct Conj_left_s
{
unsigned char* beg;
struct Rex_s* right;
struct Rex_s* cont;
} Conj_left_t;
typedef struct Conj_right_s
{
unsigned char* end;
struct Rex_s* cont;
} Conj_right_t;
typedef unsigned int Bm_mask_t;
typedef struct Bm_s
{
Bm_mask_t** mask;
size_t* skip;
size_t* fail;
size_t size;
ssize_t back;
ssize_t left;
ssize_t right;
size_t complete;
} Bm_t;
typedef struct String_s
{
int* fail;
unsigned char* base;
size_t size;
} String_t;
typedef struct Set_s
{
unsigned char bits[(UCHAR_MAX+1)/CHAR_BIT];
} Set_t;
typedef struct Collate_s
{
int invert;
Celt_t* elements;
} Collate_t;
typedef struct Binary_s
{
struct Rex_s* left;
struct Rex_s* right;
int serial;
} Binary_t;
typedef struct Group_s
{
int number;
int last;
int size;
int back;
regflags_t flags;
union
{
Binary_t binary;
struct Rex_s* rex;
} expr;
} Group_t;
typedef struct Exec_s
{
void* data;
const char* text;
size_t size;
} Exec_t;
#define REX_NEST_open 0x01
#define REX_NEST_close 0x02
#define REX_NEST_escape 0x04
#define REX_NEST_quote 0x08
#define REX_NEST_literal 0x10
#define REX_NEST_delimiter 0x20
#define REX_NEST_terminator 0x40
#define REX_NEST_separator 0x80
#define REX_NEST_SHIFT 8
typedef struct Nest_s
{
int primary;
unsigned short none;
unsigned short type[1];
} Nest_t;
typedef struct Alt_catch_s
{
struct Rex_s* cont;
} Alt_catch_t;
typedef struct Group_catch_s
{
struct Rex_s* cont;
regoff_t* eo;
} Group_catch_t;
typedef struct Behind_catch_s
{
struct Rex_s* cont;
unsigned char* beg;
unsigned char* end;
} Behind_catch_t;
typedef struct Neg_catch_s
{
unsigned char* beg;
unsigned char* index;
} Neg_catch_t;
typedef struct Rep_catch_s
{
struct Rex_s* cont;
struct Rex_s* ref;
unsigned char* beg;
int n;
} Rep_catch_t;
typedef struct Trie_node_s
{
unsigned char c;
unsigned char end;
struct Trie_node_s* son;
struct Trie_node_s* sib;
} Trie_node_t;
typedef struct Trie_s
{
Trie_node_t** root;
int min;
int max;
} Trie_t;
typedef struct Rex_s
{
unsigned char type;
unsigned char marked;
short serial;
regflags_t flags;
int explicit;
struct Rex_s* next;
int lo;
int hi;
unsigned char* map;
union
{
Alt_catch_t alt_catch;
Bm_t bm;
Behind_catch_t behind_catch;
Set_t* charclass;
Collate_t collate;
Cond_t cond_catch;
Conj_left_t conj_left;
Conj_right_t conj_right;
void* data;
Exec_t exec;
Group_t group;
Group_catch_t group_catch;
Neg_catch_t neg_catch;
Nest_t nest;
unsigned char onechar;
Rep_catch_t rep_catch;
String_t string;
Trie_t trie;
} re;
} Rex_t;
typedef struct reglib_s
{
struct Rex_s* rex;
regdisc_t* disc;
const regex_t* regex;
unsigned char* beg;
unsigned char* end;
Vector_t* pos;
Vector_t* bestpos;
regmatch_t* match;
regmatch_t* best;
Stk_pos_t stk;
size_t min;
size_t nsub;
regflags_t flags;
int error;
int explicit;
int leading;
int refs;
Rex_t done;
regstat_t stats;
unsigned char fold[UCHAR_MAX+1];
unsigned char hard;
unsigned char once;
unsigned char separate;
unsigned char stack;
unsigned char sub;
unsigned char test;
} Env_t;
typedef struct State_s
{
regmatch_t nomatch;
struct
{
unsigned char key;
short val[15];
} escape[52];
short* magic[UCHAR_MAX+1];
regdisc_t disc;
int fatal;
int initialized;
Dt_t* attrs;
Dt_t* names;
Dtdisc_t dtdisc;
} State_t;
extern State_t state;
extern void* alloc(regdisc_t*, void*, size_t);
extern regclass_t classfun(int);
extern void drop(regdisc_t*, Rex_t*);
extern int fatal(regdisc_t*, int, const char*);
#endif