Blame locale/programs/locale-spec.c

Packit 6c4009
/* Handle special requests.
Packit 6c4009
   Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1996.
Packit 6c4009
Packit 6c4009
   This program is free software; you can redistribute it and/or modify
Packit 6c4009
   it under the terms of the GNU General Public License as published
Packit 6c4009
   by the Free Software Foundation; version 2 of the License, or
Packit 6c4009
   (at your option) any later version.
Packit 6c4009
Packit 6c4009
   This program is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 6c4009
   GNU General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU General Public License
Packit 6c4009
   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifdef HAVE_CONFIG_H
Packit 6c4009
# include <config.h>
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#include <error.h>
Packit 6c4009
#include <libintl.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <string.h>
Packit 6c4009
#include <wchar.h>
Packit 6c4009
Packit 6c4009
#include "localeinfo.h"
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* We provide support for some special names.  This helps debugging
Packit 6c4009
   and may be useful for advanced usage of the provided information
Packit 6c4009
   outside C.  */
Packit 6c4009
void
Packit 6c4009
locale_special (const char *name, int show_category_name,
Packit 6c4009
		int show_keyword_name)
Packit 6c4009
{
Packit 6c4009
#if 0
Packit 6c4009
  /* "collate-elements": print collation elements of locale.  */
Packit 6c4009
  if (strcmp (name, "collate-elements") == 0)
Packit 6c4009
    {
Packit 6c4009
      size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_ELEM_HASH_SIZE);
Packit 6c4009
Packit 6c4009
      if (show_category_name)
Packit 6c4009
	puts ("LC_COLLATE");
Packit 6c4009
      if (show_keyword_name)
Packit 6c4009
	fputs ("collate-elements=", stdout);
Packit 6c4009
Packit 6c4009
      if (nelem != 0)
Packit 6c4009
	{
Packit 6c4009
	  int first = 1;
Packit 6c4009
	  size_t cnt;
Packit 6c4009
Packit 6c4009
	  for (cnt = 0; cnt < nelem; ++cnt)
Packit 6c4009
	    if (__collate_element_hash[2 * cnt] != (~((uint32_t) 0)))
Packit 6c4009
	      {
Packit 6c4009
		size_t idx = __collate_element_hash[2 * cnt];
Packit 6c4009
Packit 6c4009
		printf ("%s<%s>", first ? "" : ";",
Packit 6c4009
			&__collate_element_strings[idx]);
Packit 6c4009
Packit 6c4009
		/* We don't print the string.  This is only confusing
Packit 6c4009
		   because only the programs have to know the
Packit 6c4009
		   encoding.  The code is left in place because it
Packit 6c4009
		   shows how to get the information.  */
Packit 6c4009
		{
Packit 6c4009
		  const wchar_t *wp;
Packit 6c4009
Packit 6c4009
		  idx = __collate_element_hash[2 * cnt + 1];
Packit 6c4009
		  wp = &__collate_element_values[idx];
Packit 6c4009
		  while (*wp != L'\0')
Packit 6c4009
		    {
Packit 6c4009
		      /********************************************\
Packit 6c4009
		      |* XXX The element values are really wide	  *|
Packit 6c4009
		      |* chars.  But we are currently not able to *|
Packit 6c4009
		      |* print these so fake here.		  *|
Packit 6c4009
		      \********************************************/
Packit 6c4009
		      int ch = wctob (*wp++);
Packit 6c4009
		      if (ch != EOF)
Packit 6c4009
			putchar (ch);
Packit 6c4009
		      else
Packit 6c4009
			fputs ("", stdout);
Packit 6c4009
		    }
Packit 6c4009
Packit 6c4009
		  putchar ('"');
Packit 6c4009
		}
Packit 6c4009
		first = 0;
Packit 6c4009
	      }
Packit 6c4009
	}
Packit 6c4009
      putchar ('\n');
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  if (strcmp (name, "collate-classes") == 0)
Packit 6c4009
    {
Packit 6c4009
      size_t nelem = _NL_CURRENT_WORD (LC_COLLATE, _NL_COLLATE_SYMB_HASH_SIZE);
Packit 6c4009
      size_t cnt;
Packit 6c4009
      int first = 1;
Packit 6c4009
Packit 6c4009
      if (show_category_name)
Packit 6c4009
	puts ("LC_COLLATE");
Packit 6c4009
      if (show_keyword_name)
Packit 6c4009
	fputs ("collate-classes=", stdout);
Packit 6c4009
Packit 6c4009
      for (cnt = 0; cnt < nelem; ++cnt)
Packit 6c4009
	if (__collate_symbol_hash[2 * cnt] != 0xffffffff)
Packit 6c4009
	  {
Packit 6c4009
	    printf ("%s<%s>", first ? "" : ",",
Packit 6c4009
		    &__collate_symbol_strings[__collate_symbol_hash[2 * cnt]]);
Packit 6c4009
#if 0
Packit 6c4009
	    {
Packit 6c4009
	      size_t idx = __collate_symbol_hash[2 * cnt + 1];
Packit 6c4009
	      size_t cls;
Packit 6c4009
Packit 6c4009
	      putchar ('=');
Packit 6c4009
	      for (cls = 0; cls < __collate_symbol_classes[idx]; ++cls)
Packit 6c4009
		printf ("%s%d", cls == 0 ? "" : ":",
Packit 6c4009
			__collate_symbol_classes[idx + 1 + cls]);
Packit 6c4009
	    }
Packit 6c4009
#endif
Packit 6c4009
	    first = 0;
Packit 6c4009
	  }
Packit 6c4009
      putchar ('\n');
Packit 6c4009
      return;
Packit 6c4009
    }
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
  /* If nothing matches, fail.  */
Packit 6c4009
  error (1, 0, gettext ("unknown name \"%s\""), name);
Packit 6c4009
}