OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [extra/] [locale/] [gen_ldc.c] - Blame information for rev 1771

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
#include <assert.h>
5
#include <stdint.h>
6
#include <stddef.h>
7
 
8
#ifndef __WCHAR_ENABLED
9
#warning WHOA!!! __WCHAR_ENABLED is not defined! defining it now...
10
#define __WCHAR_ENABLED
11
#endif
12
 
13
#define WANT_DATA
14
#include "c8tables.h"
15
#ifndef __CTYPE_HAS_8_BIT_LOCALES
16
#warning __CTYPE_HAS_8_BIT_LOCALES is not defined...
17
/* #define __CTYPE_HAS_8_BIT_LOCALES */
18
#endif
19
 
20
/*  #define __LOCALE_DATA_Cctype_TBL_LEN 328 */
21
/*  #define __LOCALE_DATA_Cuplow_TBL_LEN 400 */
22
/*  #define __LOCALE_DATA_Cc2wc_TBL_LEN 1448 */
23
/*  #define __LOCALE_DATA_Cwc2c_TBL_LEN 3744 */
24
 
25
#define WANT_WCctype_data
26
#define WANT_WCuplow_data
27
#define WANT_WCuplow_diff_data
28
/* #define WANT_WCcomb_data */
29
/*  #define WANT_WCwidth_data */
30
#include "wctables.h"
31
#undef WANT_WCctype_data
32
#undef WANT_WCuplow_data
33
#undef WANT_WCuplow_diff_data
34
/* #undef WANT_WCcomb_data */
35
/*  #undef WANT_WCwidth_data */
36
 
37
 #define __LOCALE_DATA_WCctype_TBL_LEN          (__LOCALE_DATA_WCctype_II_LEN + __LOCALE_DATA_WCctype_TI_LEN + __LOCALE_DATA_WCctype_UT_LEN)
38
 #define __LOCALE_DATA_WCuplow_TBL_LEN          (__LOCALE_DATA_WCuplow_II_LEN + __LOCALE_DATA_WCuplow_TI_LEN + __LOCALE_DATA_WCuplow_UT_LEN)
39
 #define __LOCALE_DATA_WCuplow_diff_TBL_LEN (2 * __LOCALE_DATA_WCuplow_diffs)
40
/*  #define WCcomb_TBL_LEN              (WCcomb_II_LEN + WCcomb_TI_LEN + WCcomb_UT_LEN) */
41
 
42
#include "locale_collate.h"
43
#include "locale_tables.h"
44
 
45
#include "locale_mmap.h"
46
 
47
/*  #undef __PASTE2 */
48
/*  #define __PASTE2(A,B)               A ## B */
49
/*  #undef __PASTE3 */
50
/*  #define __PASTE3(A,B,C)             A ## B ## C */
51
 
52
 
53
/*  #define __LOCALE_DATA_MAGIC_SIZE 64 */
54
 
55
/*  #define COMMON_MMAP(X) \ */
56
/*      unsigned char   __PASTE3(lc_,X,_data)[__PASTE3(__lc_,X,_data_LEN)]; */
57
 
58
/*  #define COMMON_MMIDX(X) \ */
59
/*      unsigned char   __PASTE3(lc_,X,_rows)[__PASTE3(__lc_,X,_rows_LEN)]; \ */
60
/*      uint16_t                __PASTE3(lc_,X,_item_offsets)[__PASTE3(__lc_,X,_item_offsets_LEN)]; \ */
61
/*      uint16_t                __PASTE3(lc_,X,_item_idx)[__PASTE3(__lc_,X,_item_idx_LEN)]; \ */
62
 
63
/* ---------------------------------------------------------------------- */
64
 
65
#define COMMON_OFFSETS(X) \
66
        offsetof(__locale_mmap_t, __PASTE3(lc_,X,_rows)), \
67
        offsetof(__locale_mmap_t, __PASTE3(lc_,X,_item_offsets)), \
68
        offsetof(__locale_mmap_t, __PASTE3(lc_,X,_item_idx)), \
69
        offsetof(__locale_mmap_t, __PASTE3(lc_,X,_data)) \
70
 
71
 
72
static const size_t common_tbl_offsets[__LOCALE_DATA_CATEGORIES*4] = {
73
        COMMON_OFFSETS(ctype),
74
        COMMON_OFFSETS(numeric),
75
        COMMON_OFFSETS(monetary),
76
        COMMON_OFFSETS(time),
77
        0, 0, 0, 0,                                 /* collate */
78
        COMMON_OFFSETS(messages),
79
};
80
 
81
 
82
void out_uc(FILE *f, const unsigned char *p, size_t n, char *comment)
83
{
84
        size_t i;
85
 
86
        fprintf(f, "{\t/* %s */", comment);
87
        for (i = 0 ; i < n ; i++) {
88
                if (!(i & 7)) {
89
                        fprintf(f, "\n\t");
90
                }
91
                if (p[i]) {
92
                        fprintf(f, "%#04x, ", p[i]);
93
                } else {
94
                        fprintf(f, "%#4x, ", p[i]);
95
                }
96
        }
97
        fprintf(f, "\n},\n");
98
}
99
 
100
void out_u16(FILE *f, const uint16_t *p, size_t n, char *comment)
101
{
102
        size_t i;
103
 
104
        fprintf(f, "{\t/* %s */", comment);
105
        for (i = 0 ; i < n ; i++) {
106
                if (!(i & 7)) {
107
                        fprintf(f, "\n\t");
108
                }
109
                if (p[i]) {
110
                        fprintf(f, "%#06x, ", p[i]);
111
                } else {
112
                        fprintf(f, "%#6x, ", p[i]);
113
                }
114
        }
115
        fprintf(f, "\n},\n");
116
}
117
 
118
void out_i16(FILE *f, const int16_t *p, size_t n, char *comment)
119
{
120
        size_t i;
121
 
122
        fprintf(f, "{\t/* %s */", comment);
123
        for (i = 0 ; i < n ; i++) {
124
                if (!(i & 7)) {
125
                        fprintf(f, "\n\t");
126
                }
127
                fprintf(f, "%6d, ", p[i]);
128
        }
129
        fprintf(f, "\n},\n");
130
}
131
 
132
void out_size_t(FILE *f, const size_t *p, size_t n, char *comment)
133
{
134
        size_t i;
135
 
136
        fprintf(f, "{\t/* %s */", comment);
137
        for (i = 0 ; i < n ; i++) {
138
                if (!(i & 3)) {
139
                        fprintf(f, "\n\t");
140
                }
141
                if (p[i]) {
142
                        fprintf(f, "%#010zx, ", p[i]);
143
                } else {
144
                        fprintf(f, "%#10zx, ", p[i]);
145
                }
146
        }
147
        fprintf(f, "\n},\n");
148
}
149
 
150
 
151
int main(void)
152
{
153
        FILE *lso;                                      /* static object */
154
        int i;
155
#ifdef __LOCALE_DATA_MAGIC_SIZE
156
        unsigned char magic[__LOCALE_DATA_MAGIC_SIZE];
157
 
158
        memset(magic, 0, __LOCALE_DATA_MAGIC_SIZE);
159
#endif /* __LOCALE_DATA_MAGIC_SIZE */
160
 
161
        if (!(lso = fopen("locale_data.c", "w"))) {
162
                printf("can't open locale_data.c!\n");
163
                return EXIT_FAILURE;
164
        }
165
 
166
        fprintf(lso,
167
                        "#include <stddef.h>\n"
168
                        "#include <stdint.h>\n"
169
/*                      "#define __CTYPE_HAS_8_BIT_LOCALES\n" */
170
                        "#ifndef __WCHAR_ENABLED\n"
171
                        "#error __WCHAR_ENABLED not defined\n"
172
                        "#endif\n"
173
                        "#include \"c8tables.h\"\n"
174
                        "#include \"wctables.h\"\n"
175
                        "#include \"lt_defines.h\"\n"
176
                        "#include \"locale_mmap.h\"\n\n"
177
                        "static const __locale_mmap_t locale_mmap = {\n\n"
178
                        );
179
#ifdef __LOCALE_DATA_MAGIC_SIZE
180
        out_uc(lso, magic, __LOCALE_DATA_MAGIC_SIZE, "magic");
181
#endif /* __LOCALE_DATA_MAGIC_SIZE */
182
#ifdef __CTYPE_HAS_8_BIT_LOCALES
183
        out_uc(lso, __LOCALE_DATA_Cctype_data, __LOCALE_DATA_Cctype_TBL_LEN, "tbl8ctype");
184
        out_uc(lso, __LOCALE_DATA_Cuplow_data, __LOCALE_DATA_Cuplow_TBL_LEN, "tbl8uplow");
185
#ifdef __WCHAR_ENABLED
186
        out_u16(lso, __LOCALE_DATA_Cc2wc_data, __LOCALE_DATA_Cc2wc_TBL_LEN, "tbl8c2wc");
187
        out_uc(lso, __LOCALE_DATA_Cwc2c_data, __LOCALE_DATA_Cwc2c_TBL_LEN, "tbl8wc2c");
188
        /* translit  */
189
#endif /* __WCHAR_ENABLED */
190
#endif /* __CTYPE_HAS_8_BIT_LOCALES */
191
#ifdef __WCHAR_ENABLED
192
        out_uc(lso, __LOCALE_DATA_WCctype_data, __LOCALE_DATA_WCctype_TBL_LEN, "tblwctype");
193
        out_uc(lso, __LOCALE_DATA_WCuplow_data, __LOCALE_DATA_WCuplow_TBL_LEN, "tblwuplow");
194
        out_i16(lso, __LOCALE_DATA_WCuplow_diff_data, __LOCALE_DATA_WCuplow_diff_TBL_LEN, "tblwuplow_diff");
195
/*      const unsigned char tblwcomb[WCcomb_TBL_LEN]; */
196
        /* width?? */
197
#endif /* __WCHAR_ENABLED */
198
        out_uc(lso, __lc_ctype_data, __lc_ctype_data_LEN, "lc_ctype_data");
199
        out_uc(lso, __lc_numeric_data, __lc_numeric_data_LEN, "lc_numeric_data");
200
        out_uc(lso, __lc_monetary_data, __lc_monetary_data_LEN, "lc_monetary_data");
201
        out_uc(lso, __lc_time_data, __lc_time_data_LEN, "lc_time_data");
202
        /* TODO -- collate*/
203
        out_uc(lso, __lc_messages_data, __lc_messages_data_LEN, "lc_messages_data");
204
 
205
#ifdef __CTYPE_HAS_8_BIT_LOCALES
206
        fprintf(lso, "{ /* codeset_8_bit array */\n");
207
        for (i = 0 ; i < __LOCALE_DATA_NUM_CODESETS ; i++) {
208
                fprintf(lso, "{ /* codeset_8_bit[%d] */\n", i);
209
                out_uc(lso, codeset_8_bit[i].idx8ctype, __LOCALE_DATA_Cctype_IDX_LEN, "idx8ctype");
210
                out_uc(lso, codeset_8_bit[i].idx8uplow, __LOCALE_DATA_Cuplow_IDX_LEN, "idx8uplow");
211
                out_uc(lso, codeset_8_bit[i].idx8c2wc, __LOCALE_DATA_Cc2wc_IDX_LEN, "idx8c2wc");
212
                out_uc(lso, codeset_8_bit[i].idx8wc2c, __LOCALE_DATA_Cwc2c_II_LEN, "idx8wc2c");
213
                fprintf(lso, "},\n");
214
        }
215
        fprintf(lso, "},\n");
216
#endif /* __CTYPE_HAS_8_BIT_LOCALES */
217
 
218
        out_uc(lso, __lc_ctype_rows, __lc_ctype_rows_LEN, "lc_ctype_rows");
219
        out_u16(lso, __lc_ctype_item_offsets, __lc_ctype_item_offsets_LEN, "lc_ctype_item_offsets");
220
        out_u16(lso, __lc_ctype_item_idx, __lc_ctype_item_idx_LEN, "lc_ctype_item_idx");
221
 
222
        out_uc(lso, __lc_numeric_rows, __lc_numeric_rows_LEN, "lc_numeric_rows");
223
        out_u16(lso, __lc_numeric_item_offsets, __lc_numeric_item_offsets_LEN, "lc_numeric_item_offsets");
224
        out_u16(lso, __lc_numeric_item_idx, __lc_numeric_item_idx_LEN, "lc_numeric_item_idx");
225
 
226
        out_uc(lso, __lc_monetary_rows, __lc_monetary_rows_LEN, "lc_monetary_rows");
227
        out_u16(lso, __lc_monetary_item_offsets, __lc_monetary_item_offsets_LEN, "lc_monetary_item_offsets");
228
        out_u16(lso, __lc_monetary_item_idx, __lc_monetary_item_idx_LEN, "lc_monetary_item_idx");
229
 
230
        out_uc(lso, __lc_time_rows, __lc_time_rows_LEN, "lc_time_rows");
231
        out_u16(lso, __lc_time_item_offsets, __lc_time_item_offsets_LEN, "lc_time_item_offsets");
232
        out_u16(lso, __lc_time_item_idx, __lc_time_item_idx_LEN, "lc_time_item_idx");
233
 
234
        out_uc(lso, __lc_messages_rows, __lc_messages_rows_LEN, "lc_messages_rows");
235
        out_u16(lso, __lc_messages_item_offsets, __lc_messages_item_offsets_LEN, "lc_messages_item_offsets");
236
        out_u16(lso, __lc_messages_item_idx, __lc_messages_item_idx_LEN, "lc_messages_item_idx");
237
 
238
        /* collate should be last*/
239
        assert(sizeof(__locale_collate_tbl)/sizeof(__locale_collate_tbl[0]) == __lc_collate_data_LEN) ;
240
        out_u16(lso, __locale_collate_tbl, __lc_collate_data_LEN, "collate_data");
241
 
242
 
243
        {
244
                unsigned char co_buf[__LOCALE_DATA_CATEGORIES] = {
245
                        __lc_ctype_item_offsets_LEN,
246
                        __lc_numeric_item_offsets_LEN,
247
                        __lc_monetary_item_offsets_LEN,
248
                        __lc_time_item_offsets_LEN,
249
                        0,
250
                        __lc_messages_item_offsets_LEN
251
                };
252
                out_uc(lso, co_buf, __LOCALE_DATA_CATEGORIES, "lc_common_item_offsets_LEN");
253
        }
254
 
255
        out_size_t(lso, common_tbl_offsets, __LOCALE_DATA_CATEGORIES * 4, "lc_common_tbl_offsets");
256
        /* offsets from start of locale_mmap_t */
257
        /* rows, item_offsets, item_idx, data */
258
 
259
#ifdef __LOCALE_DATA_NUM_LOCALES
260
        out_uc(lso, __locales, __LOCALE_DATA_NUM_LOCALES * __LOCALE_DATA_WIDTH_LOCALES, "locales");
261
        out_uc(lso, __locale_names5, 5 * __LOCALE_DATA_NUM_LOCALE_NAMES, "locale_names5");
262
#ifdef __LOCALE_DATA_AT_MODIFIERS_LENGTH
263
        out_uc(lso, __locale_at_modifiers, __LOCALE_DATA_AT_MODIFIERS_LENGTH, "locale_at_modifiers");
264
#else
265
#error __LOCALE_DATA_AT_MODIFIERS_LENGTH not defined!
266
#endif /* __LOCALE_DATA_AT_MODIFIERS_LENGTH */
267
#endif /* __LOCALE_DATA_NUM_LOCALES */
268
 
269
        out_uc(lso, lc_names, __lc_names_LEN, "lc_names");
270
#ifdef __CTYPE_HAS_8_BIT_LOCALES
271
        out_uc(lso, (const unsigned char*) __LOCALE_DATA_CODESET_LIST, sizeof(__LOCALE_DATA_CODESET_LIST), "codeset_list");
272
#endif /* __CTYPE_HAS_8_BIT_LOCALES */
273
 
274
        fprintf(lso,
275
                        "\n};\n\n"
276
                        "const __locale_mmap_t *__locale_mmap = &locale_mmap;\n\n"
277
                        );
278
 
279
        if (ferror(lso) || fclose(lso)) {
280
                printf("error writing!\n");
281
                return EXIT_FAILURE;
282
        }
283
 
284
        return EXIT_SUCCESS;
285
}
286
 
287
/* ---------------------------------------------------------------------- */
288
 
289
/* TODO:
290
 * collate data (8-bit weighted single char only)
291
 * @ mappings!
292
 * codeset list? yes, since we'll want to be able to inspect them...
293
 * that means putting some header stuff in magic
294
 * fix ctype LEN defines in gen_c8tables
295
 */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.