Updated to fedora-glibc-20070814T0725
[glibc.git] / posix / bug-regex22.c
blobc5bc94869ba8907bd7992f703056e237e66c2097
1 /* Test re.translate != NULL.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Jakub Jelinek <jakub@redhat.com>, 2004.
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
19 02111-1307 USA. */
21 #include <ctype.h>
22 #include <locale.h>
23 #include <regex.h>
24 #include <stdio.h>
25 #include <string.h>
27 int
28 main (void)
30 struct re_pattern_buffer re;
31 char trans[256];
32 int i, result = 0;
33 const char *s;
35 setlocale (LC_ALL, "de_DE.ISO-8859-1");
37 for (i = 0; i < 256; ++i)
38 trans[i] = tolower (i);
40 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
42 memset (&re, 0, sizeof (re));
43 re.translate = (unsigned char *) trans;
44 s = re_compile_pattern ("\\W", 2, &re);
46 if (s != NULL)
48 printf ("failed to compile pattern \"\\W\": %s\n", s);
49 result = 1;
51 else
53 int ret = re_search (&re, "abc.de", 6, 0, 6, NULL);
54 if (ret != 3)
56 printf ("1st re_search returned %d\n", ret);
57 result = 1;
60 ret = re_search (&re, "\xc4\xd6\xae\xf7", 4, 0, 4, NULL);
61 if (ret != 2)
63 printf ("2nd re_search returned %d\n", ret);
64 result = 1;
66 re.translate = NULL;
67 regfree (&re);
70 memset (&re, 0, sizeof (re));
71 re.translate = (unsigned char *) trans;
72 s = re_compile_pattern ("\\w", 2, &re);
74 if (s != NULL)
76 printf ("failed to compile pattern \"\\w\": %s\n", s);
77 result = 1;
79 else
81 int ret = re_search (&re, ".,!abc", 6, 0, 6, NULL);
82 if (ret != 3)
84 printf ("3rd re_search returned %d\n", ret);
85 result = 1;
88 ret = re_search (&re, "\xae\xf7\xc4\xd6", 4, 0, 4, NULL);
89 if (ret != 2)
91 printf ("4th re_search returned %d\n", ret);
92 result = 1;
94 re.translate = NULL;
95 regfree (&re);
98 memset (&re, 0, sizeof (re));
99 re.translate = (unsigned char *) trans;
100 s = re_compile_pattern ("[[:DIGIT:]]", 11, &re);
101 if (s == NULL)
103 printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n",
105 result = 1;
108 memset (&re, 0, sizeof (re));
109 re.translate = (unsigned char *) trans;
110 s = re_compile_pattern ("[[:DIGIT:]]", 2, &re);
111 if (s == NULL)
113 printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n",
115 result = 1;
118 return result;