1 | #include <stdio.h> |
2 | #include <string.h> |
3 | #include <stdint.h> |
4 | #include <locale.h> |
5 | #include <locale/localeinfo.h> |
6 | |
7 | int |
8 | main (void) |
9 | { |
10 | int32_t table_size, idx, i, found; |
11 | const int32_t *symb_table; |
12 | const unsigned char *; |
13 | uint32_t nrules; |
14 | char *ca; |
15 | union locale_data_value u; |
16 | |
17 | ca = setlocale (LC_ALL, "da_DK.ISO-8859-1" ); |
18 | if (ca == NULL) |
19 | { |
20 | printf (format: "cannot set locale: %m\n" ); |
21 | return 1; |
22 | } |
23 | printf (format: "current locale : %s\n" , ca); |
24 | |
25 | u.string = nl_langinfo (_NL_COLLATE_NRULES); |
26 | nrules = u.word; |
27 | if (nrules == 0) |
28 | { |
29 | printf(format: "No rule\n" ); |
30 | return 1; |
31 | } |
32 | |
33 | u.string = nl_langinfo (_NL_COLLATE_SYMB_HASH_SIZEMB); |
34 | table_size = u.word; |
35 | symb_table = (const int32_t *) nl_langinfo (_NL_COLLATE_SYMB_TABLEMB); |
36 | extra = (const unsigned char *) nl_langinfo (_NL_COLLATE_SYMB_EXTRAMB); |
37 | |
38 | found = 0; |
39 | for (i = 0; i < table_size; ++i) |
40 | { |
41 | if (symb_table[2 * i] != 0) |
42 | { |
43 | char elem[256]; |
44 | idx = symb_table[2 * i + 1]; |
45 | strncpy (elem, (const char *) (extra + idx + 1), extra[idx]); |
46 | elem[extra[idx]] = '\0'; |
47 | printf (format: "Found a collating element: %s\n" , elem); |
48 | ++found; |
49 | } |
50 | } |
51 | if (found == 0) |
52 | { |
53 | printf (format: "No collating element!\n" ); |
54 | return 1; |
55 | } |
56 | else if (found != 6) |
57 | { |
58 | printf (format: "expected 6 collating elements, found %d\n" , found); |
59 | return 1; |
60 | } |
61 | |
62 | return 0; |
63 | } |
64 | |