Rizin
unix-like reverse engineering framework and cli tools
test.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <rz_regex.h>
3 
4 int _main(void) {
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 }
20 
21 static void test_or(void) {
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 }
33 
34 int main(int argc, char **argv) {
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 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
int _main(void)
Definition: test.c:4
static void test_or(void)
Definition: test.c:21
int main(int argc, char **argv)
Definition: test.c:34
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
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
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