build-many-glibcs.py: Add openrisc hard float glibc variant
[glibc.git] / posix / bug-regex22.c
blob38caa05622579ee08e46212e1097d01b1d52be49
1 /* Test re.translate != NULL.
2 Copyright (C) 2004-2024 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 <ctype.h>
20 #include <locale.h>
21 #include <regex.h>
22 #include <stdio.h>
23 #include <string.h>
25 int
26 main (void)
28 struct re_pattern_buffer re;
29 char trans[256];
30 int i, result = 0;
31 const char *s;
33 setlocale (LC_ALL, "de_DE.ISO-8859-1");
35 for (i = 0; i < 256; ++i)
36 trans[i] = tolower (i);
38 re_set_syntax (RE_SYNTAX_POSIX_EGREP);
40 memset (&re, 0, sizeof (re));
41 re.translate = (unsigned char *) trans;
42 s = re_compile_pattern ("\\W", 2, &re);
44 if (s != NULL)
46 printf ("failed to compile pattern \"\\W\": %s\n", s);
47 result = 1;
49 else
51 int ret = re_search (&re, "abc.de", 6, 0, 6, NULL);
52 if (ret != 3)
54 printf ("1st re_search returned %d\n", ret);
55 result = 1;
58 ret = re_search (&re, "\xc4\xd6\xae\xf7", 4, 0, 4, NULL);
59 if (ret != 2)
61 printf ("2nd re_search returned %d\n", ret);
62 result = 1;
64 re.translate = NULL;
65 regfree (&re);
68 memset (&re, 0, sizeof (re));
69 re.translate = (unsigned char *) trans;
70 s = re_compile_pattern ("\\w", 2, &re);
72 if (s != NULL)
74 printf ("failed to compile pattern \"\\w\": %s\n", s);
75 result = 1;
77 else
79 int ret = re_search (&re, ".,!abc", 6, 0, 6, NULL);
80 if (ret != 3)
82 printf ("3rd re_search returned %d\n", ret);
83 result = 1;
86 ret = re_search (&re, "\xae\xf7\xc4\xd6", 4, 0, 4, NULL);
87 if (ret != 2)
89 printf ("4th re_search returned %d\n", ret);
90 result = 1;
92 re.translate = NULL;
93 regfree (&re);
96 memset (&re, 0, sizeof (re));
97 re.translate = (unsigned char *) trans;
98 s = re_compile_pattern ("[[:DIGIT:]]", 11, &re);
99 if (s == NULL)
101 puts ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: "
102 "length 11");
103 result = 1;
106 memset (&re, 0, sizeof (re));
107 re.translate = (unsigned char *) trans;
108 s = re_compile_pattern ("[[:DIGIT:]]", 2, &re);
109 if (s == NULL)
111 puts ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: "
112 "length 2");
113 result = 1;
116 return result;