usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-dfa-match-aux.c
blob112f9dd91879b804d521b7a5ea1e07b6c460085d
1 /* Auxiliary program to test a DFA code path that cannot be triggered
2 by grep or gawk.
3 Copyright 2014-2024 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, write to the Free Software
17 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
18 02110-1301, USA. */
20 #include <config.h>
21 #include <locale.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <regex.h>
27 #include <dfa.h>
28 #include <localeinfo.h>
30 #include "binary-io.h"
32 _Noreturn void
33 dfaerror (char const *mesg)
35 printf ("dfaerror: %s\n", mesg);
36 exit (EXIT_FAILURE);
39 static int exit_status = EXIT_SUCCESS;
41 void
42 dfawarn (char const *mesg)
44 printf ("dfawarn: %s\n", mesg);
45 exit_status = EXIT_FAILURE;
48 int
49 main (int argc, char **argv)
51 struct dfa *dfa;
52 char *beg, *end, *p;
53 int allow_nl;
54 struct localeinfo localeinfo;
56 if (argc < 3)
57 exit (EXIT_FAILURE);
59 /* This test's fixture needs to compare this program's output with an expected
60 output. On native Windows, the CR-LF newlines would cause this comparison
61 to fail. But we don't want to postprocess this program's output. */
62 set_binary_mode (STDOUT_FILENO, O_BINARY);
64 setlocale (LC_ALL, "");
65 init_localeinfo (&localeinfo);
67 dfa = dfaalloc ();
68 dfasyntax (dfa, &localeinfo, RE_SYNTAX_EGREP | RE_NO_EMPTY_RANGES, 0);
69 dfacomp (argv[1], strlen (argv[1]), dfa, 0);
71 beg = argv[2];
72 end = argv[2] + strlen (argv[2]);
73 allow_nl = argc > 3 && atoi (argv[3]);
75 p = dfaexec (dfa, beg, end, allow_nl, NULL, NULL);
77 if (p != NULL)
78 printf ("%zd\n", p - beg);
80 exit (exit_status);