1 /* Regular expression tests.
2 Copyright (C) 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 #include <sys/types.h>
29 frob_escapes (char *src, int pattern)
33 for (dst = src; *src != '\0'; dst++, src++)
72 main (int argc, char **argv)
79 char *pattern, *string;
80 int flags = REG_EXTENDED;
89 fprintf (stderr, "Missing test filename\n");
93 f = fopen (argv[1], "r");
96 fprintf (stderr, "Couldn't open %s\n", argv[1]);
100 while ((len = getline (&line, &line_len, f)) > 0)
105 if (line[len - 1] == '\n')
118 if (strstr (line, "REG_BASIC"))
121 flags = REG_EXTENDED;
122 if (strstr (line, "REG_ICASE"))
124 if (strstr (line, "REG_NEWLINE"))
125 flags |= REG_NEWLINE;
127 if (strstr (line, "REG_NOTBOL"))
128 eflags |= REG_NOTBOL;
129 if (strstr (line, "REG_NOTEOL"))
130 eflags |= REG_NOTEOL;
134 pattern = line + strspn (line, " \t");
135 if (*pattern == '\0')
137 p = pattern + strcspn (pattern, " \t");
142 string = p + strspn (p, " \t");
148 p = strchr (string, '"');
155 p = string + strcspn (string, " \t");
164 frob_escapes (pattern, 1);
166 frob_escapes (string, 0);
168 n = regcomp (&re, pattern, flags);
174 regerror (n, &re, buf, sizeof (buf));
175 printf ("FAIL regcomp unexpectedly failed: %s\n",
181 else if (string == NULL)
184 puts ("FAIL regcomp unpexpectedly succeeded");
189 if (regexec (&re, string, 20, rm, eflags))
191 for (i = 0; i < 20; ++i)
200 for (i = 0; i < 20 && *p != '\0'; ++i)
204 rm_so = strtol (p, &q, 10);
209 rm_eo = strtol (p, &q, 10);
214 if (rm[i].rm_so != rm_so || rm[i].rm_eo != rm_eo)
216 printf ("FAIL rm[%d] %d..%d != expected %d..%d\n",
217 i, rm[i].rm_so, rm[i].rm_eo, rm_so, rm_eo);