diff options
Diffstat (limited to 'locale/programs/locale.c')
-rw-r--r-- | locale/programs/locale.c | 188 |
1 files changed, 34 insertions, 154 deletions
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};"); -} |