Sun Jul 28 23:46:14 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[platform/upstream/linaro-glibc.git] / locale / programs / locale-spec.c
1 /* Handle special requests.
2 Copyright (C) 1996 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 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public License as
8 published by the Free Software Foundation; either version 2 of the
9 License, or (at your option) any later version.
10
11 The GNU C Library 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 GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with the GNU C Library; see the file COPYING.LIB.  If
18 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <wchar.h>
28
29 #include "localeinfo.h"
30
31
32 /* We provide support for some special names.  This helps debugging
33    and may be useful for advanced usage of the provided information
34    outside C.  */
35 void
36 locale_special (const char *name, int show_category_name,
37                 int show_keyword_name)
38 {
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] != (~((u_int32_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 #if 0
63                 /* We don't print the string.  This is only confusing
64                    because only the programs have to know the
65                    encoding.  The code is left in place because it
66                    shows how to get the information.  */
67                 {
68                   const wchar_t *wp;
69
70                   idx = __collate_element_hash[2 * cnt + 1];
71                   wp = &__collate_element_values[idx];
72                   while (*wp != L'\0')
73                     {
74                       /********************************************\
75                       |* XXX The element values are really wide   *|
76                       |* chars.  But we are currently not able to *|
77                       |* print these so fake here.                *|
78                       \********************************************/
79                       int ch = wctob (*wp++);
80                       if (ch != EOF)
81                         putchar (ch);
82                       else
83                         fputs ("<???>", stdout);
84                     }
85
86                   putchar ('"');
87                 }
88 #endif
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 1
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 }