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>
46 # if !STDC_HEADERS && HAVE_MEMORY_H
57 #define appname "gen-joining-type-tab"
58 #define outputname "joining-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, p, q);
90 fprintf (stderr, "\n");
101 fprintf (stderr, appname ": ");
102 fprintf (stderr, fmt, l, p);
103 fprintf (stderr, "\n");
107 enum FriBidiJoiningLinearEnumOffsetOne
109 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE,
110 # include <fribidi-joining-types-list.h>
111 # undef _FRIBIDI_ADD_TYPE
122 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) {STRINGIZE(TYPE), TYPE},
123 # include <fribidi-joining-types-list.h>
124 # undef _FRIBIDI_ADD_TYPE
127 #define type_names_count (sizeof (type_names) / sizeof (type_names[0]))
129 static const char *names[type_names_count];
138 for (i = 0; i < type_names_count; i++)
139 if (!strcmp (s, type_names[i].name))
140 return type_names[i].key;
141 die2 ("joining type name `%s' not found", s);
145 static const char *ignored_bidi_types[] = {
159 static const char *transparent_general_categories[] = {
169 const char *type_list[]
172 for (; type_list[0]; type_list++)
173 if (!strcmp (s, type_list[0]))
178 #define table_name "Joi"
179 #define macro_name "FRIBIDI_GET_JOINING_TYPE"
181 static signed int table[FRIBIDI_UNICODE_CHARS];
182 static char buf[4000];
183 static char tp[sizeof (buf)], tp_gen[sizeof (buf)], tp_bidi[sizeof (buf)];
190 register FriBidiChar c;
192 for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
203 for (i = 0; i < type_names_count; i++)
205 for (i = type_names_count - 1; i >= 0; i--)
206 names[type_names[i].key] = type_names[i].name;
212 read_unicode_data_txt (
219 while (fgets (buf, sizeof buf, f))
229 if (*s == '#' || *s == '\0' || *s == '\n')
232 i = sscanf (s, "%lx;%*[^;];%[^; ];%*[^;];%[^; ]", &c, tp_gen, tp_bidi);
233 if (i != 3 || c >= FRIBIDI_UNICODE_CHARS)
234 die3l ("UnicodeData.txt: invalid input at line %ld: %s", l, s);
236 if (type_is (tp_bidi, ignored_bidi_types))
238 if (type_is (tp_gen, transparent_general_categories))
244 read_arabic_shaping_txt (
248 unsigned long c, c2, l;
251 while (fgets (buf, sizeof buf, f))
262 if (*s == '#' || *s == '\0' || *s == '\n')
265 i = sscanf (s, "%lx ; %*[^;]; %[^; ]", &c, tp);
269 i = sscanf (s, "%lx..%lx ; %*[^;]; %[^; ]", &c, &c2, tp) - 1;
271 if (i != 2 || c > c2 || c2 >= FRIBIDI_UNICODE_CHARS)
272 die3l ("ArabicShaping.txt: invalid input at line %ld: %s", l, s);
282 const char *data_file_type[],
283 const char *data_file_name[]
288 for (; data_file_name[0] && data_file_type[0];
289 data_file_name++, data_file_type++)
291 if (!(f = fopen (data_file_name[0], "rt")))
292 die2 ("error: cannot open `%s' for reading", data_file_name[0]);
294 if (!strcmp (data_file_type[0], "UnicodeData.txt"))
295 read_unicode_data_txt (f);
296 else if (!strcmp (data_file_type[0], "ArabicShaping.txt"))
297 read_arabic_shaping_txt (f);
299 die2 ("error: unknown data-file type %s", data_file_type[0]);
307 gen_joining_type_tab (
309 const char *data_file_type[]
312 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
313 FRIBIDI_VERSION ")\n" " * from the files %s, %s of Unicode version "
314 FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type[0],
317 printf ("#define PACKTAB_UINT8 uint8_t\n"
318 "#define PACKTAB_UINT16 uint16_t\n"
319 "#define PACKTAB_UINT32 uint32_t\n\n");
322 (table, FRIBIDI_UNICODE_CHARS, 1, U, max_depth, 1, names,
323 "unsigned char", table_name, macro_name, stdout))
324 die ("error: insufficient memory, decrease max_depth");
326 printf ("#undef PACKTAB_UINT8\n"
327 "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n");
329 printf ("/* End of generated " outputname " */\n");
338 const char *data_file_type[] =
339 { "UnicodeData.txt", "ArabicShaping.txt", NULL };
342 die3 ("usage:\n " appname " max-depth /path/to/%s /path/to/%s [junk...]",
343 data_file_type[0], data_file_type[1]);
346 int max_depth = atoi (argv[1]);
347 const char *data_file_name[] = { NULL, NULL, NULL };
348 data_file_name[0] = argv[2];
349 data_file_name[1] = argv[3];
352 die ("invalid depth");
355 read_data (data_file_type, data_file_name);
356 gen_joining_type_tab (max_depth, data_file_type);