Rizin
unix-like reverse engineering framework and cli tools
regexec.c File Reference
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include <rz_regex.h>
#include "utils.h"
#include "regex2.h"
#include "engine.c"

Go to the source code of this file.

Macros

#define states1   long long /* for later use in regexec() decision */
 
#define states   states1
 
#define CLEAR(v)   ((v) = 0)
 
#define SET0(v, n)   ((v) &= ~((unsigned states)1 << (n)))
 
#define SET1(v, n)   ((v) |= (unsigned states)1 << (n))
 
#define ISSET(v, n)   (((v) & ((unsigned states)1 << (n))) != 0)
 
#define ASSIGN(d, s)   ((d) = (s))
 
#define EQ(a, b)   ((a) == (b))
 
#define STATEVARS   states dummy /* dummy version */
 
#define STATESETUP(m, n)   /* nothing */
 
#define STATETEARDOWN(m)   /* nothing */
 
#define SETUP(v)   ((v) = 0)
 
#define onestate   states
 
#define INIT(o, n)   ((o) = (unsigned states)1 << (n))
 
#define INC(o)   ((o) <<= 1)
 
#define ISSTATEIN(v, o)   (((v) & (o)) != 0)
 
#define FWD(dst, src, n)   ((dst) |= ((unsigned states)(src) & (here)) << (n))
 
#define BACK(dst, src, n)   ((dst) |= ((unsigned states)(src) & (here)) >> (n))
 
#define ISSETBACK(v, n)   (((v) & ((unsigned states)here >> (n))) != 0)
 
#define SNAMES   /* engine.c looks after details */
 
#define states   char *
 
#define CLEAR(v)   memset(v, 0, m->g->nstates)
 
#define SET0(v, n)   ((v)[n] = 0)
 
#define SET1(v, n)   ((v)[n] = 1)
 
#define ISSET(v, n)   ((v)[n])
 
#define ASSIGN(d, s)   memcpy(d, s, m->g->nstates)
 
#define EQ(a, b)   (memcmp(a, b, m->g->nstates) == 0)
 
#define STATEVARS
 
#define STATESETUP(m, nv)
 
#define STATETEARDOWN(m)    { free((m)->space); }
 
#define SETUP(v)   ((v) = &m->space[m->vn++ * m->g->nstates])
 
#define onestate   states1
 
#define INIT(o, n)   ((o) = (n))
 
#define INC(o)   ((o)++)
 
#define ISSTATEIN(v, o)   ((v)[o])
 
#define FWD(dst, src, n)   ((dst)[here + (n)] |= (src)[here])
 
#define BACK(dst, src, n)   ((dst)[here - (n)] |= (src)[here])
 
#define ISSETBACK(v, n)   ((v)[here - (n)])
 
#define LNAMES   /* flag */
 
#define GOODFLAGS(f)   ((f) & (RZ_REGEX_NOTBOL | RZ_REGEX_NOTEOL | RZ_REGEX_STARTEND | RZ_REGEX_LARGE))
 

Functions

RZ_API bool rz_regex_check (const RzRegex *rr, const char *str)
 
RZ_API int rz_regex_exec (const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch pmatch[], int eflags)
 

Macro Definition Documentation

◆ ASSIGN [1/2]

#define ASSIGN (   d,
  s 
)    ((d) = (s))

Definition at line 109 of file regexec.c.

◆ ASSIGN [2/2]

#define ASSIGN (   d,
  s 
)    memcpy(d, s, m->g->nstates)

Definition at line 109 of file regexec.c.

◆ BACK [1/2]

#define BACK (   dst,
  src,
  n 
)    ((dst) |= ((unsigned states)(src) & (here)) >> (n))

Definition at line 131 of file regexec.c.

◆ BACK [2/2]

#define BACK (   dst,
  src,
  n 
)    ((dst)[here - (n)] |= (src)[here])

Definition at line 131 of file regexec.c.

◆ CLEAR [1/2]

#define CLEAR (   v)    ((v) = 0)

Definition at line 105 of file regexec.c.

◆ CLEAR [2/2]

#define CLEAR (   v)    memset(v, 0, m->g->nstates)

Definition at line 105 of file regexec.c.

◆ EQ [1/2]

#define EQ (   a,
  b 
)    ((a) == (b))

Definition at line 110 of file regexec.c.

◆ EQ [2/2]

#define EQ (   a,
  b 
)    (memcmp(a, b, m->g->nstates) == 0)

Definition at line 110 of file regexec.c.

◆ FWD [1/2]

#define FWD (   dst,
  src,
  n 
)    ((dst) |= ((unsigned states)(src) & (here)) << (n))

Definition at line 130 of file regexec.c.

◆ FWD [2/2]

#define FWD (   dst,
  src,
  n 
)    ((dst)[here + (n)] |= (src)[here])

Definition at line 130 of file regexec.c.

◆ GOODFLAGS

#define GOODFLAGS (   f)    ((f) & (RZ_REGEX_NOTBOL | RZ_REGEX_NOTEOL | RZ_REGEX_STARTEND | RZ_REGEX_LARGE))

◆ INC [1/2]

#define INC (   o)    ((o) <<= 1)

Definition at line 126 of file regexec.c.

◆ INC [2/2]

#define INC (   o)    ((o)++)

Definition at line 126 of file regexec.c.

◆ INIT [1/2]

#define INIT (   o,
  n 
)    ((o) = (unsigned states)1 << (n))

Definition at line 125 of file regexec.c.

◆ INIT [2/2]

#define INIT (   o,
  n 
)    ((o) = (n))

Definition at line 125 of file regexec.c.

◆ ISSET [1/2]

#define ISSET (   v,
  n 
)    (((v) & ((unsigned states)1 << (n))) != 0)

Definition at line 108 of file regexec.c.

◆ ISSET [2/2]

#define ISSET (   v,
  n 
)    ((v)[n])

Definition at line 108 of file regexec.c.

◆ ISSETBACK [1/2]

#define ISSETBACK (   v,
  n 
)    (((v) & ((unsigned states)here >> (n))) != 0)

Definition at line 132 of file regexec.c.

◆ ISSETBACK [2/2]

#define ISSETBACK (   v,
  n 
)    ((v)[here - (n)])

Definition at line 132 of file regexec.c.

◆ ISSTATEIN [1/2]

#define ISSTATEIN (   v,
 
)    (((v) & (o)) != 0)

Definition at line 127 of file regexec.c.

◆ ISSTATEIN [2/2]

#define ISSTATEIN (   v,
 
)    ((v)[o])

Definition at line 127 of file regexec.c.

◆ LNAMES

#define LNAMES   /* flag */

Definition at line 134 of file regexec.c.

◆ onestate [1/2]

#define onestate   states

Definition at line 124 of file regexec.c.

◆ onestate [2/2]

#define onestate   states1

Definition at line 124 of file regexec.c.

◆ SET0 [1/2]

#define SET0 (   v,
  n 
)    ((v) &= ~((unsigned states)1 << (n)))

Definition at line 106 of file regexec.c.

◆ SET0 [2/2]

#define SET0 (   v,
  n 
)    ((v)[n] = 0)

Definition at line 106 of file regexec.c.

◆ SET1 [1/2]

#define SET1 (   v,
  n 
)    ((v) |= (unsigned states)1 << (n))

Definition at line 107 of file regexec.c.

◆ SET1 [2/2]

#define SET1 (   v,
  n 
)    ((v)[n] = 1)

Definition at line 107 of file regexec.c.

◆ SETUP [1/2]

#define SETUP (   v)    ((v) = 0)

Definition at line 123 of file regexec.c.

◆ SETUP [2/2]

#define SETUP (   v)    ((v) = &m->space[m->vn++ * m->g->nstates])

Definition at line 123 of file regexec.c.

◆ SNAMES

#define SNAMES   /* engine.c looks after details */

Definition at line 78 of file regexec.c.

◆ states [1/2]

#define states   states1

Definition at line 104 of file regexec.c.

◆ states [2/2]

#define states   char *

Definition at line 104 of file regexec.c.

◆ states1

#define states1   long long /* for later use in regexec() decision */

Definition at line 56 of file regexec.c.

◆ STATESETUP [1/2]

#define STATESETUP (   m,
  n 
)    /* nothing */

Definition at line 114 of file regexec.c.

◆ STATESETUP [2/2]

#define STATESETUP (   m,
  nv 
)
Value:
{ \
(m)->space = malloc((nv) * (m)->g->nstates); \
if (!(m)->space) \
return RZ_REGEX_ESPACE; \
(m)->vn = 0; \
}
struct @667 g
void * malloc(size_t size)
Definition: malloc.c:123
#define RZ_REGEX_ESPACE
Definition: rz_regex.h:44

Definition at line 114 of file regexec.c.

◆ STATETEARDOWN [1/2]

#define STATETEARDOWN (   m)    /* nothing */

Definition at line 121 of file regexec.c.

◆ STATETEARDOWN [2/2]

#define STATETEARDOWN (   m)     { free((m)->space); }

Definition at line 121 of file regexec.c.

◆ STATEVARS [1/2]

#define STATEVARS   states dummy /* dummy version */

Definition at line 111 of file regexec.c.

◆ STATEVARS [2/2]

#define STATEVARS
Value:
states1 vn; \
char *space
#define states1
Definition: regexec.c:56

Definition at line 111 of file regexec.c.

Function Documentation

◆ rz_regex_check()

RZ_API bool rz_regex_check ( const RzRegex rr,
const char *  str 
)

Definition at line 138 of file regexec.c.

138  {
139  return rz_regex_exec(rr, str, 0, NULL, rr->re_flags);
140 }
#define NULL
Definition: cris-opc.c:27
RZ_API int rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch pmatch[], int eflags)
Definition: regexec.c:149
int re_flags
Definition: rz_regex.h:13

References NULL, rz_regex_t::re_flags, rz_regex_exec(), and cmd_descs_generate::str.

Referenced by test_or().

◆ rz_regex_exec()

RZ_API int rz_regex_exec ( const RzRegex preg,
const char *  string,
size_t  nmatch,
RzRegexMatch  pmatch[],
int  eflags 
)

Definition at line 149 of file regexec.c.

150  {
151  struct re_guts *g;
152 #ifdef REDEBUG
153 #define GOODFLAGS(f) (f)
154 #else
155 #define GOODFLAGS(f) ((f) & (RZ_REGEX_NOTBOL | RZ_REGEX_NOTEOL | RZ_REGEX_STARTEND | RZ_REGEX_LARGE))
156 #endif
157  if (!preg || !string) {
158  return RZ_REGEX_ASSERT;
159  }
160 
161  g = preg->re_g;
162  if (preg->re_magic != MAGIC1 || g->magic != MAGIC2) {
163  return (RZ_REGEX_BADPAT);
164  }
165  if (g->iflags & BAD) { /* backstop for no-debug case */
166  return (RZ_REGEX_BADPAT);
167  }
168  eflags = GOODFLAGS(eflags);
169  if (g->nstates <= CHAR_BIT * sizeof(states1) && !(eflags & RZ_REGEX_LARGE)) {
170  return (smatcher(g, (char *)string, nmatch, pmatch, eflags));
171  } else {
172  return (lmatcher(g, (char *)string, nmatch, pmatch, eflags));
173  }
174 }
#define CHAR_BIT
Definition: readbits.h:99
#define MAGIC1
Definition: regex2.h:41
#define MAGIC2
Definition: regex2.h:128
#define BAD
Definition: regex2.h:141
#define GOODFLAGS(f)
#define RZ_REGEX_BADPAT
Definition: rz_regex.h:34
#define RZ_REGEX_LARGE
Definition: rz_regex.h:58
#define RZ_REGEX_ASSERT
Definition: rz_regex.h:47
int re_magic
Definition: rz_regex.h:9
struct re_guts * re_g
Definition: rz_regex.h:12

References BAD, CHAR_BIT, g, GOODFLAGS, MAGIC1, MAGIC2, rz_regex_t::re_g, rz_regex_t::re_magic, RZ_REGEX_ASSERT, RZ_REGEX_BADPAT, RZ_REGEX_LARGE, and states1.

Referenced by _main(), check_fmt(), find_e_opts(), magiccheck(), main(), pager_all_matches(), rz_asm_tokenize_asm_regex(), rz_core_asm_strsearch(), rz_regex_check(), rz_regex_get_match_list(), rz_regex_match(), rz_search_regexp_update(), str_split_list_common_regex(), and test_or().