6 #include "libre9/re9.h"
9 static const char text
[] = "test\0for zero";
12 static void dump_matches (const char *str
, const re9_sub_t
*rs
, int ms
) {
13 for (int c
= 0; c
< 10; ++c
) {
14 if (rs
[c
].sp
!= NULL
&& rs
[c
].ep
!= NULL
) {
15 fprintf(stdout
, " %d:(%d,%d) <", c
, rs
[c
].sp
-str
, rs
[c
].ep
-str
);
16 fwrite(rs
[c
].sp
, rs
[c
].ep
-rs
[c
].sp
, 1, stdout
);
24 int main (int argc
, char *argv
[]) {
26 re9_prog_t
*p0
, *p1
, *p2
;
29 p0
= re9_compile("t\\zfor", RE9_FLAG_NONUTF8
, &errmsg
);
30 if (p0
== NULL
) { fprintf(stderr
, "FATAL: invalid regexp: %s\n", errmsg
); exit(2); }
31 p1
= re9_compile("\\zfor", RE9_FLAG_NONUTF8
, &errmsg
);
32 if (p1
== NULL
) { fprintf(stderr
, "FATAL: invalid regexp: %s\n", errmsg
); exit(2); }
33 p2
= re9_compile("[a\\z]for", RE9_FLAG_NONUTF8
, &errmsg
);
34 if (p1
== NULL
) { fprintf(stderr
, "FATAL: invalid regexp: %s\n", errmsg
); exit(2); }
36 printf("=============================== (%u)\n", sizeof(text
));
38 rs
[0].ep
= text
+sizeof(text
);
39 if (re9_execute(p0
, RE9_FLAG_NONUTF8
|RE9_FLAG_MT0_RANGE
, text
, rs
, 10) > 0) dump_matches(text
, rs
, 10);
40 printf("=============================== (%u)\n", sizeof(text
));
42 rs
[0].ep
= text
+sizeof(text
);
43 if (re9_execute(p1
, RE9_FLAG_NONUTF8
|RE9_FLAG_MT0_RANGE
, text
, rs
, 10) > 0) dump_matches(text
, rs
, 10);
44 printf("=============================== (%u)\n", sizeof(text
));
46 rs
[0].ep
= text
+sizeof(text
);
47 if (re9_execute(p2
, RE9_FLAG_NONUTF8
|RE9_FLAG_MT0_RANGE
, text
, rs
, 10) > 0) dump_matches(text
, rs
, 10);