Sun Dec 17 15:56:35 1995 Miles Bader <miles@gnu.ai.mit.edu>
[glibc.git] / locale / ctypedump.c
blobe00f3e0f11e6e90639b78c7784941d10fb191beb
1 /* Copyright (C) 1995 Free Software Foundation, Inc.
3 The GNU C Library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Library General Public License as
5 published by the Free Software Foundation; either version 2 of the
6 License, or (at your option) any later version.
8 The GNU C Library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
13 You should have received a copy of the GNU Library General Public
14 License along with the GNU C Library; see the file COPYING.LIB. If
15 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
16 Cambridge, MA 02139, USA. */
18 #include <ctype.h>
19 #include <endian.h>
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <netinet/in.h> /* Just for htons() */
24 #include "localedef.h"
25 #include "localeinfo.h"
28 /* FIXME: these values should be part of the LC_CTYPE information. */
29 #define mb_cur_max 1
30 #define mb_cur_min 1
33 #define SWAP32(v) \
34 ((u32) (((((u32) (v)) & 0x000000ff) << 24) \
35 | ((((u32) (v)) & 0x0000ff00) << 8) \
36 | ((((u32) (v)) & 0x00ff0000) >> 8) \
37 | ((((u32) (v)) & 0xff000000) >> 24)))
41 static inline void
42 print_short_in_char (unsigned short val)
44 const unsigned char *p = (const unsigned char *) &val;
45 printf ("\"\\%03o\\%03o\"", p[0], p[1]);
49 static inline void
50 print_int_in_char (unsigned int val)
52 const unsigned char *p = (const unsigned char *) &val;
53 printf ("\"\\%03o\\%03o\\%03o\\%03o\"", p[0], p[1], p[2], p[3]);
57 int
58 ctype_output (void)
60 int ch;
61 int result = 0;
62 const char *locname = (getenv ("LC_ALL") ?: getenv ("LC_CTYPE") ?:
63 getenv ("LANG") ?: "POSIX");
65 puts ("#include <endian.h>\n");
67 if (mb_cur_max == 1)
69 printf ("const char _nl_%s_LC_CTYPE_class[] = \n", locname);
70 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
72 if (((ch + 128) % 6) == 0)
73 printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
74 print_short_in_char (htons (__ctype_b [ch < 0 ? 256 + ch : ch]));
75 fputc (((ch + 128) % 6) == 5 ? '\n' : ' ', stdout);
77 puts (";");
80 printf ("#if BYTE_ORDER == %s\n",
81 BYTE_ORDER == LITTLE_ENDIAN ? "LITTLE_ENDIAN" : "BIG_ENDIAN");
83 if (mb_cur_max == 1)
85 printf ("const char _nl_%s_LC_CTYPE_toupper[] = \n", locname);
86 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
88 if (((ch + 128) % 3) == 0)
89 printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
90 print_int_in_char (__ctype_toupper[ch < 0 ? 256 + ch : ch]);
91 fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
93 puts (";");
95 printf ("const char _nl_%s_LC_CTYPE_tolower[] = \n", locname);
96 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
98 if (((ch + 128) % 3) == 0)
99 printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
100 print_int_in_char (__ctype_tolower[ch < 0 ? 256 + ch : ch]);
101 fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
103 puts (";");
105 else
106 /* not implemented */;
108 printf ("#elif BYTE_ORDER == %s\n",
109 BYTE_ORDER == LITTLE_ENDIAN ? "BIG_ENDIAN" : "LITTLE_ENDIAN");
111 if (mb_cur_max == 1)
113 printf ("const char _nl_%s_LC_CTYPE_toupper[] = \n", locname);
114 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
116 if (((ch + 128) % 3) == 0)
117 printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
118 print_int_in_char (SWAP32 (__ctype_toupper[ch < 0 ? 256 + ch : ch]));
119 fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
121 puts (";");
123 printf ("const char _nl_%s_LC_CTYPE_tolower[] = \n", locname);
124 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
126 if (((ch + 128) % 3) == 0)
127 printf (" /* 0x%02x */ ", ch < 0 ? 256 + ch : ch);
128 print_int_in_char (SWAP32 (__ctype_tolower[ch < 0 ? 256 + ch : ch]));
129 fputc (((ch + 128) % 3) == 2 ? '\n' : ' ', stdout);
131 puts (";");
133 else
134 /* not implemented */;
136 puts ("#else\n#error \"BYTE_ORDER\" BYTE_ORDER \" not handled.\"\n#endif\n");
138 printf("const struct locale_data _nl_%s_LC_CTYPE = \n\
139 {\n\
140 NULL, 0, /* no file mapped */\n\
141 5,\n\
142 {\n\
143 _nl_C_LC_CTYPE_class,\n\
144 #ifdef BYTE_ORDER == LITTLE_ENDIAN\n\
145 NULL, NULL,\n\
146 #endif\n\
147 _nl_C_LC_CTYPE_toupper,\n\
148 _nl_C_LC_CTYPE_tolower,\n\
149 #ifdef BYTE_ORDER == BIG_ENDIAN\n\
150 NULL, NULL,\n\
151 #endif\n\
152 }\n\
153 };\n", locname);
155 return result;
159 * Local Variables:
160 * mode:c
161 * c-basic-offset:2
162 * End: