1 #ifndef R2_REGEX_H 2 #define R2_REGEX_H 3 4 #include <r_types.h> 5 #include <r_list.h> 6 #include <sys/types.h> 7 8 typedef struct r_regex_t { 9 int re_magic; 10 size_t re_nsub; /* number of parenthesized subexpressions */ 11 const char *re_endp; /* end pointer for R_REGEX_PEND */ 12 struct re_guts *re_g; /* none of your business :-) */ 13 int re_flags; 14 } RRegex; 15 16 typedef struct r_regmatch_t { 17 st64 rm_so; /* start of match */ 18 st64 rm_eo; /* end of match */ 19 } RRegexMatch; 20 21 /* regcomp() flags */ 22 #define R_REGEX_BASIC 0000 23 #define R_REGEX_EXTENDED 0001 24 #define R_REGEX_ICASE 0002 25 #define R_REGEX_NOSUB 0004 26 #define R_REGEX_NEWLINE 0010 27 #define R_REGEX_NOSPEC 0020 28 #define R_REGEX_PEND 0040 29 #define R_REGEX_DUMP 0200 30 31 /* regerror() flags */ 32 #define R_REGEX_ENOSYS (-1) /* Reserved */ 33 #define R_REGEX_NOMATCH 1 34 #define R_REGEX_BADPAT 2 35 #define R_REGEX_ECOLLATE 3 36 #define R_REGEX_ECTYPE 4 37 #define R_REGEX_EESCAPE 5 38 #define R_REGEX_ESUBREG 6 39 #define R_REGEX_EBRACK 7 40 #define R_REGEX_EPAREN 8 41 #define R_REGEX_EBRACE 9 42 #define R_REGEX_BADBR 10 43 #define R_REGEX_ERANGE 11 44 #define R_REGEX_ESPACE 12 45 #define R_REGEX_BADRPT 13 46 #define R_REGEX_EMPTY 14 47 #define R_REGEX_ASSERT 15 48 #define R_REGEX_INVARG 16 49 #define R_REGEX_ILLSEQ 17 50 #define R_REGEX_ATOI 255 /* convert name to number (!) */ 51 #define R_REGEX_ITOA 0400 /* convert number to name (!) */ 52 53 /* regexec() flags */ 54 #define R_REGEX_NOTBOL 00001 55 #define R_REGEX_NOTEOL 00002 56 #define R_REGEX_STARTEND 00004 57 #define R_REGEX_TRACE 00400 /* tracing of execution */ 58 #define R_REGEX_LARGE 01000 /* force large representation */ 59 #define R_REGEX_BACKR 02000 /* force use of backref code */ 60 61 R_API int r_regex_run(const char *pattern, const char *flags, const char *text); 62 R_API bool r_regex_match(const char *pattern, const char *flags, const char *text); 63 64 R_API int r_regex_flags(const char *flags); 65 66 // lifecicle 67 R_API RRegex *r_regex_new(const char *pattern, const char *cflags); 68 R_API void r_regex_free(RRegex *); 69 R_API int r_regex_init(RRegex*, const char *pattern, int flags); 70 R_API void r_regex_fini(RRegex *); 71 // checks 72 R_API bool r_regex_check(const RRegex *rr, const char *str); 73 R_API int r_regex_exec(const RRegex *preg, const char *string, size_t nmatch, RRegexMatch __pmatch[], int eflags); 74 R_API RList *r_regex_match_list(RRegex *rx, const char *text); 75 R_API char *r_regex_error(RRegex *rx, int errcode); 76 // R_API size_t r_regex_error(int, const RRegex*, char *, size_t); 77 78 #endif /* !_REGEX_H_ */ 79