2 * gen-joining-type-tab.c - generate joining-type.tab.i
5 * Behdad Esfahbod, 2004
7 * Copyright (C) 2004 Sharif FarsiWeb, Inc
8 * Copyright (C) 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>
42 # if !STDC_HEADERS && HAVE_MEMORY_H
53 #define appname "gen-joining-type-tab"
54 #define outputname "joining-type.tab.i"
61 fprintf (stderr, appname ": %s\n", msg);
71 fprintf (stderr, appname ": ");
72 fprintf (stderr, fmt, p);
73 fprintf (stderr, "\n");
84 fprintf (stderr, appname ": ");
85 fprintf (stderr, fmt, p, q);
86 fprintf (stderr, "\n");
97 fprintf (stderr, appname ": ");
98 fprintf (stderr, fmt, l, p);
99 fprintf (stderr, "\n");
103 enum FriBidiJoiningLinearEnumOffsetOne
105 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE,
106 # include <fribidi-joining-types-list.h>
107 # undef _FRIBIDI_ADD_TYPE
118 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) {STRINGIZE(TYPE), TYPE},
119 # include <fribidi-joining-types-list.h>
120 # undef _FRIBIDI_ADD_TYPE
123 #define type_names_count (sizeof (type_names) / sizeof (type_names[0]))
125 static const char *names[type_names_count];
134 for (i = 0; i < type_names_count; i++)
135 if (!strcmp (s, type_names[i].name))
136 return type_names[i].key;
137 die2 ("joining type name `%s' not found", s);
141 static const char *ignored_bidi_types[] = {
155 static const char *transparent_general_categories[] = {
165 const char *type_list[]
168 for (; type_list[0]; type_list++)
169 if (!strcmp (s, type_list[0]))
174 #define table_name "Joi"
175 #define macro_name "FRIBIDI_GET_JOINING_TYPE"
177 static signed int table[FRIBIDI_UNICODE_CHARS];
178 static char buf[4000];
179 static char tp[sizeof (buf)], tp_gen[sizeof (buf)], tp_bidi[sizeof (buf)];
186 register FriBidiChar c;
188 for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
199 for (i = 0; i < type_names_count; i++)
201 for (i = type_names_count - 1; i >= 0; i--)
202 names[type_names[i].key] = type_names[i].name;
208 read_unicode_data_txt (
215 while (fgets (buf, sizeof buf, f))
225 if (*s == '#' || *s == '\0' || *s == '\n')
228 i = sscanf (s, "%lx;%*[^;];%[^; ];%*[^;];%[^; ]", &c, tp_gen, tp_bidi);
229 if (i != 3 || c >= FRIBIDI_UNICODE_CHARS)
230 die3l ("UnicodeData.txt: invalid input at line %ld: %s", l, s);
232 if (type_is (tp_bidi, ignored_bidi_types))
234 if (type_is (tp_gen, transparent_general_categories))
240 read_arabic_shaping_txt (
244 unsigned long c, c2, l;
247 while (fgets (buf, sizeof buf, f))
258 if (*s == '#' || *s == '\0' || *s == '\n')
261 i = sscanf (s, "%lx ; %*[^;]; %[^; ]", &c, tp);
265 i = sscanf (s, "%lx..%lx ; %*[^;]; %[^; ]", &c, &c2, tp) - 1;
267 if (i != 2 || c > c2 || c2 >= FRIBIDI_UNICODE_CHARS)
268 die3l ("ArabicShaping.txt: invalid input at line %ld: %s", l, s);
278 const char *data_file_type[],
279 const char *data_file_name[]
284 for (; data_file_name[0] && data_file_type[0];
285 data_file_name++, data_file_type++)
287 if (!(f = fopen (data_file_name[0], "rt")))
288 die2 ("error: cannot open `%s' for reading", data_file_name[0]);
290 if (!strcmp (data_file_type[0], "UnicodeData.txt"))
291 read_unicode_data_txt (f);
292 else if (!strcmp (data_file_type[0], "ArabicShaping.txt"))
293 read_arabic_shaping_txt (f);
295 die2 ("error: unknown data-file type %s", data_file_type[0]);
303 gen_joining_type_tab (
305 const char *data_file_type[]
308 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
309 FRIBIDI_VERSION ")\n" " * from the files %s, %s of Unicode version "
310 FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type[0],
313 printf ("#define PACKTAB_UINT8 uint8_t\n"
314 "#define PACKTAB_UINT16 uint16_t\n"
315 "#define PACKTAB_UINT32 uint32_t\n\n");
318 (table, FRIBIDI_UNICODE_CHARS, 1, U, max_depth, 1, names,
319 "unsigned char", table_name, macro_name, stdout))
320 die ("error: insufficient memory, decrease max_depth");
322 printf ("#undef PACKTAB_UINT8\n"
323 "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n");
325 printf ("/* End of generated " outputname " */\n");
334 const char *data_file_type[] =
335 { "UnicodeData.txt", "ArabicShaping.txt", NULL };
338 die3 ("usage:\n " appname " max-depth /path/to/%s /path/to/%s [junk...]",
339 data_file_type[0], data_file_type[1]);
342 int max_depth = atoi (argv[1]);
343 const char *data_file_name[] = { NULL, NULL, NULL };
344 data_file_name[0] = argv[2];
345 data_file_name[1] = argv[3];
348 die ("invalid depth");
351 read_data (data_file_type, data_file_name);
352 gen_joining_type_tab (max_depth, data_file_type);