1
/* FriBidi - Library of BiDi algorithm
2
* Copyright (C) 2001,2002 Behdad Esfahbod.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this library, in a file named COPYING; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
17
* Boston, MA 02111-1307, USA
19
* For licensing issues, contact <fwpg@sharif.edu>.
29
#include "fribidi_unicode.h"
34
fprintf (stderr, "fribidi_create_char_types: %s\n", msg);
39
err2 (const char *fmt, const char *p)
41
fprintf (stderr, "fribidi_create_char_types: ");
42
fprintf (stderr, fmt, p);
43
fprintf (stderr, "\n");
72
{"SS", 17}, {"S", 17},
77
#define type_names_count (sizeof (type_names) / sizeof (type_names[0]))
79
static char *names[type_names_count];
81
static char *unidata_file;
84
get_type (const char *s)
88
for (i = 0; i < type_names_count; i++)
89
if (!strcmp (s, type_names[i].name))
90
return type_names[i].key;
91
err2 ("type name `%s' not found", s);
95
#define table_name "FriBidiPropertyBlock"
96
#define key_type_name "FriBidiPropCharType"
97
#define macro_name "FRIBIDI_GET_TYPE"
98
#define function_name "fribidi_get_type_internal"
99
#define char_type_name "FriBidiCharType"
100
#define char_name "FriBidiChar"
101
#define prop_to_type_name "fribidi_prop_to_type"
102
#define default_type "LTR"
103
#define export_api "FRIBIDI_API"
105
static int table[FRIBIDI_UNICODE_CHARS];
111
register FriBidiChar c;
112
int deftype = get_type (default_type),
113
RTL = get_type ("RTL"), AL = get_type ("AL"), BN = get_type ("BN");
115
for (i = 0; i < type_names_count; i++)
117
for (i = type_names_count - 1; i >= 0; i--)
118
names[type_names[i].key] = type_names[i].name;
120
/* initialize table */
121
for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
124
for (c = 0x0590; c < 0x0600; c++)
126
for (c = 0x07C0; c < 0x0900; c++)
128
for (c = 0xFB1D; c < 0xFB50; c++)
131
for (c = 0x0600; c < 0x07C0; c++)
133
for (c = 0xFB50; c < 0xFDD0; c++)
135
for (c = 0xFDF0; c < 0xFE00; c++)
137
for (c = 0xFE70; c < 0xFF00; c++)
140
for (c = 0x2060; c < 0x2070; c++)
142
for (c = 0xFDD0; c < 0xFDF0; c++)
144
for (c = 0xFFF0; c < 0xFFF9; c++)
146
for (c = 0xFFFF; c < FRIBIDI_UNICODE_CHARS; c += 0x10000)
147
table[c - 1] = table[c] = BN;
149
if (FRIBIDI_UNICODE_CHARS > 0x10000)
151
for (c = 0x10800; c < 0x11000; c++)
154
for (c = 0xE0000; c < 0xE1000; c++)
160
read_unicode_data (void)
166
printf ("Reading `UnicodeData.txt'\n");
167
if (!(f = fopen (unidata_file, "rt")))
168
err2 ("error: cannot open `%s' for reading", unidata_file);
169
while (fgets (s, sizeof s, f))
171
sscanf (s, "%x;%*[^;];%*[^;];%*[^;];%[^;]", &i, tp);
172
table[i] = get_type (tp);
178
headermacro (const char *file)
180
char *t = strdup (file);
184
if (*p >= 'a' && *p <= 'z')
186
else if ((*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9'))
194
write_char_type (const char *file, int max_depth)
198
char *FILENAME = headermacro (file);
200
printf ("Writing `%s', it may take a few minutes\n", file);
201
if (!(f = fopen (file, "wt")))
202
err2 ("error: cannot open `%s' for writing", file);
204
" This file was automatically created from UnicodeData.txt version %s\n"
205
" by fribidi_create_char_types\n*/\n\n", FRIBIDI_UNICODE_VERSION);
207
fprintf (f, "#ifndef %s\n#define %s\n\n#include \"fribidi.h\"\n\n",
210
for (i = 0; i < type_names_count; i++)
212
fprintf (f, "#define %s FRIBIDI_PROP_TYPE_%s\n", names[i], names[i]);
215
fprintf (f, "#define PACKTAB_UINT8 fribidi_uint8\n");
216
fprintf (f, "#define PACKTAB_UINT16 fribidi_uint16\n");
217
fprintf (f, "#define PACKTAB_UINT32 fribidi_uint32\n");
220
(table, FRIBIDI_UNICODE_CHARS, sizeof (char), max_depth, 3, names,
221
key_type_name, table_name, macro_name, f))
222
err ("error: insufficient memory, decrease max_depth");
224
for (i = type_names_count - 1; i >= 0; i--)
226
fprintf (f, "#undef %s\n", names[i]);
229
"/*======================================================================\n"
230
" * %s() returns the bidi type of a character.\n"
231
" *----------------------------------------------------------------------*/\n"
236
" return %s[(unsigned char)%s (uch)];\n"
238
" return FRIBIDI_TYPE_%s;\n"
239
" /* Non-Unicode chars */\n"
242
function_name, export_api, char_type_name, function_name,
243
char_name, FRIBIDI_UNICODE_CHARS, prop_to_type_name, macro_name,
245
fprintf (f, "\n#endif /* %s */\n", FILENAME);
251
main (int argc, char **argv)
256
err ("usage: fribidi_create_char_types max_depth [UnicodeData.txt path]");
257
p = (argc >= 3) ? argv[2] : "unidata";
258
unidata_file = malloc (50 + strlen (p));
259
sprintf (unidata_file, "%s/UnicodeData.txt", p);
260
max_depth = atoi (argv[1]);
262
err ("invalid depth");
263
if (max_depth < 2 || max_depth > 9)
264
err2 ("invalid max_depth `%s', max_depth should be between 2 and 9",
266
sprintf (file, "fribidi_tab_char_type_%d.i", max_depth);
268
read_unicode_data ();
269
write_char_type (file, max_depth);