1 /* Handle special requests.
2 Copyright (C) 1996-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 2 of the License, or
8 (at your option) any later version.
9
10 This program 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
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <https://www.gnu.org/licenses/>. */
17
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <error.h>
23 #include <libintl.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <wchar.h>
27
28 #include "localeinfo.h"
29
30
31 /* We provide support for some special names. This helps debugging
32 and may be useful for advanced usage of the provided information
33 outside C. */
34 void
locale_special(const char * name,int show_category_name,int show_keyword_name)35 locale_special (const char *name, int show_category_name,
36 int show_keyword_name)
37 {
38 #if 0
39 /* "collate-elements": print collation elements of locale. */
40 if (strcmp (name, "collate-elements") == 0)
41 {
42 size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_ELEM_HASH_SIZE);
43
44 if (show_category_name)
45 puts ("LC_COLLATE");
46 if (show_keyword_name)
47 fputs ("collate-elements=", stdout);
48
49 if (nelem != 0)
50 {
51 int first = 1;
52 size_t cnt;
53
54 for (cnt = 0; cnt < nelem; ++cnt)
55 if (__collate_element_hash[2 * cnt] != (~((uint32_t) 0)))
56 {
57 size_t idx = __collate_element_hash[2 * cnt];
58
59 printf ("%s<%s>", first ? "" : ";",
60 &__collate_element_strings[idx]);
61
62 /* We don't print the string. This is only confusing
63 because only the programs have to know the
64 encoding. The code is left in place because it
65 shows how to get the information. */
66 {
67 const wchar_t *wp;
68
69 idx = __collate_element_hash[2 * cnt + 1];
70 wp = &__collate_element_values[idx];
71 while (*wp != L'\0')
72 {
73 /********************************************\
74 |* XXX The element values are really wide *|
75 |* chars. But we are currently not able to *|
76 |* print these so fake here. *|
77 \********************************************/
78 int ch = wctob (*wp++);
79 if (ch != EOF)
80 putchar (ch);
81 else
82 fputs ("<??\?>", stdout);
83 }
84
85 putchar ('"');
86 }
87 first = 0;
88 }
89 }
90 putchar ('\n');
91 return;
92 }
93
94 if (strcmp (name, "collate-classes") == 0)
95 {
96 size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZE);
97 size_t cnt;
98 int first = 1;
99
100 if (show_category_name)
101 puts ("LC_COLLATE");
102 if (show_keyword_name)
103 fputs ("collate-classes=", stdout);
104
105 for (cnt = 0; cnt < nelem; ++cnt)
106 if (__collate_symbol_hash[2 * cnt] != 0xffffffff)
107 {
108 printf ("%s<%s>", first ? "" : ",",
109 &__collate_symbol_strings[__collate_symbol_hash[2 * cnt]]);
110 #if 0
111 {
112 size_t idx = __collate_symbol_hash[2 * cnt + 1];
113 size_t cls;
114
115 putchar ('=');
116 for (cls = 0; cls < __collate_symbol_classes[idx]; ++cls)
117 printf ("%s%d", cls == 0 ? "" : ":",
118 __collate_symbol_classes[idx + 1 + cls]);
119 }
120 #endif
121 first = 0;
122 }
123 putchar ('\n');
124 return;
125 }
126 #endif
127
128 /* If nothing matches, fail. */
129 error (1, 0, gettext ("unknown name \"%s\""), name);
130 }
131