1 /* Regular expression tests.
2 Copyright (C) 2003-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <sys/types.h>
27 frob_escapes (char *src, int pattern)
31 for (dst = src; *src != '\0'; dst++, src++)
70 main (int argc, char **argv)
77 char *pattern, *string;
78 int flags = REG_EXTENDED;
87 fprintf (stderr, "Missing test filename\n");
91 f = fopen (argv[1], "r");
94 fprintf (stderr, "Couldn't open %s\n", argv[1]);
98 while ((len = getline (&line, &line_len, f)) > 0)
103 if (line[len - 1] == '\n')
116 if (strstr (line, "REG_BASIC"))
119 flags = REG_EXTENDED;
120 if (strstr (line, "REG_ICASE"))
122 if (strstr (line, "REG_NEWLINE"))
123 flags |= REG_NEWLINE;
125 if (strstr (line, "REG_NOTBOL"))
126 eflags |= REG_NOTBOL;
127 if (strstr (line, "REG_NOTEOL"))
128 eflags |= REG_NOTEOL;
132 pattern = line + strspn (line, " \t");
133 if (*pattern == '\0')
135 p = pattern + strcspn (pattern, " \t");
140 string = p + strspn (p, " \t");
146 p = strchr (string, '"');
153 p = string + strcspn (string, " \t");
162 frob_escapes (pattern, 1);
164 frob_escapes (string, 0);
166 n = regcomp (&re, pattern, flags);
172 regerror (n, &re, buf, sizeof (buf));
173 printf ("FAIL regcomp unexpectedly failed: %s\n",
179 else if (string == NULL)
182 puts ("FAIL regcomp unpexpectedly succeeded");
187 if (regexec (&re, string, 20, rm, eflags))
189 for (i = 0; i < 20; ++i)
198 for (i = 0; i < 20 && *p != '\0'; ++i)
202 rm_so = strtol (p, &q, 10);
207 rm_eo = strtol (p, &q, 10);
212 if (rm[i].rm_so != rm_so || rm[i].rm_eo != rm_eo)
214 printf ("FAIL rm[%d] %d..%d != expected %d..%d\n",
215 i, rm[i].rm_so, rm[i].rm_eo, rm_so, rm_eo);