summary refs log tree commit diff
path: root/locale/programs
diff options
context:
space:
mode:
Diffstat (limited to 'locale/programs')
-rw-r--r--locale/programs/config.h3
-rw-r--r--locale/programs/ctypedump.c163
-rw-r--r--locale/programs/locale.c188
3 files changed, 35 insertions, 319 deletions
diff --git a/locale/programs/config.h b/locale/programs/config.h
index 64054657cb..4aa406d755 100644
--- a/locale/programs/config.h
+++ b/locale/programs/config.h
@@ -27,7 +27,6 @@ typedef int wint_t;
 typedef unsigned short int u16_t;
 
 
-
-int euidaccess (__const char *__name, int __type);
+#include_next <config.h>
 
 #endif
diff --git a/locale/programs/ctypedump.c b/locale/programs/ctypedump.c
deleted file mode 100644
index 2a6753495e..0000000000
--- a/locale/programs/ctypedump.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
-
-The GNU C Library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-The GNU C Library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the GNU C Library; see the file COPYING.LIB.  If
-not, write to the Free Software Foundation, Inc., 675 Mass Ave,
-Cambridge, MA 02139, USA.  */
-
-#include <ctype.h>
-#include <endian.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <netinet/in.h>        /* Just for htons() */
-
-/*#include "localedef.h"*/
-#include "localeinfo.h"
-
-
-/* FIXME: these values should be part of the LC_CTYPE information.  */
-#define mb_cur_max 1
-#define mb_cur_min 1
-
-
-#define SWAP32(v)							     \
-	((u32_t) (((((u32_t) (v)) & 0x000000ff) << 24)			     \
-		| ((((u32_t) (v)) & 0x0000ff00) << 8)			     \
-		| ((((u32_t) (v)) & 0x00ff0000) >> 8)			     \
-		| ((((u32_t) (v)) & 0xff000000) >> 24)))
-
-
-
-static inline void
-print_short_in_char (unsigned short val)
-{
-  const unsigned char *p = (const unsigned char *) &val;
-  printf ("\"\\%03o\\%03o\"", p[0], p[1]);
-}
-
-
-static inline void
-print_int_in_char (unsigned int val)
-{
-  const unsigned char *p = (const unsigned char *) &val;
-  printf ("\"\\%03o\\%03o\\%03o\\%03o\"", p[0], p[1], p[2], p[3]);
-}
-
-
-int
-ctype_output (void)
-{
-  int ch;
-  int result = 0;
-  const char *locname = (getenv ("LC_ALL") ?: getenv ("LC_CTYPE") ?:
-			 getenv ("LANG") ?: "POSIX");
-
-  puts ("#include <endian.h>\n");
-
-  if (mb_cur_max == 1)
-    {
-      printf ("const char _nl_%s_LC_CTYPE_class[] = \n", locname);
-      for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
-        {
-	  if (((ch + 128) % 6) == 0)
-	    printf ("  /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
-	  print_short_in_char (htons (__ctype_b [ch < 0 ? 256 + ch : ch]));
-	  fputc (((ch + 128) % 6) == 5 ? '\n' : ' ', stdout);
-        }
-      puts (";");
-    }
-
-  printf ("#if BYTE_ORDER == %s\n",
-	  BYTE_ORDER == LITTLE_ENDIAN ? "LITTLE_ENDIAN" : "BIG_ENDIAN");
-
-  if (mb_cur_max == 1)
-    {
-      printf ("const char _nl_%s_LC_CTYPE_toupper[] = \n", locname);
-      for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
-        {
-	  if (((ch + 128) % 3) == 0)
-	    printf ("  /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
-	  print_int_in_char (__ctype_toupper[ch < 0 ? 256 + ch : ch]);
-	  fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
-        }
-      puts (";");
-
-      printf ("const char _nl_%s_LC_CTYPE_tolower[] = \n", locname);
-      for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
-        {
-	  if (((ch + 128) % 3) == 0)
-	    printf ("  /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
-	  print_int_in_char (__ctype_tolower[ch < 0 ? 256 + ch : ch]);
-	  fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
-        }
-      puts (";");
-    }
-  else
-    /* not implemented */;
-
-  printf ("#elif BYTE_ORDER == %s\n",
-          BYTE_ORDER == LITTLE_ENDIAN ? "BIG_ENDIAN" : "LITTLE_ENDIAN");
-
-  if (mb_cur_max == 1)
-    {
-      printf ("const char _nl_%s_LC_CTYPE_toupper[] = \n", locname);
-      for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
-        {
-	  if (((ch + 128) % 3) == 0)
-	    printf ("  /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
-	  print_int_in_char (SWAP32 (__ctype_toupper[ch < 0 ? 256 + ch : ch]));
-	  fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
-        }
-      puts (";");
-
-      printf ("const char _nl_%s_LC_CTYPE_tolower[] = \n", locname);
-      for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
-        {
-	  if (((ch + 128) % 3) == 0)
-	    printf ("  /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
-	  print_int_in_char (SWAP32 (__ctype_tolower[ch < 0 ? 256 + ch : ch]));
-	  fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
-        }
-      puts (";");
-    }
-  else
-    /* not implemented */;
-
-  puts ("#else\n#error \"BYTE_ORDER\" BYTE_ORDER \" not handled.\"\n#endif\n");
-
-  printf("const struct locale_data _nl_%s_LC_CTYPE = \n\
-{\n\
-  NULL, 0, /* no file mapped */\n\
-  5,\n\
-  {\n\
-    _nl_C_LC_CTYPE_class,\n\
-#ifdef BYTE_ORDER == LITTLE_ENDIAN\n\
-    NULL, NULL,\n\
-#endif\n\
-    _nl_C_LC_CTYPE_toupper,\n\
-    _nl_C_LC_CTYPE_tolower,\n\
-#ifdef BYTE_ORDER == BIG_ENDIAN\n\
-    NULL, NULL,\n\
-#endif\n\
-  }\n\
-};\n", locname);
-
-  return result;
-}
-
-/*
- * Local Variables:
- *  mode:c
- *  c-basic-offset:2
- * End:
- */
diff --git a/locale/programs/locale.c b/locale/programs/locale.c
index 4e4ff83a37..8254289598 100644
--- a/locale/programs/locale.c
+++ b/locale/programs/locale.c
@@ -15,7 +15,12 @@ License along with the GNU C Library; see the file COPYING.LIB.  If
 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
 Cambridge, MA 02139, USA.  */
 
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include <dirent.h>
+#include <error.h>
 #include <getopt.h>
 #include <langinfo.h>
 #include <libintl.h>
@@ -26,13 +31,9 @@ Cambridge, MA 02139, USA.  */
 #include <unistd.h>
 #include <errno.h>
 
-/*#include "localedef.h"*/
 #include "localeinfo.h"
 
 
-/* If set dump C code describing the current locale.  */
-static int do_dump;
-
 /* If set print the name of the category.  */
 static int show_category_name;
 
@@ -45,7 +46,6 @@ static const struct option long_options[] =
   { "all-locales", no_argument, NULL, 'a' },
   { "category-name", no_argument, &show_category_name, 1 },
   { "charmaps", no_argument, NULL, 'm' },
-  { "dump", no_argument, &do_dump, 1 },
   { "help", no_argument, NULL, 'h' },
   { "keyword-name", no_argument, &show_keyword_name, 1 },
   { "version", no_argument, NULL, 'v' },
@@ -65,35 +65,48 @@ static const struct option long_options[] =
 #define CTYPE_TOUPPER_EL 0
 #define CTYPE_TOLOWER_EL 0
 
-/* XXX Hack */
-struct cat_item
+/* Definition of the data structure which represents a category and its
+   items.  */
+struct category
 {
-  int item_id;
+  int cat_id;
   const char *name;
-  enum { std, opt } status;
-  enum value_type value_type;
-  int min;
-  int max;
+  size_t number;
+  struct cat_item
+  {
+    int item_id;
+    const char *name;
+    enum { std, opt } status;
+    enum value_type value_type;
+    int min;
+    int max;
+  } *item_desc;
 };
 
+/* Simple helper macro.  */
+#define NELEMS(arr) ((sizeof (arr)) / (sizeof (arr[0])))
+
+/* For some tricky stuff.  */
+#define NO_PAREN(Item, More...) Item, ## More
 
 /* We have all categories defined in `categories.def'.  Now construct
    the description and data structure used for all categories.  */
+#define DEFINE_ELEMENT(Item, More...) { Item, ## More },
 #define DEFINE_CATEGORY(category, name, items, postload, in, check, out)      \
     static struct cat_item category##_desc[] =				      \
       {									      \
         NO_PAREN items							      \
       };
 
-#include "locale/aux/categories.def"
+#include "categories.def"
 #undef DEFINE_CATEGORY
 
 static struct category category[] =
   {
 #define DEFINE_CATEGORY(category, name, items, postload, in, check, out)      \
     { _NL_NUM_##category, name, NELEMS (category##_desc) - 1,                 \
-      category##_desc, NULL, NULL, NULL, out },
-#include "locale/aux/categories.def"
+      category##_desc },
+#include "categories.def"
 #undef DEFINE_CATEGORY
   };
 #define NCATEGORIES NELEMS (category)
@@ -105,7 +118,6 @@ static void write_locales (void);
 static void write_charmaps (void);
 static void show_locale_vars (void);
 static void show_info (const char *name);
-static void dump_category (const char *name);
 
 
 int
@@ -118,7 +130,6 @@ main (int argc, char *argv[])
   int do_charmaps = 0;
 
   /* Set initial values for global varaibles.  */
-  do_dump = 0;
   show_category_name = 0;
   show_keyword_name = 0;
 
@@ -170,20 +181,6 @@ main (int argc, char *argv[])
   if (do_help)
     usage (EXIT_SUCCESS);
 
-  /* Dump C code.  */
-  if (do_dump)
-    {
-      printf ("\
-/* Generated by GNU %s %s.  */\n\
-\n\
-#include \"localeinfo.h\"\n", program_invocation_name, VERSION);
-
-      while (optind < argc)
-	dump_category (argv[optind++]);
-
-      exit (EXIT_SUCCESS);
-    }
-
   /* `-a' requests the names of all available locales.  */
   if (do_all != 0)
     {
@@ -235,8 +232,6 @@ Mandatory arguments to long options are mandatory for short options too.\n\
   -c, --category-name   write names of selected categories\n\
   -k, --keyword-name    write names of selected keywords\n\
 \n\
-      --dump            dump C code describing the current locale\n\
-                        (this code can be used in the C library)\n\
 "), program_invocation_name);
 
   exit (status);
@@ -389,6 +384,12 @@ show_info (const char *name)
 	    printf ("%d", cnt == 0 || *val == CHAR_MAX ? -1 : *val);
 	  }
 	  break;
+	case word:
+	  {
+	    unsigned int val = (unsigned int) nl_langinfo (item->item_id);
+	    printf ("%d", val);
+	  }
+	  break;
 	default:
 	}
       putchar ('\n');
@@ -398,13 +399,6 @@ show_info (const char *name)
     {
       size_t item_no;
 
-      if (category[cat_no].outfct != NULL)
-	/* Categories which need special handling of the output are
-	   not written.  This is especially for LC_CTYPE and LC_COLLATE.
-	   It does not make sense to have this large number of cryptic
-	   characters displayed.  */
-	continue;
-
       if (strcmp (name, category[cat_no].name) == 0)
 	/* Print the whole category.  */
 	{
@@ -428,117 +422,3 @@ show_info (const char *name)
 	  }
     }
 }
-
-
-static void
-dump_category (const char *name)
-{
-  char *locname;
-  size_t cat_no, item_no, nstrings;
-
-  for (cat_no = 0; cat_no < NCATEGORIES; ++cat_no)
-    if (strcmp (name, category[cat_no].name) == 0)
-      break;
-
-  if (cat_no >= NCATEGORIES)
-    return;
-
-  /* The NAME specifies a correct locale category.  */
-  if (category[cat_no].outfct != NULL)
-    {
-      category[cat_no].outfct ();
-      return;
-    }
-
-  locname = (getenv ("LC_ALL") ?: getenv (name) ?:
-	     getenv ("LANG") ?: (char *) "POSIX");
-
-  /* Determine the number of strings in advance.  */
-  nstrings = 0;
-  for (item_no = 0; item_no < category[cat_no].number; ++item_no)
-    switch (category[cat_no].item_desc[item_no].value_type)
-      {
-      case string:
-      case byte:
-      case bytearray:
-	++nstrings;
-	break;
-      case stringarray:
-	nstrings += category[cat_no].item_desc[item_no].max;
-      default:
-      }
-
-  printf ("\nconst struct locale_data _nl_%s_%s =\n{\n"
-	  "  NULL, 0, /* no file mapped */\n  %Zu,\n  {\n",
-	  locname, name, nstrings);
-
-  for (item_no = 0; item_no < category[cat_no].number; ++item_no)
-    switch (category[cat_no].item_desc[item_no].value_type)
-      {
-      case string:
-	{
-	  const char *val = nl_langinfo (
-	    category[cat_no].item_desc[item_no].item_id);
-
-	  if (val != NULL)
-	    printf ("    \"%s\",\n", val);
-	  else
-	    puts ("    NULL,");
-	}
-	break;
-      case stringarray:
-	{
-	  const char *val;
-	  int cnt;
-
-	  for (cnt = 0; cnt < category[cat_no].item_desc[item_no].max; ++cnt)
-	    {
-	      val = nl_langinfo (
-		category[cat_no].item_desc[item_no].item_id + cnt);
-
-	      if (val != NULL)
-		printf ("    \"%s\",\n", val);
-	      else
-                puts ("    NULL,");
-	    }
-	}
-	break;
-      case byte:
-	{
-	  const char *val = nl_langinfo (
-	    category[cat_no].item_desc[item_no].item_id);
-
-	  if (val != NULL)
-	    printf ("    \"\\%o\",\n",
-		    *(unsigned char *) val ? : UCHAR_MAX);
-	  else
-	    puts ("    NULL,");
-	}
-	break;
-      case bytearray:
-	{
-	  const char *bytes = nl_langinfo (
-	    category[cat_no].item_desc[item_no].item_id);
-
-	  if (bytes != NULL)
-	    {
-	      fputs ("    \"", stdout);
-	      if (*bytes != '\0')
-		do
-		  printf ("\\%o", *(unsigned char *) bytes++);
-		while (*bytes != '\0');
-	      else
-		printf ("\\%o", UCHAR_MAX);
-
-	      puts ("\",");
-	    }
-	  else
-	    puts ("    NULL,");
-	}
-	break;
-      default:
-	break;
-      }
-
-  puts ("  }\n};");
-}