This source file includes following definitions.
- dfaerror
- dfawarn
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21 #include <locale.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <regex.h>
26 #include <dfa.h>
27 #include <localeinfo.h>
28
29 _Noreturn void
30 dfaerror (char const *mesg)
31 {
32 printf ("dfaerror: %s\n", mesg);
33 exit (EXIT_FAILURE);
34 }
35
36 static int exit_status = EXIT_SUCCESS;
37
38 void
39 dfawarn (char const *mesg)
40 {
41 printf ("dfawarn: %s\n", mesg);
42 exit_status = EXIT_FAILURE;
43 }
44
45 int
46 main (int argc, char **argv)
47 {
48 struct dfa *dfa;
49 char *beg, *end, *p;
50 int allow_nl;
51 struct localeinfo localeinfo;
52
53 if (argc < 3)
54 exit (EXIT_FAILURE);
55
56 setlocale (LC_ALL, "");
57 init_localeinfo (&localeinfo);
58
59 dfa = dfaalloc ();
60 dfasyntax (dfa, &localeinfo, RE_SYNTAX_EGREP | RE_NO_EMPTY_RANGES, 0);
61 dfacomp (argv[1], strlen (argv[1]), dfa, 0);
62
63 beg = argv[2];
64 end = argv[2] + strlen (argv[2]);
65 allow_nl = argc > 3 && atoi (argv[3]);
66
67 p = dfaexec (dfa, beg, end, allow_nl, NULL, NULL);
68
69 if (p != NULL)
70 printf ("%zd\n", p - beg);
71
72 exit (exit_status);
73 }