2 * gen-bidi-type-tab.c - generate bidi-type.tab.i
5 * Behdad Esfahbod, 2001, 2002, 2004
7 * Copyright (C) 2004 Sharif FarsiWeb, Inc
8 * Copyright (C) 2001,2002,2004 Behdad Esfahbod
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library, in a file named COPYING; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA
25 * For licensing issues, contact <fribidi.license@gmail.com>.
30 #include <fribidi-unicode.h>
46 # if !STDC_HEADERS && HAVE_MEMORY_H
57 #define appname "gen-bidi-type-tab"
58 #define outputname "bidi-type.tab.i"
65 fprintf (stderr, appname ": %s\n", msg);
75 fprintf (stderr, appname ": ");
76 fprintf (stderr, fmt, p);
77 fprintf (stderr, "\n");
88 fprintf (stderr, appname ": ");
89 fprintf (stderr, fmt, l, p);
90 fprintf (stderr, "\n");
94 enum FriBidiCharTypeLinearEnumOffsetOne
96 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE,
97 # define _FRIBIDI_ADD_ALIAS(TYPE1,TYPE2) TYPE1 = TYPE2,
98 # include <fribidi-bidi-types-list.h>
99 # undef _FRIBIDI_ADD_ALIAS
100 # undef _FRIBIDI_ADD_TYPE
111 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) {STRINGIZE(TYPE), TYPE},
112 # define _FRIBIDI_ADD_ALIAS(TYPE1,TYPE2) _FRIBIDI_ADD_TYPE(TYPE1, SYMBOL)
113 # include <fribidi-bidi-types-list.h>
114 # undef _FRIBIDI_ADD_ALIAS
115 # undef _FRIBIDI_ADD_TYPE
118 #define type_names_count (sizeof (type_names) / sizeof (type_names[0]))
120 static const char *names[type_names_count];
129 for (i = 0; i < type_names_count; i++)
130 if (!strcmp (s, type_names[i].name))
131 return type_names[i].key;
132 die2 ("bidi type name `%s' not found", s);
136 #define table_name "Bid"
137 #define macro_name "FRIBIDI_GET_BIDI_TYPE"
139 static signed int table[FRIBIDI_UNICODE_CHARS];
140 static char buf[4000];
141 static char tp[sizeof (buf)];
150 for (i = 0; i < type_names_count; i++)
152 for (i = type_names_count - 1; i >= 0; i--)
153 names[type_names[i].key] = type_names[i].name;
161 register FriBidiChar c;
163 for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
168 init_tab_unicode_data_txt (
172 register FriBidiChar c;
176 for (c = 0x0590; c < 0x0600; c++)
178 for (c = 0x07C0; c < 0x0900; c++)
180 for (c = 0xFB1D; c < 0xFB50; c++)
183 for (c = 0x0600; c < 0x07C0; c++)
185 for (c = 0xFB50; c < 0xFDD0; c++)
187 for (c = 0xFDF0; c < 0xFE00; c++)
189 for (c = 0xFE70; c < 0xFF00; c++)
192 for (c = 0x2060; c < 0x2070; c++)
194 for (c = 0xFDD0; c < 0xFDF0; c++)
196 for (c = 0xFFF0; c < 0xFFF9; c++)
198 for (c = 0xFFFF; c < FRIBIDI_UNICODE_CHARS; c += 0x10000)
199 table[c - 1] = table[c] = BN;
201 if (FRIBIDI_UNICODE_CHARS > 0x10000)
203 for (c = 0x10800; c < 0x11000; c++)
206 for (c = 0xE0000; c < 0xE1000; c++)
212 init_tab_derived_bidi_class_txt (
220 read_unicode_data_txt (
226 init_tab_unicode_data_txt ();
229 while (fgets (buf, sizeof buf, f))
239 if (s[0] == '#' || s[0] == '\0' || s[0] == '\n')
242 i = sscanf (s, "%lx;%*[^;];%*[^;];%*[^;];%[^; ]", &c, tp);
243 if (i != 2 || c >= FRIBIDI_UNICODE_CHARS)
244 die3 ("invalid input at line %ld: %s", l, s);
246 /* FIXME: We don't handle First..Last parts of UnicodeData.txt,
247 * but it works, since all those are LTR. */
248 table[c] = get_type (tp);
253 read_derived_bidi_class_txt (
257 unsigned long c, c2, l;
259 init_tab_derived_bidi_class_txt ();
262 while (fgets (buf, sizeof buf, f))
273 if (s[0] == '#' || s[0] == '\0' || s[0] == '\n')
276 i = sscanf (s, "%lx ; %[^; ]", &c, tp);
280 i = sscanf (s, "%lx..%lx ; %[^; ]", &c, &c2, tp) - 1;
282 if (i != 2 || c > c2 || c2 >= FRIBIDI_UNICODE_CHARS)
283 die3 ("invalid input at line %ld: %s", l, s);
293 const char *data_file_type,
294 const char *data_file_name
299 if (!(f = fopen (data_file_name, "rt")))
300 die2 ("error: cannot open `%s' for reading", data_file_name);
302 if (!strcmp (data_file_type, "UnicodeData.txt"))
303 read_unicode_data_txt (f);
304 else if (!strcmp (data_file_type, "DerivedBidiClass.txt"))
305 read_derived_bidi_class_txt (f);
307 die2 ("error: unknown data-file type %s", data_file_type);
315 const char *data_file_type
318 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
319 FRIBIDI_VERSION ")\n" " * from the file %s of Unicode version "
320 FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type);
322 printf ("#define PACKTAB_UINT8 uint8_t\n"
323 "#define PACKTAB_UINT16 uint16_t\n"
324 "#define PACKTAB_UINT32 uint32_t\n\n");
327 (table, FRIBIDI_UNICODE_CHARS, 1, LTR, max_depth, 3, names,
328 "unsigned char", table_name, macro_name, stdout))
329 die ("error: insufficient memory, decrease max_depth");
331 printf ("#undef PACKTAB_UINT8\n"
332 "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n");
334 printf ("/* End of generated " outputname " */\n");
343 const char *data_file_type = "UnicodeData.txt";
346 die2 ("usage:\n " appname " max-depth /path/to/%s [junk...]",
350 int max_depth = atoi (argv[1]);
351 const char *data_file_name = argv[2];
354 die ("invalid depth");
357 read_data (data_file_type, data_file_name);
358 gen_bidi_type_tab (max_depth, data_file_type);