2.5-18.1
[jlayton/glibc.git] / locale / programs / locale-spec.c
1 /* Handle special requests.
2    Copyright (C) 1996, 1997, 1999, 2005 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 version 2 as
8    published by the Free Software Foundation.
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, write to the Free Software Foundation,
17    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <stdio.h>
24 #include <string.h>
25 #include <wchar.h>
26
27 #include "localeinfo.h"
28
29
30 /* We provide support for some special names.  This helps debugging
31    and may be useful for advanced usage of the provided information
32    outside C.  */
33 void
34 locale_special (const char *name, int show_category_name,
35                 int show_keyword_name)
36 {
37 #if 0
38   /* "collate-elements": print collation elements of locale.  */
39   if (strcmp (name, "collate-elements") == 0)
40     {
41       size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_ELEM_HASH_SIZE);
42
43       if (show_category_name)
44         puts ("LC_COLLATE");
45       if (show_keyword_name)
46         fputs ("collate-elements=", stdout);
47
48       if (nelem != 0)
49         {
50           int first = 1;
51           size_t cnt;
52
53           for (cnt = 0; cnt < nelem; ++cnt)
54             if (__collate_element_hash[2 * cnt] != (~((u_int32_t) 0)))
55               {
56                 size_t idx = __collate_element_hash[2 * cnt];
57
58                 printf ("%s<%s>", first ? "" : ";",
59                         &__collate_element_strings[idx]);
60
61                 /* We don't print the string.  This is only confusing
62                    because only the programs have to know the
63                    encoding.  The code is left in place because it
64                    shows how to get the information.  */
65                 {
66                   const wchar_t *wp;
67
68                   idx = __collate_element_hash[2 * cnt + 1];
69                   wp = &__collate_element_values[idx];
70                   while (*wp != L'\0')
71                     {
72                       /********************************************\
73                       |* XXX The element values are really wide   *|
74                       |* chars.  But we are currently not able to *|
75                       |* print these so fake here.                *|
76                       \********************************************/
77                       int ch = wctob (*wp++);
78                       if (ch != EOF)
79                         putchar (ch);
80                       else
81                         fputs ("<??\?>", stdout);
82                     }
83
84                   putchar ('"');
85                 }
86                 first = 0;
87               }
88         }
89       putchar ('\n');
90       return;
91     }
92
93   if (strcmp (name, "collate-classes") == 0)
94     {
95       size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZE);
96       size_t cnt;
97       int first = 1;
98
99       if (show_category_name)
100         puts ("LC_COLLATE");
101       if (show_keyword_name)
102         fputs ("collate-classes=", stdout);
103
104       for (cnt = 0; cnt < nelem; ++cnt)
105         if (__collate_symbol_hash[2 * cnt] != 0xffffffff)
106           {
107             printf ("%s<%s>", first ? "" : ",",
108                     &__collate_symbol_strings[__collate_symbol_hash[2 * cnt]]);
109 #if 0
110             {
111               size_t idx = __collate_symbol_hash[2 * cnt + 1];
112               size_t cls;
113
114               putchar ('=');
115               for (cls = 0; cls < __collate_symbol_classes[idx]; ++cls)
116                 printf ("%s%d", cls == 0 ? "" : ":",
117                         __collate_symbol_classes[idx + 1 + cls]);
118             }
119 #endif
120             first = 0;
121           }
122       putchar ('\n');
123       return;
124     }
125 #endif
126 }