summaryrefslogtreecommitdiff
path: root/locale/ctypedump.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-05-18 09:00:09 +0000
committerRoland McGrath <roland@gnu.org>1995-05-18 09:00:09 +0000
commit2b83a2a4d978012cdf78b648337c31091e20526d (patch)
tree6a5130b031f6815b6edbbb6e2b084c79ece15b1d /locale/ctypedump.c
parent4f6dc78a9237bb327a1d694635be9b0f50cc395e (diff)
Wed May 17 16:50:21 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
Merged 1003.2 locale and localedef programs by Ulrich Drepper. * locale/charmap.c: New file. * locale/collate.c: New file. * locale/config.h: New file. * locale/ctype.c: New file. * locale/ctypedump.c: New file. * locale/hash.c: New file. * locale/hash.h: New file. * locale/iso-4217.def: New file. * locale/keyword.gperf: New file. * locale/keyword.h: New file. * locale/libintl.h: New file. * locale/locale.c: New file. * locale/localedef.c: New file. * locale/localedef.h: New file. * locale/locfile-lex.c: New file. * locale/locfile-parse.c: New file. * locale/messages.c: New file. * locale/monetary.c: New file. * locale/numeric.c: New file. * locale/token.h: New file. * posix/regex.c, posix/regex.h: New files, incorporated from GNU regex. * posix/Makefile (headers): Add regex.h. (routines): Add regex. (gpl2lgpl): Add regex.c and regex.h. Tue May 16 17:35:07 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu> * locale/loadlocale.c: Expect macro LOCALE_PATH to be defined, instead of hard-coding "/share/locale".
Diffstat (limited to 'locale/ctypedump.c')
-rw-r--r--locale/ctypedump.c163
1 files changed, 163 insertions, 0 deletions
diff --git a/locale/ctypedump.c b/locale/ctypedump.c
new file mode 100644
index 0000000000..e00f3e0f11
--- /dev/null
+++ b/locale/ctypedump.c
@@ -0,0 +1,163 @@
+/* Copyright (C) 1995 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) (((((u32) (v)) & 0x000000ff) << 24) \
+ | ((((u32) (v)) & 0x0000ff00) << 8) \
+ | ((((u32) (v)) & 0x00ff0000) >> 8) \
+ | ((((u32) (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:
+ */