2 * gen-joining-type-tab.c - generate joining-type.tab.i
4 * $Id: gen-joining-type-tab.c,v 1.7 2010-12-07 19:44:26 behdad Exp $
6 * $Date: 2010-12-07 19:44:26 $
8 * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/gen.tab/gen-joining-type-tab.c,v $
11 * Behdad Esfahbod, 2004
13 * Copyright (C) 2004 Sharif FarsiWeb, Inc
14 * Copyright (C) 2004 Behdad Esfahbod
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public License
27 * along with this library, in a file named COPYING; if not, write to the
28 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 * Boston, MA 02110-1301, USA
31 * For licensing issues, contact <license@farsiweb.info>.
36 #include <fribidi-unicode.h>
48 # if !STDC_HEADERS && HAVE_MEMORY_H
59 #define appname "gen-joining-type-tab"
60 #define outputname "joining-type.tab.i"
67 fprintf (stderr, appname ": %s\n", msg);
77 fprintf (stderr, appname ": ");
78 fprintf (stderr, fmt, p);
79 fprintf (stderr, "\n");
90 fprintf (stderr, appname ": ");
91 fprintf (stderr, fmt, p, q);
92 fprintf (stderr, "\n");
103 fprintf (stderr, appname ": ");
104 fprintf (stderr, fmt, l, p);
105 fprintf (stderr, "\n");
109 enum FriBidiJoiningLinearEnumOffsetOne
111 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE,
112 # include <fribidi-joining-types-list.h>
113 # undef _FRIBIDI_ADD_TYPE
124 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) {STRINGIZE(TYPE), TYPE},
125 # include <fribidi-joining-types-list.h>
126 # undef _FRIBIDI_ADD_TYPE
129 #define type_names_count (sizeof (type_names) / sizeof (type_names[0]))
131 static const char *names[type_names_count];
140 for (i = 0; i < type_names_count; i++)
141 if (!strcmp (s, type_names[i].name))
142 return type_names[i].key;
143 die2 ("joining type name `%s' not found", s);
147 static const char *ignored_bidi_types[] = {
157 static const char *transparent_general_categories[] = {
167 const char *type_list[]
170 for (; type_list[0]; type_list++)
171 if (!strcmp (s, type_list[0]))
176 #define table_name "Joi"
177 #define macro_name "FRIBIDI_GET_JOINING_TYPE"
179 static signed int table[FRIBIDI_UNICODE_CHARS];
180 static char buf[4000];
181 static char tp[sizeof (buf)], tp_gen[sizeof (buf)], tp_bidi[sizeof (buf)];
188 register FriBidiChar c;
190 for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
201 for (i = 0; i < type_names_count; i++)
203 for (i = type_names_count - 1; i >= 0; i--)
204 names[type_names[i].key] = type_names[i].name;
210 read_unicode_data_txt (
217 while (fgets (buf, sizeof buf, f))
227 if (*s == '#' || *s == '\0' || *s == '\n')
230 i = sscanf (s, "%lx;%*[^;];%[^; ];%*[^;];%[^; ]", &c, tp_gen, tp_bidi);
231 if (i != 3 || c >= FRIBIDI_UNICODE_CHARS)
232 die3l ("UnicodeData.txt: invalid input at line %ld: %s", l, s);
234 if (type_is (tp_bidi, ignored_bidi_types))
236 if (type_is (tp_gen, transparent_general_categories))
242 read_arabic_shaping_txt (
246 unsigned long c, c2, l;
249 while (fgets (buf, sizeof buf, f))
260 if (*s == '#' || *s == '\0' || *s == '\n')
263 i = sscanf (s, "%lx ; %*[^;]; %[^; ]", &c, tp);
267 i = sscanf (s, "%lx..%lx ; %*[^;]; %[^; ]", &c, &c2, tp) - 1;
269 if (i != 2 || c > c2 || c2 >= FRIBIDI_UNICODE_CHARS)
270 die3l ("ArabicShaping.txt: invalid input at line %ld: %s", l, s);
280 const char *data_file_type[],
281 const char *data_file_name[]
286 for (; data_file_name[0] && data_file_type[0];
287 data_file_name++, data_file_type++)
289 fprintf (stderr, "Reading `%s'\n", data_file_name[0]);
290 if (!(f = fopen (data_file_name[0], "rt")))
291 die2 ("error: cannot open `%s' for reading", data_file_name[0]);
293 if (!strcmp (data_file_type[0], "UnicodeData.txt"))
294 read_unicode_data_txt (f);
295 else if (!strcmp (data_file_type[0], "ArabicShaping.txt"))
296 read_arabic_shaping_txt (f);
298 die2 ("error: unknown data-file type %s", data_file_type[0]);
306 gen_joining_type_tab (
308 const char *data_file_type[]
312 "Generating `" outputname "', it may take up to a few minutes\n");
313 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
314 FRIBIDI_VERSION ")\n" " * from the files %s, %s of Unicode version "
315 FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type[0],
318 printf ("#define PACKTAB_UINT8 fribidi_uint8\n"
319 "#define PACKTAB_UINT16 fribidi_uint16\n"
320 "#define PACKTAB_UINT32 fribidi_uint32\n\n");
323 (table, FRIBIDI_UNICODE_CHARS, 1, U, max_depth, 1, names,
324 "unsigned char", table_name, macro_name, stdout))
325 die ("error: insufficient memory, decrease max_depth");
327 printf ("#undef PACKTAB_UINT8\n"
328 "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n");
330 printf ("/* End of generated " outputname " */\n");
339 const char *data_file_type[] =
340 { "UnicodeData.txt", "ArabicShaping.txt", NULL };
343 die3 ("usage:\n " appname " max-depth /path/to/%s /path/to/%s [junk...]",
344 data_file_type[0], data_file_type[1]);
347 int max_depth = atoi (argv[1]);
348 const char *data_file_name[] = { NULL, NULL, NULL };
349 data_file_name[0] = argv[2];
350 data_file_name[1] = argv[3];
353 die ("invalid depth");
356 read_data (data_file_type, data_file_name);
357 gen_joining_type_tab (max_depth, data_file_type);