]> git.ipfire.org Git - thirdparty/glibc.git/blame - locale/programs/locale-spec.c
Update copyright dates with scripts/update-copyrights
[thirdparty/glibc.git] / locale / programs / locale-spec.c
CommitLineData
036cc82f 1/* Handle special requests.
6d7e8eda 2 Copyright (C) 1996-2023 Free Software Foundation, Inc.
c84142e8 3 This file is part of the GNU C Library.
c84142e8 4
43bc8ac6 5 This program is free software; you can redistribute it and/or modify
2e2efe65
RM
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.
c84142e8 9
43bc8ac6 10 This program is distributed in the hope that it will be useful,
c84142e8 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
43bc8ac6
UD
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
c84142e8 14
43bc8ac6 15 You should have received a copy of the GNU General Public License
5a82c748 16 along with this program; if not, see <https://www.gnu.org/licenses/>. */
036cc82f
RM
17
18#ifdef HAVE_CONFIG_H
19# include <config.h>
20#endif
21
2c5c07f5
AS
22#include <error.h>
23#include <libintl.h>
036cc82f
RM
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. */
34void
35locale_special (const char *name, int show_category_name,
36 int show_keyword_name)
37{
b06c53e7 38#if 0
036cc82f
RM
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)
d9fee042 55 if (__collate_element_hash[2 * cnt] != (~((uint32_t) 0)))
036cc82f
RM
56 {
57 size_t idx = __collate_element_hash[2 * cnt];
58
59 printf ("%s<%s>", first ? "" : ";",
60 &__collate_element_strings[idx]);
61
036cc82f
RM
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
b1418d8f 82 fputs ("<??\?>", stdout);
036cc82f
RM
83 }
84
85 putchar ('"');
86 }
036cc82f
RM
87 first = 0;
88 }
89 }
90 putchar ('\n');
91 return;
92 }
ce7a5ef4
RM
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]]);
4b10dd6c 110#if 0
ce7a5ef4
RM
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 }
b06c53e7 126#endif
9d076f21
UD
127
128 /* If nothing matches, fail. */
129 error (1, 0, gettext ("unknown name \"%s\""), name);
036cc82f 130}