2 * gen-bidi-type-tab.c - generate bidi-type.tab.i
4 * $Id: gen-bidi-type-tab.c,v 1.18 2006-01-31 03:23:12 behdad Exp $
6 * $Date: 2006-01-31 03:23:12 $
8 * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/gen.tab/gen-bidi-type-tab.c,v $
11 * Behdad Esfahbod, 2001, 2002, 2004
13 * Copyright (C) 2004 Sharif FarsiWeb, Inc
14 * Copyright (C) 2001,2002,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-bidi-type-tab"
60 #define outputname "bidi-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, l, p);
92 fprintf (stderr, "\n");
96 enum FriBidiCharTypeLinearEnumOffsetOne
98 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE,
99 # define _FRIBIDI_ADD_ALIAS(TYPE1,TYPE2) TYPE1 = TYPE2,
100 # include <fribidi-bidi-types-list.h>
101 # undef _FRIBIDI_ADD_ALIAS
102 # undef _FRIBIDI_ADD_TYPE
113 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) {STRINGIZE(TYPE), TYPE},
114 # define _FRIBIDI_ADD_ALIAS(TYPE1,TYPE2) _FRIBIDI_ADD_TYPE(TYPE1, SYMBOL)
115 # include <fribidi-bidi-types-list.h>
116 # undef _FRIBIDI_ADD_ALIAS
117 # undef _FRIBIDI_ADD_TYPE
120 #define type_names_count (sizeof (type_names) / sizeof (type_names[0]))
122 static const char *names[type_names_count];
131 for (i = 0; i < type_names_count; i++)
132 if (!strcmp (s, type_names[i].name))
133 return type_names[i].key;
134 die2 ("bidi type name `%s' not found", s);
138 #define table_name "Bid"
139 #define macro_name "FRIBIDI_GET_BIDI_TYPE"
141 static signed int table[FRIBIDI_UNICODE_CHARS];
142 static char buf[4000];
143 static char tp[sizeof (buf)];
152 for (i = 0; i < type_names_count; i++)
154 for (i = type_names_count - 1; i >= 0; i--)
155 names[type_names[i].key] = type_names[i].name;
163 register FriBidiChar c;
165 for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
170 init_tab_unicode_data_txt (
174 register FriBidiChar c;
178 for (c = 0x0590; c < 0x0600; c++)
180 for (c = 0x07C0; c < 0x0900; c++)
182 for (c = 0xFB1D; c < 0xFB50; c++)
185 for (c = 0x0600; c < 0x07C0; c++)
187 for (c = 0xFB50; c < 0xFDD0; c++)
189 for (c = 0xFDF0; c < 0xFE00; c++)
191 for (c = 0xFE70; c < 0xFF00; c++)
194 for (c = 0x2060; c < 0x2070; c++)
196 for (c = 0xFDD0; c < 0xFDF0; c++)
198 for (c = 0xFFF0; c < 0xFFF9; c++)
200 for (c = 0xFFFF; c < FRIBIDI_UNICODE_CHARS; c += 0x10000)
201 table[c - 1] = table[c] = BN;
203 if (FRIBIDI_UNICODE_CHARS > 0x10000)
205 for (c = 0x10800; c < 0x11000; c++)
208 for (c = 0xE0000; c < 0xE1000; c++)
214 init_tab_derived_bidi_class_txt (
222 read_unicode_data_txt (
228 init_tab_unicode_data_txt ();
231 while (fgets (buf, sizeof buf, f))
241 if (s[0] == '#' || s[0] == '\0' || s[0] == '\n')
244 i = sscanf (s, "%lx;%*[^;];%*[^;];%*[^;];%[^; ]", &c, tp);
245 if (i != 2 || c >= FRIBIDI_UNICODE_CHARS)
246 die3 ("invalid input at line %ld: %s", l, s);
248 /* FIXME: We don't handle First..Last parts of UnicodeData.txt,
249 * but it works, since all those are LTR. */
250 table[c] = get_type (tp);
255 read_derived_bidi_class_txt (
259 unsigned long c, c2, l;
261 init_tab_derived_bidi_class_txt ();
264 while (fgets (buf, sizeof buf, f))
275 if (s[0] == '#' || s[0] == '\0' || s[0] == '\n')
278 i = sscanf (s, "%lx ; %[^; ]", &c, tp);
282 i = sscanf (s, "%lx..%lx ; %[^; ]", &c, &c2, tp) - 1;
284 if (i != 2 || c > c2 || c2 >= FRIBIDI_UNICODE_CHARS)
285 die3 ("invalid input at line %ld: %s", l, s);
295 const char *data_file_type,
296 const char *data_file_name
301 fprintf (stderr, "Reading `%s'\n", data_file_name);
302 if (!(f = fopen (data_file_name, "rt")))
303 die2 ("error: cannot open `%s' for reading", data_file_name);
305 if (!strcmp (data_file_type, "UnicodeData.txt"))
306 read_unicode_data_txt (f);
307 else if (!strcmp (data_file_type, "DerivedBidiClass.txt"))
308 read_derived_bidi_class_txt (f);
310 die2 ("error: unknown data-file type %s", data_file_type);
318 const char *data_file_type
322 "Generating `" outputname "', it may take up to a few minutes\n");
323 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
324 FRIBIDI_VERSION ")\n" " * from the file %s of Unicode version "
325 FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type);
327 printf ("#define PACKTAB_UINT8 fribidi_uint8\n"
328 "#define PACKTAB_UINT16 fribidi_uint16\n"
329 "#define PACKTAB_UINT32 fribidi_uint32\n\n");
332 (table, FRIBIDI_UNICODE_CHARS, 1, LTR, max_depth, 3, names,
333 "unsigned char", table_name, macro_name, stdout))
334 die ("error: insufficient memory, decrease max_depth");
336 printf ("#undef PACKTAB_UINT8\n"
337 "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n");
339 printf ("/* End of generated " outputname " */\n");
348 const char *data_file_type = "UnicodeData.txt";
351 die2 ("usage:\n " appname " max-depth /path/to/%s [junk...]",
355 int max_depth = atoi (argv[1]);
356 const char *data_file_name = argv[2];
359 die ("invalid depth");
362 read_data (data_file_type, data_file_name);
363 gen_bidi_type_tab (max_depth, data_file_type);