Back to index

glibc  2.9
locale-spec.c
Go to the documentation of this file.
00001 /* Handle special requests.
00002    Copyright (C) 1996, 1997, 1999, 2005 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published
00008    by the Free Software Foundation; version 2 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software Foundation,
00018    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
00019 
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023 
00024 #include <stdio.h>
00025 #include <string.h>
00026 #include <wchar.h>
00027 
00028 #include "localeinfo.h"
00029 
00030 
00031 /* We provide support for some special names.  This helps debugging
00032    and may be useful for advanced usage of the provided information
00033    outside C.  */
00034 void
00035 locale_special (const char *name, int show_category_name,
00036               int show_keyword_name)
00037 {
00038 #if 0
00039   /* "collate-elements": print collation elements of locale.  */
00040   if (strcmp (name, "collate-elements") == 0)
00041     {
00042       size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_ELEM_HASH_SIZE);
00043 
00044       if (show_category_name)
00045        puts ("LC_COLLATE");
00046       if (show_keyword_name)
00047        fputs ("collate-elements=", stdout);
00048 
00049       if (nelem != 0)
00050        {
00051          int first = 1;
00052          size_t cnt;
00053 
00054          for (cnt = 0; cnt < nelem; ++cnt)
00055            if (__collate_element_hash[2 * cnt] != (~((u_int32_t) 0)))
00056              {
00057               size_t idx = __collate_element_hash[2 * cnt];
00058 
00059               printf ("%s<%s>", first ? "" : ";",
00060                      &__collate_element_strings[idx]);
00061 
00062               /* We don't print the string.  This is only confusing
00063                  because only the programs have to know the
00064                  encoding.  The code is left in place because it
00065                  shows how to get the information.  */
00066               {
00067                 const wchar_t *wp;
00068 
00069                 idx = __collate_element_hash[2 * cnt + 1];
00070                 wp = &__collate_element_values[idx];
00071                 while (*wp != L'\0')
00072                   {
00073                     /********************************************\
00074                     |* XXX The element values are really wide    *|
00075                     |* chars.  But we are currently not able to *|
00076                     |* print these so fake here.          *|
00077                     \********************************************/
00078                     int ch = wctob (*wp++);
00079                     if (ch != EOF)
00080                      putchar (ch);
00081                     else
00082                      fputs ("<??\?>", stdout);
00083                   }
00084 
00085                 putchar ('"');
00086               }
00087               first = 0;
00088              }
00089        }
00090       putchar ('\n');
00091       return;
00092     }
00093 
00094   if (strcmp (name, "collate-classes") == 0)
00095     {
00096       size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZE);
00097       size_t cnt;
00098       int first = 1;
00099 
00100       if (show_category_name)
00101        puts ("LC_COLLATE");
00102       if (show_keyword_name)
00103        fputs ("collate-classes=", stdout);
00104 
00105       for (cnt = 0; cnt < nelem; ++cnt)
00106        if (__collate_symbol_hash[2 * cnt] != 0xffffffff)
00107          {
00108            printf ("%s<%s>", first ? "" : ",",
00109                   &__collate_symbol_strings[__collate_symbol_hash[2 * cnt]]);
00110 #if 0
00111            {
00112              size_t idx = __collate_symbol_hash[2 * cnt + 1];
00113              size_t cls;
00114 
00115              putchar ('=');
00116              for (cls = 0; cls < __collate_symbol_classes[idx]; ++cls)
00117               printf ("%s%d", cls == 0 ? "" : ":",
00118                      __collate_symbol_classes[idx + 1 + cls]);
00119            }
00120 #endif
00121            first = 0;
00122          }
00123       putchar ('\n');
00124       return;
00125     }
00126 #endif
00127 }