Rizin
unix-like reverse engineering framework and cli tools
test.c File Reference
#include <stdio.h>
#include <rz_regex.h>

Go to the source code of this file.

Functions

int _main (void)
 
static void test_or (void)
 
int main (int argc, char **argv)
 

Function Documentation

◆ _main()

int _main ( void  )

Definition at line 4 of file test.c.

4  {
5  RzRegex rx;
6  int rc = rz_regex_comp(&rx, "^hi", RZ_REGEX_NOSUB);
7  if (rc) {
8  printf("error\n");
9 
10  } else {
11  rc = rz_regex_exec(&rx, "patata", 0, 0, 0);
12  printf("out = %d\n", rc);
13 
14  rc = rz_regex_exec(&rx, "hillow", 0, 0, 0);
15  printf("out = %d\n", rc);
16  }
17  rz_regex_free(&rx);
18  return 0;
19 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
RZ_API int rz_regex_exec(const RzRegex *preg, const char *string, size_t nmatch, RzRegexMatch __pmatch[], int eflags)
Definition: regexec.c:149
RZ_API int rz_regex_comp(RzRegex *, const char *, int)
Definition: regcomp.c:258
#define RZ_REGEX_NOSUB
Definition: rz_regex.h:25
RZ_API void rz_regex_free(RzRegex *)
Definition: regcomp.c:249

References printf(), rz_regex_comp(), rz_regex_exec(), rz_regex_free(), and RZ_REGEX_NOSUB.

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file test.c.

34  {
35  const char *needle = "^hi";
36  const char *haystack_1 = "patata";
37  const char *haystack_2 = "hillow";
38  if (argc > 3) {
39  needle = argv[1];
40  haystack_1 = argv[2];
41  haystack_2 = argv[3];
42  } else
43  printf("Using default values\n");
44  RzRegex *rx = rz_regex_new(needle, "");
45  if (rx) {
46  int res = rz_regex_exec(rx, haystack_1, 0, 0, 0);
47  printf("result (%s) = %d\n", haystack_1, res);
48  res = rz_regex_exec(rx, haystack_2, 0, 0, 0);
49  printf("result (%s) = %d\n", haystack_2, res);
50  rz_regex_free(rx);
51  } else
52  printf("oops, cannot compile regexp\n");
53  test_or();
54  return 0;
55 }
static void test_or(void)
Definition: test.c:21
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
RZ_API RzRegex * rz_regex_new(const char *pattern, const char *cflags)
Definition: regcomp.c:183

References argv, printf(), rz_regex_exec(), rz_regex_free(), rz_regex_new(), and test_or().

◆ test_or()

static void test_or ( void  )
static

Definition at line 21 of file test.c.

21  {
22  RzRegex *rx = rz_regex_new("(eax|ebx)", "e");
23  printf("result (%s) = %d\n", "mov eax", rz_regex_match("(eax|ebx)", "e", "mov eax"));
24  printf("result (%s) = %d\n", "mov ebx", rz_regex_match("(eax|ebx)", "e", "mov ebx"));
25  printf("result (%s) = %d\n", "mov eax", rz_regex_match("(eax|ebx)", "e", "mov ecx"));
26  printf("result (%s) = %d\n", "mov ebx", rz_regex_match("(eax|ecx)", "e", "mov ebx"));
27  printf("result (%s) = %d\n", "mov eax", rz_regex_check(rx, "mov eax"));
28  printf("result (%s) = %d\n", "mov ebx", rz_regex_check(rx, "mov ebx"));
29  printf("result (%s) = %d\n", "mov eax", rz_regex_exec(rx, "mov eax", 0, 0, 1));
30  printf("result (%s) = %d\n", "mov ebx", rz_regex_exec(rx, "mov ebx", 0, 0, 1));
31  rz_regex_free(rx);
32 }
RZ_API int rz_regex_match(const char *pattern, const char *flags, const char *text)
Definition: regcomp.c:142
RZ_API bool rz_regex_check(const RzRegex *rr, const char *str)
Definition: regexec.c:138

References printf(), rz_regex_check(), rz_regex_exec(), rz_regex_free(), rz_regex_match(), and rz_regex_new().

Referenced by main().