chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / posix / bug-regex1.c
1 /* Test case by Jim Meyering <jim@meyering.net>.  */
2 #include <locale.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <regex.h>
6 #include <wchar.h>
7 #include <gnu/option-groups.h>
8
9 int
10 main (void)
11 {
12   struct re_pattern_buffer regex;
13   struct re_registers regs;
14   const char *s;
15   int match;
16   int result = 0;
17
18   memset (&regex, '\0', sizeof (regex));
19
20   setlocale (LC_ALL, "de_DE.ISO-8859-1");
21 #if __OPTION_POSIX_WIDE_CHAR_DEVICE_IO
22   fwide (stdout, -1);
23 #endif
24
25   re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_DEBUG);
26
27   puts ("in C locale");
28   setlocale (LC_ALL, "C");
29   s = re_compile_pattern ("[anù]*n", 7, &regex);
30   if (s != NULL)
31     {
32       puts ("re_compile_pattern return non-NULL value");
33       result = 1;
34     }
35   else
36     {
37       match = re_match (&regex, "an", 2, 0, &regs);
38       if (match != 2)
39         {
40           printf ("re_match returned %d, expected 2\n", match);
41           result = 1;
42         }
43       else
44         puts (" -> OK");
45     }
46
47   puts ("in de_DE.ISO-8859-1 locale");
48   setlocale (LC_ALL, "de_DE.ISO-8859-1");
49   s = re_compile_pattern ("[anù]*n", 7, &regex);
50   if (s != NULL)
51     {
52       puts ("re_compile_pattern return non-NULL value");
53       result = 1;
54     }
55   else
56     {
57       match = re_match (&regex, "an", 2, 0, &regs);
58       if (match != 2)
59         {
60           printf ("re_match returned %d, expected 2\n", match);
61           result = 1;
62         }
63       else
64         puts (" -> OK");
65     }
66
67   return result;
68 }