6 #include "libre9/re9.h"
9 int main (int argc
, char *argv
[]) {
12 re9_prog_prepared_t
*prp
;
13 const char *errmsg
, *restr
;
14 int flg
= RE9_FLAG_NONUTF8
;
16 if (argc
> 1 && strcmp(argv
[1], "-d") == 0) {
17 flg
|= RE9_FLAG_DUMPPRG
;
23 if (argc
< 3) { fprintf(stderr
, "usage: %s regexp string...\n", argv
[0]); exit(1); }
26 if (restr
[0] == '/' && strchr(restr
+1, '/')) {
27 for (++restr
; *restr
!= '/'; ++restr
) {
29 case 'i': flg
|= RE9_FLAG_CASEINSENS
; break;
30 case 'u': flg
&= ~RE9_FLAG_NONUTF8
; break;
32 fprintf(stderr
, "invalid regexp option: '%c'\n", *restr
);
38 p
= re9_compile(restr
, flg
, &errmsg
);
39 if (p
== NULL
) { fprintf(stderr
, "FATAL: invalid regexp '%s': %s\n", argv
[1], errmsg
); exit(2); }
40 if ((prp
= re9_prepare(p
)) == NULL
) { fprintf(stderr
, "FATAL: can't prepare regexp!\n"); exit(2); }
42 for (int f
= 2; f
< argc
; ++f
) {
44 if (f
> 2) printf("===============================\n");
45 printf("(%d) %s VIA %s\n", re9_nsub(p
), argv
[f
], argv
[1]);
46 if ((res
= re9_prepared_execute(prp
, flg
, argv
[f
], rs
, 10)) > 0) {
47 for (int c
= 0; c
< 10; ++c
) {
48 if (rs
[c
].sp
!= NULL
&& rs
[c
].ep
!= NULL
) {
49 printf(" %d:(%d,%d) <", c
, rs
[c
].sp
-argv
[f
], rs
[c
].ep
-argv
[f
]);
50 fwrite(rs
[c
].sp
, rs
[c
].ep
-rs
[c
].sp
, 1, stdout
);
55 printf("OUT OF MEMORY!");
60 re9_prepared_free(prp
);