37 #include <sys/types.h>
116 #define PEEK() (*p->next)
117 #define PEEK2() (*(p->next + 1))
118 #define MORE() (p->next < p->end)
119 #define MORE2() (p->next + 1 < p->end)
120 #define SEE(c) (MORE() && PEEK() == (c))
121 #define SEETWO(a, b) (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
122 #define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
123 #define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
124 #define NEXT() (p->next++)
125 #define NEXT2() (p->next += 2)
126 #define NEXTn(n) (p->next += (n))
127 #define GETNEXT() (*p->next++)
128 #define SETERROR(e) seterr(p, (e))
129 #define REQUIRE(co, e) (void)((co) || SETERROR(e))
130 #define MUSTSEE(c, e) (REQUIRE(MORE() && PEEK() == (c), e))
131 #define MUSTEAT(c, e) (REQUIRE(MORE() && GETNEXT() == (c), e))
132 #define MUSTNOTSEE(c, e) (REQUIRE(!MORE() || PEEK() != (c), e))
133 #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
134 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE() - (pos) + 1, pos)
135 #define AHEAD(pos) dofwd(p, pos, HERE() - (pos))
136 #define ASTERN(sop, pos) EMIT(sop, HERE() - (pos))
137 #define HERE() (p->slen)
138 #define THERE() (p->slen - 1)
139 #define THERETHERE() (p->slen - 2)
140 #define DROP(n) (p->slen -= (n))
147 eprintf(
"FAIL TO COMPILE %s\n", pattern);
160 size_t entry_len = 0;
163 eprintf(
"Failed to compile regexp: %s\n", pattern);
202 if (strchr(
f,
'e')) {
205 if (strchr(
f,
'i')) {
208 if (strchr(
f,
's')) {
211 if (strchr(
f,
'n')) {
214 if (strchr(
f,
'N')) {
217 if (strchr(
f,
'p')) {
220 if (strchr(
f,
'd')) {
265 #define GOODFLAGS(f) (f)
267 #define GOODFLAGS(f) ((f) & ~RZ_REGEX_DUMP)
279 len = strlen((
char *)pattern);
302 if (
p->ssize <
len) {
320 p->next = (
char *)pattern;
321 p->end =
p->next +
len;
340 g->categories = &
g->catspace[-(CHAR_MIN)];
368 if (
g->iflags &
BAD) {
391 while (
MORE() && (
c =
PEEK()) !=
'|' &&
c != stop) {
442 p->pbegin[subno] =
HERE();
449 p->pend[subno] =
HERE();
450 if (!
p->pend[subno]) {
508 if (!(
c ==
'*' ||
c ==
'+' ||
c ==
'?' ||
563 if (!(
c ==
'*' ||
c ==
'+' ||
c ==
'?' ||
630 #define BACKSL (1 << CHAR_BIT)
660 p->pbegin[subno] =
HERE();
668 p->pend[subno] =
HERE();
669 if (!
p->pend[subno]) {
690 if (
p->pend[
i] != 0) {
691 if (i <= p->
g->nsub) {
695 (void)
dupl(
p,
p->pbegin[
i] + 1,
p->pend[
i]);
718 }
else if (
EATTWO(
'\\',
'{')) {
738 }
else if (
c ==
'$') {
773 if (
p->next + 5 <
p->end && strncmp(
p->next,
"[:<:]]", 6) == 0) {
778 if (
p->next + 5 <
p->end && strncmp(
p->next,
"[:>:]]", 6) == 0) {
794 }
else if (
EAT(
'-')) {
814 for (
i =
p->g->csetsize - 1;
i >= 0;
i--) {
829 for (
i =
p->g->csetsize - 1;
i >= 0;
i--) {
946 while ((
c = *u++) !=
'\0') {
949 for (u = cp->
multis; *u !=
'\0'; u += strlen(u) + 1) {
1039 char *oldnext =
p->next;
1040 char *oldend =
p->end;
1046 p->end = bracket + 2;
1051 if (
p->next == bracket + 2) {
1063 cat_t *cap =
p->g->categories;
1070 cap[ch] =
p->g->ncategories++;
1077 char *oldnext =
p->next;
1078 char *oldend =
p->end;
1079 char bracket[16] = { 0 };
1080 char digits[3] = { 0 };
1087 c = (char)strtol(digits,
NULL, 16);
1117 p->end = bracket +
num;
1121 if (
p->next == bracket +
num) {
1134 char *oldnext =
p->next;
1135 char *oldend =
p->end;
1139 p->end = bracket + 3;
1145 if (
p->next == bracket + 3) {
1163 #define REP(f, t) ((f)*8 + (t))
1164 #define MAP(n) (((n) <= 1) ? (n) : ((n) == INTFINITY) ? INF \
1168 if (
p->error != 0) {
1204 if (copy ==
finish + 4) {
1231 if (
p->error == 0) {
1243 int no =
p->g->ncsets++;
1247 size_t css = (
size_t)
p->g->csetsize;
1250 if (no >=
p->ncsalloc) {
1270 p->g->setbits = ptr;
1272 for (
i = 0;
i < no;
i++) {
1273 p->g->sets[
i].ptr =
p->g->setbits + css * (
i /
CHAR_BIT);
1276 (void)
memset((
char *)
p->g->setbits + (
nbytes - css), 0, css);
1279 if (!
p->g->sets || !
p->g->setbits) {
1283 cs = &
p->g->sets[no];
1284 cs->ptr =
p->g->setbits + css * ((no) /
CHAR_BIT);
1305 cset *top = &
p->g->sets[
p->g->ncsets];
1306 size_t css = (
size_t)
p->g->csetsize;
1308 for (
i = 0;
i < css;
i++) {
1311 if (
cs == top - 1) {
1329 cset *top = &
p->g->sets[
p->g->ncsets];
1331 size_t css = (
size_t)
p->g->csetsize;
1334 for (cs2 = &
p->g->sets[0]; cs2 < top; cs2++) {
1335 if (cs2->
hash ==
h && cs2 !=
cs) {
1337 for (
i = 0;
i < css;
i++) {
1353 return ((
int)(
cs -
p->g->sets));
1362 size_t css = (
size_t)
p->g->csetsize;
1364 for (
i = 0;
i < css;
i++) {
1377 size_t css = (
size_t)
p->g->csetsize;
1380 for (
i = 0;
i < css;
i++) {
1392 size_t oldend =
cs->smultis;
1395 cs->smultis += strlen(cp) + 1;
1407 STRLCPY(
cs->multis + oldend - 1, cp,
cs->smultis - oldend + 1);
1442 unsigned uc = (
ut8)
c;
1444 for (
i = 0, col =
g->setbits; i < ncols; i++, col += g->csetsize) {
1460 unsigned uc1 = (
ut8)
c1;
1461 unsigned uc2 = (
ut8)
c2;
1463 for (
i = 0, col =
g->setbits; i < ncols; i++, col += g->csetsize) {
1464 if (col[uc1] != col[uc2]) {
1482 if (!
p ||
p->error != 0 || !cats) {
1486 for (
c = CHAR_MIN;
c <= CHAR_MAX;
c++) {
1488 cat =
g->ncategories++;
1490 for (
c2 =
c + 1;
c2 <= CHAR_MAX;
c2++) {
1515 if (
p->ssize >=
p->slen +
len) {
1516 (void)
memcpy((
char *)(
p->strip +
p->slen),
1517 (
char *)(
p->strip +
start), (
size_t)
len *
sizeof(
sop));
1535 if (
p->error != 0) {
1543 if (
p->slen >=
p->ssize) {
1546 if (
p->slen <
p->ssize) {
1548 p->strip[
p->slen++] =
SOP(
op, opnd);
1563 if (
p->error != 0) {
1569 if (
HERE() != sn + 1) {
1577 if (
p->pbegin[
i] >=
pos) {
1580 if (
p->pend[
i] >=
pos) {
1586 memmove((
char *)&
p->strip[
pos + 1], (
char *)&
p->strip[
pos],
1597 if (
p->error != 0) {
1613 if (
p->ssize >=
size) {
1631 g->nstates =
p->slen;
1635 g->strip =
p->strip;
1659 if (
p->error != 0) {
1665 start = scan =
g->strip + 1;
1671 newstart = scan - 1;
1694 if (newlen >
g->mlen) {
1708 g->must =
malloc((
size_t)
g->mlen + 1);
1715 for (
i =
g->mlen;
i > 0;
i--) {
1719 if (cp < g->must +
g->mlen) {
1720 *cp++ = (char)
OPND(
s);
1723 if (cp ==
g->must +
g->mlen) {
1738 if (
p->error != 0) {
1742 scan =
g->strip + 1;
1750 if (plusnest > maxnest) {
1757 if (plusnest != 0) {
static unsigned invert(unsigned x)
static bool finish(void *user)
static RzILOpEffect * cset(cs_insn *insn)
lsl lsr asr ror lsl lsr asr ror lsl lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror c1
lsl lsr asr ror lsl lsr asr ror lsl lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror c2
static struct cclass cclasses[]
static struct cname cnames[]
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void nbytes
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void start
#define OP(v, w, x, y, z)
unsigned char match[65280+2]
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
void * realloc(void *ptr, size_t size)
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
static void mccase(struct parse *, cset *)
static int samesets(struct re_guts *, int, int)
static void stripsnug(struct parse *, struct re_guts *)
RZ_API int rz_regex_flags(const char *f)
static char p_b_coll_elem(struct parse *, int)
static void mcadd(struct parse *, cset *, char *)
static void p_ere_exp(struct parse *)
static sopno dupl(struct parse *, sopno, sopno)
static char othercase(int)
static void p_b_cclass(struct parse *, cset *)
static void doemit(struct parse *, sop, size_t)
RZ_API RzRegex * rz_regex_new(const char *pattern, const char *flags)
static void nonnewline(struct parse *)
static void p_b_eclass(struct parse *, cset *)
static int freezeset(struct parse *, cset *)
RZ_API void rz_regex_free(RzRegex *preg)
static void ordinary(struct parse *, int)
static void categorize(struct parse *, struct re_guts *)
static void p_str(struct parse *)
static void bothcases(struct parse *, int)
static void repeat(struct parse *, sopno, int, int)
static void p_b_term(struct parse *, cset *)
static int isinsets(struct re_guts *, int)
RZ_API RzList * rz_regex_get_match_list(const char *pattern, const char *flags, const char *text)
static void p_bre(struct parse *, int, int)
static int nch(struct parse *, cset *)
static void doinsert(struct parse *, sop, size_t, sopno)
static sopno pluscount(struct parse *, struct re_guts *)
static void p_ere(struct parse *, int)
RZ_API int rz_regex_comp(RzRegex *preg, const char *pattern, int cflags)
static char p_b_symbol(struct parse *)
static void findmust(struct parse *, struct re_guts *)
static cset * allocset(struct parse *)
RZ_API int rz_regex_match(const char *pattern, const char *flags, const char *text)
static void p_bracket(struct parse *)
static void dofwd(struct parse *, sopno, sop)
static int p_count(struct parse *)
static void enlarge(struct parse *, sopno)
RZ_API void rz_regex_fini(RzRegex *preg)
static int p_simp_re(struct parse *, int)
static void freeset(struct parse *, cset *)
static void mcinvert(struct parse *, cset *)
static int seterr(struct parse *, int)
static void special(struct parse *, int)
static int firstch(struct parse *, cset *)
#define rz_return_val_if_fail(expr, val)
RZ_API int rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch __pmatch[], int eflags)
#define RZ_REGEX_STARTEND
#define RZ_REGEX_EXTENDED
#define RZ_REGEX_ECOLLATE
RZ_API size_t rz_str_ncpy(char *dst, const char *src, size_t n)
Secure string copy with null terminator.
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
static struct sockaddr static addrlen static backlog const void static flags void flags
if(dbg->bits==RZ_SYS_BITS_64)