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