Back to index

glibc  2.9
bug-regex1.c
Go to the documentation of this file.
00001 /* Test case by Jim Meyering <jim@meyering.net>.  */
00002 #include <locale.h>
00003 #include <stdio.h>
00004 #include <string.h>
00005 #include <regex.h>
00006 #include <wchar.h>
00007 
00008 int
00009 main (void)
00010 {
00011   struct re_pattern_buffer regex;
00012   struct re_registers regs;
00013   const char *s;
00014   int match;
00015   int result = 0;
00016 
00017   memset (&regex, '\0', sizeof (regex));
00018 
00019   setlocale (LC_ALL, "de_DE.ISO-8859-1");
00020   fwide (stdout, -1);
00021 
00022   re_set_syntax (RE_SYNTAX_POSIX_EGREP | RE_DEBUG);
00023 
00024   puts ("in C locale");
00025   setlocale (LC_ALL, "C");
00026   s = re_compile_pattern ("[aný]*n", 7, &regex);
00027   if (s != NULL)
00028     {
00029       puts ("re_compile_pattern return non-NULL value");
00030       result = 1;
00031     }
00032   else
00033     {
00034       match = re_match (&regex, "an", 2, 0, &regs);
00035       if (match != 2)
00036        {
00037          printf ("re_match returned %d, expected 2\n", match);
00038          result = 1;
00039        }
00040       else
00041        puts (" -> OK");
00042     }
00043 
00044   puts ("in de_DE.ISO-8859-1 locale");
00045   setlocale (LC_ALL, "de_DE.ISO-8859-1");
00046   s = re_compile_pattern ("[aný]*n", 7, &regex);
00047   if (s != NULL)
00048     {
00049       puts ("re_compile_pattern return non-NULL value");
00050       result = 1;
00051     }
00052   else
00053     {
00054       match = re_match (&regex, "an", 2, 0, &regs);
00055       if (match != 2)
00056        {
00057          printf ("re_match returned %d, expected 2\n", match);
00058          result = 1;
00059        }
00060       else
00061        puts (" -> OK");
00062     }
00063 
00064   return result;
00065 }