Back to index

glibc  2.9
bug-regex5.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <locale.h>
00004 #include <locale/localeinfo.h>
00005 
00006 int
00007 main (void)
00008 {
00009   int32_t table_size, idx, i, found;
00010   const int32_t *symb_table;
00011   const unsigned char *extra;
00012   uint32_t nrules;
00013   char *ca;
00014   union locale_data_value u;
00015 
00016   ca = setlocale (LC_ALL, "da_DK.ISO-8859-1");
00017   if (ca == NULL)
00018     {
00019       printf ("cannot set locale: %m\n");
00020       return 1;
00021     }
00022   printf ("current locale : %s\n", ca);
00023 
00024   u.string = nl_langinfo (_NL_COLLATE_NRULES);
00025   nrules = u.word;
00026   if (nrules == 0)
00027     {
00028       printf("No rule\n");
00029       return 1;
00030     }
00031 
00032   u.string = nl_langinfo (_NL_COLLATE_SYMB_HASH_SIZEMB);
00033   table_size = u.word;
00034   symb_table = (const int32_t *) nl_langinfo (_NL_COLLATE_SYMB_TABLEMB);
00035   extra = (const unsigned char *) nl_langinfo (_NL_COLLATE_SYMB_EXTRAMB);
00036 
00037   found = 0;
00038   for (i = 0; i < table_size; ++i)
00039     {
00040       if (symb_table[2 * i] != 0)
00041        {
00042          char elem[256];
00043          idx = symb_table[2 * i + 1];
00044          strncpy (elem, (const char *) (extra + idx + 1), extra[idx]);
00045          elem[extra[idx]] = '\0';
00046          printf ("Found a collating element: %s\n", elem);
00047          ++found;
00048        }
00049     }
00050   if (found == 0)
00051     {
00052       printf ("No collating element!\n");
00053       return 1;
00054     }
00055   else if (found != 4)
00056     {
00057       printf ("expected 4 collating elements, found %d\n", found);
00058       return 1;
00059     }
00060 
00061   return 0;
00062 }