|
| 1 | +#pragma once |
| 2 | + |
| 3 | +#inclib "tre" |
| 4 | + |
| 5 | +#include once "crt/sys/types.bi" |
| 6 | + |
| 7 | +#ifdef TRE_USE_SYSTEM_REGEX_H |
| 8 | + #include once "crt/regex.bi" |
| 9 | +#endif |
| 10 | + |
| 11 | +#include once "crt/wchar.bi" |
| 12 | + |
| 13 | +extern "C" |
| 14 | + |
| 15 | +const TRE_H = 1 |
| 16 | + |
| 17 | +#ifdef TRE_USE_SYSTEM_REGEX_H |
| 18 | + #define tre_regcomp regcomp |
| 19 | + #define tre_regexec regexec |
| 20 | + #define tre_regerror regerror |
| 21 | + #define tre_regfree regfree |
| 22 | + const REG_OK = 0 |
| 23 | + type reg_errcode_t as long |
| 24 | + const REG_LITERAL = &h1000 |
| 25 | +#else |
| 26 | + type regoff_t as long |
| 27 | + |
| 28 | + type regex_t |
| 29 | + re_nsub as uinteger |
| 30 | + value as any ptr |
| 31 | + end type |
| 32 | + |
| 33 | + type regmatch_t |
| 34 | + rm_so as regoff_t |
| 35 | + rm_eo as regoff_t |
| 36 | + end type |
| 37 | + |
| 38 | + type reg_errcode_t as long |
| 39 | + enum |
| 40 | + REG_OK = 0 |
| 41 | + REG_NOMATCH |
| 42 | + REG_BADPAT |
| 43 | + REG_ECOLLATE |
| 44 | + REG_ECTYPE |
| 45 | + REG_EESCAPE |
| 46 | + REG_ESUBREG |
| 47 | + REG_EBRACK |
| 48 | + REG_EPAREN |
| 49 | + REG_EBRACE |
| 50 | + REG_BADBR |
| 51 | + REG_ERANGE |
| 52 | + REG_ESPACE |
| 53 | + REG_BADRPT |
| 54 | + end enum |
| 55 | + |
| 56 | + const REG_EXTENDED = 1 |
| 57 | + #define REG_ICASE (REG_EXTENDED shl 1) |
| 58 | + #define REG_NEWLINE (REG_ICASE shl 1) |
| 59 | + #define REG_NOSUB (REG_NEWLINE shl 1) |
| 60 | +#endif |
| 61 | + |
| 62 | +const REG_BASIC = 0 |
| 63 | + |
| 64 | +#ifndef TRE_USE_SYSTEM_REGEX_H |
| 65 | + #define REG_LITERAL (REG_NOSUB shl 1) |
| 66 | +#endif |
| 67 | + |
| 68 | +#define REG_RIGHT_ASSOC (REG_LITERAL shl 1) |
| 69 | +#define REG_UNGREEDY (REG_RIGHT_ASSOC shl 1) |
| 70 | + |
| 71 | +#ifdef TRE_USE_SYSTEM_REGEX_H |
| 72 | + const REG_APPROX_MATCHER = &h1000 |
| 73 | +#else |
| 74 | + const REG_NOTBOL = 1 |
| 75 | + #define REG_NOTEOL (REG_NOTBOL shl 1) |
| 76 | + #define REG_APPROX_MATCHER (REG_NOTEOL shl 1) |
| 77 | +#endif |
| 78 | + |
| 79 | +#define REG_BACKTRACKING_MATCHER (REG_APPROX_MATCHER shl 1) |
| 80 | +#define REG_NOSPEC REG_LITERAL |
| 81 | +const RE_DUP_MAX = 255 |
| 82 | + |
| 83 | +#ifdef TRE_USE_SYSTEM_REGEX_H |
| 84 | + declare function regcomp(byval preg as regex_t ptr, byval regex as const zstring ptr, byval cflags as long) as long |
| 85 | + declare function regexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long |
| 86 | + declare function regerror(byval errcode as long, byval preg as const regex_t ptr, byval errbuf as zstring ptr, byval errbuf_size as uinteger) as uinteger |
| 87 | + declare sub regfree(byval preg as regex_t ptr) |
| 88 | +#else |
| 89 | + declare function tre_regcomp(byval preg as regex_t ptr, byval regex as const zstring ptr, byval cflags as long) as long |
| 90 | + declare function tre_regexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long |
| 91 | + declare function tre_regerror(byval errcode as long, byval preg as const regex_t ptr, byval errbuf as zstring ptr, byval errbuf_size as uinteger) as uinteger |
| 92 | + declare sub tre_regfree(byval preg as regex_t ptr) |
| 93 | +#endif |
| 94 | + |
| 95 | +declare function tre_regwcomp(byval preg as regex_t ptr, byval regex as const wstring ptr, byval cflags as long) as long |
| 96 | +declare function tre_regwexec(byval preg as const regex_t ptr, byval string as const wstring ptr, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long |
| 97 | +declare function tre_regncomp(byval preg as regex_t ptr, byval regex as const zstring ptr, byval len as uinteger, byval cflags as long) as long |
| 98 | +declare function tre_regnexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval len as uinteger, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long |
| 99 | +declare function tre_regwncomp(byval preg as regex_t ptr, byval regex as const wstring ptr, byval len as uinteger, byval cflags as long) as long |
| 100 | +declare function tre_regwnexec(byval preg as const regex_t ptr, byval string as const wstring ptr, byval len as uinteger, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long |
| 101 | + |
| 102 | +type regaparams_t |
| 103 | + cost_ins as long |
| 104 | + cost_del as long |
| 105 | + cost_subst as long |
| 106 | + max_cost as long |
| 107 | + max_ins as long |
| 108 | + max_del as long |
| 109 | + max_subst as long |
| 110 | + max_err as long |
| 111 | +end type |
| 112 | + |
| 113 | +type regamatch_t |
| 114 | + nmatch as uinteger |
| 115 | + pmatch as regmatch_t ptr |
| 116 | + cost as long |
| 117 | + num_ins as long |
| 118 | + num_del as long |
| 119 | + num_subst as long |
| 120 | +end type |
| 121 | + |
| 122 | +declare function tre_regaexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as long) as long |
| 123 | +declare function tre_reganexec(byval preg as const regex_t ptr, byval string as const zstring ptr, byval len as uinteger, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as long) as long |
| 124 | +declare function tre_regawexec(byval preg as const regex_t ptr, byval string as const wstring ptr, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as long) as long |
| 125 | +declare function tre_regawnexec(byval preg as const regex_t ptr, byval string as const wstring ptr, byval len as uinteger, byval match as regamatch_t ptr, byval params as regaparams_t, byval eflags as long) as long |
| 126 | +declare sub tre_regaparams_default(byval params as regaparams_t ptr) |
| 127 | +type tre_char_t as wstring |
| 128 | + |
| 129 | +type tre_str_source |
| 130 | + get_next_char as function(byval c as wstring ptr, byval pos_add as ulong ptr, byval context as any ptr) as long |
| 131 | + rewind as sub(byval pos as uinteger, byval context as any ptr) |
| 132 | + compare as function(byval pos1 as uinteger, byval pos2 as uinteger, byval len as uinteger, byval context as any ptr) as long |
| 133 | + context as any ptr |
| 134 | +end type |
| 135 | + |
| 136 | +declare function tre_reguexec(byval preg as const regex_t ptr, byval string as const tre_str_source ptr, byval nmatch as uinteger, byval pmatch as regmatch_t ptr, byval eflags as long) as long |
| 137 | +declare function tre_version() as zstring ptr |
| 138 | +declare function tre_config(byval query as long, byval result as any ptr) as long |
| 139 | + |
| 140 | +enum |
| 141 | + TRE_CONFIG_APPROX |
| 142 | + TRE_CONFIG_WCHAR |
| 143 | + TRE_CONFIG_MULTIBYTE |
| 144 | + TRE_CONFIG_SYSTEM_ABI |
| 145 | + TRE_CONFIG_VERSION |
| 146 | +end enum |
| 147 | + |
| 148 | +declare function tre_have_backrefs(byval preg as const regex_t ptr) as long |
| 149 | +declare function tre_have_approx(byval preg as const regex_t ptr) as long |
| 150 | + |
| 151 | +end extern |
0 commit comments