]> git.ipfire.org Git - thirdparty/glibc.git/blame - locale/programs/ctypedump.c
Thu Mar 28 03:25:10 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
[thirdparty/glibc.git] / locale / programs / ctypedump.c
CommitLineData
19bc17a9 1/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
2b83a2a4
RM
2
3The GNU C Library is free software; you can redistribute it and/or
4modify it under the terms of the GNU Library General Public License as
5published by the Free Software Foundation; either version 2 of the
6License, or (at your option) any later version.
7
8The GNU C Library is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11Library General Public License for more details.
12
13You should have received a copy of the GNU Library General Public
14License along with the GNU C Library; see the file COPYING.LIB. If
15not, write to the Free Software Foundation, Inc., 675 Mass Ave,
16Cambridge, MA 02139, USA. */
17
18#include <ctype.h>
19#include <endian.h>
20#include <stdlib.h>
21#include <stdio.h>
22#include <netinet/in.h> /* Just for htons() */
23
19bc17a9 24/*#include "localedef.h"*/
2b83a2a4
RM
25#include "localeinfo.h"
26
27
28/* FIXME: these values should be part of the LC_CTYPE information. */
29#define mb_cur_max 1
30#define mb_cur_min 1
31
32
33#define SWAP32(v) \
19bc17a9
RM
34 ((u32_t) (((((u32_t) (v)) & 0x000000ff) << 24) \
35 | ((((u32_t) (v)) & 0x0000ff00) << 8) \
36 | ((((u32_t) (v)) & 0x00ff0000) >> 8) \
37 | ((((u32_t) (v)) & 0xff000000) >> 24)))
2b83a2a4
RM
38
39
40
41static inline void
42print_short_in_char (unsigned short val)
43{
44 const unsigned char *p = (const unsigned char *) &val;
45 printf ("\"\\%03o\\%03o\"", p[0], p[1]);
46}
47
48
49static inline void
50print_int_in_char (unsigned int val)
51{
52 const unsigned char *p = (const unsigned char *) &val;
53 printf ("\"\\%03o\\%03o\\%03o\\%03o\"", p[0], p[1], p[2], p[3]);
54}
55
19bc17a9 56
2b83a2a4
RM
57int
58ctype_output (void)
59{
60 int ch;
61 int result = 0;
19bc17a9 62 const char *locname = (getenv ("LC_ALL") ?: getenv ("LC_CTYPE") ?:
2b83a2a4
RM
63 getenv ("LANG") ?: "POSIX");
64
65 puts ("#include <endian.h>\n");
66
67 if (mb_cur_max == 1)
68 {
69 printf ("const char _nl_%s_LC_CTYPE_class[] = \n", locname);
70 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
71 {
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);
76 }
77 puts (";");
78 }
79
80 printf ("#if BYTE_ORDER == %s\n",
81 BYTE_ORDER == LITTLE_ENDIAN ? "LITTLE_ENDIAN" : "BIG_ENDIAN");
82
83 if (mb_cur_max == 1)
84 {
85 printf ("const char _nl_%s_LC_CTYPE_toupper[] = \n", locname);
86 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
87 {
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);
92 }
93 puts (";");
94
95 printf ("const char _nl_%s_LC_CTYPE_tolower[] = \n", locname);
96 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
97 {
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);
102 }
103 puts (";");
104 }
105 else
106 /* not implemented */;
107
108 printf ("#elif BYTE_ORDER == %s\n",
109 BYTE_ORDER == LITTLE_ENDIAN ? "BIG_ENDIAN" : "LITTLE_ENDIAN");
110
111 if (mb_cur_max == 1)
112 {
113 printf ("const char _nl_%s_LC_CTYPE_toupper[] = \n", locname);
114 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
115 {
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);
120 }
121 puts (";");
122
123 printf ("const char _nl_%s_LC_CTYPE_tolower[] = \n", locname);
124 for (ch = -128; ch < (1 << (8 * MB_CUR_MAX)); ++ch)
125 {
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);
130 }
131 puts (";");
132 }
133 else
134 /* not implemented */;
135
136 puts ("#else\n#error \"BYTE_ORDER\" BYTE_ORDER \" not handled.\"\n#endif\n");
137
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);
154
155 return result;
156}
157
158/*
159 * Local Variables:
160 * mode:c
161 * c-basic-offset:2
162 * End:
163 */