errno-h: document Haiku errors can’t be -1
[gnulib.git] / tests / test-dfa-match-aux.c
blob573d6e77c0d80d6b319d785d23c6a6159bd5a528
1 /* Auxiliary program to test a DFA code path that cannot be triggered
2 by grep or gawk.
3 Copyright 2014-2025 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 #include <config.h>
19 #include <locale.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <regex.h>
25 #include <dfa.h>
26 #include <localeinfo.h>
28 #include "binary-io.h"
30 _Noreturn void
31 dfaerror (char const *mesg)
33 printf ("dfaerror: %s\n", mesg);
34 exit (EXIT_FAILURE);
37 static int exit_status = EXIT_SUCCESS;
39 void
40 dfawarn (char const *mesg)
42 printf ("dfawarn: %s\n", mesg);
43 exit_status = EXIT_FAILURE;
46 int
47 main (int argc, char **argv)
49 struct dfa *dfa;
50 char *beg, *end, *p;
51 int allow_nl;
52 struct localeinfo localeinfo;
54 if (argc < 3)
55 exit (EXIT_FAILURE);
57 /* This test's fixture needs to compare this program's output with an expected
58 output. On native Windows, the CR-LF newlines would cause this comparison
59 to fail. But we don't want to postprocess this program's output. */
60 set_binary_mode (STDOUT_FILENO, O_BINARY);
62 setlocale (LC_ALL, "");
63 init_localeinfo (&localeinfo);
65 dfa = dfaalloc ();
66 dfasyntax (dfa, &localeinfo, RE_SYNTAX_EGREP | RE_NO_EMPTY_RANGES, 0);
67 dfacomp (argv[1], strlen (argv[1]), dfa, 0);
69 beg = argv[2];
70 end = argv[2] + strlen (argv[2]);
71 allow_nl = argc > 3 && atoi (argv[3]);
73 p = dfaexec (dfa, beg, end, allow_nl, NULL, NULL);
75 if (p != NULL)
76 printf ("%zd\n", p - beg);
78 exit (exit_status);