VirtualBox

source: kBuild/vendor/grep/current/gnulib-tests/test-dfa-match-aux.c@ 3530

Last change on this file since 3530 was 3529, checked in by bird, 3 years ago

Imported grep 3.7 from grep-3.7.tar.gz (sha256: c22b0cf2d4f6bbe599c902387e8058990e1eee99aef333a203829e5fd3dbb342), applying minimal auto-props.

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1/* Auxiliary program to test a DFA code path that cannot be triggered
2 by grep or gawk.
3 Copyright 2014-2021 Free Software Foundation, Inc.
4
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.
9
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.
14
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. */
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
30dfaerror (char const *mesg)
31{
32 printf ("dfaerror: %s\n", mesg);
33 exit (EXIT_FAILURE);
34}
35
36static int exit_status = EXIT_SUCCESS;
37
38void
39dfawarn (char const *mesg)
40{
41 printf ("dfawarn: %s\n", mesg);
42 exit_status = EXIT_FAILURE;
43}
44
45int
46main (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}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette