2 * gen-mirroring-tab.c - generate mirroring.tab.i
4 * $Id: gen-mirroring-tab.c,v 1.14 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-mirroring-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., 59 Temple Place, Suite 330,
29 * Boston, MA 02111-1307, 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-mirroring-tab"
60 #define outputname "mirroring.tab.i"
67 fprintf (stderr, appname ": %s\n", msg);
77 fprintf (stderr, appname ": ");
78 fprintf (stderr, fmt, p);
79 fprintf (stderr, "\n");
91 fprintf (stderr, appname ": ");
92 fprintf (stderr, fmt, l, p, q);
93 fprintf (stderr, "\n");
97 #define table_name "Mir"
98 #define macro_name "FRIBIDI_GET_MIRRORING"
100 static signed int table[FRIBIDI_UNICODE_CHARS];
101 static char buf[4000];
102 static signed long max_dist;
117 register FriBidiChar c;
119 for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
124 init_tab_mirroring_txt (
132 read_bidi_mirroring_txt (
138 init_tab_mirroring_txt ();
141 while (fgets (buf, sizeof buf, f))
153 if (s[0] == '#' || s[0] == '\0' || s[0] == '\n')
156 k = sscanf (s, "%lx; %lx", &i, &j);
157 if (k != 2 || i >= FRIBIDI_UNICODE_CHARS || j >= FRIBIDI_UNICODE_CHARS)
158 die4 ("invalid pair in input at line %ld: %04lX, %04lX", l, i, j);
159 dist = ((signed long) j - (signed long) i);
163 else if (-dist > max_dist)
170 const char *data_file_type,
171 const char *data_file_name
176 fprintf (stderr, "Reading `%s'\n", data_file_name);
177 if (!(f = fopen (data_file_name, "rt")))
178 die2 ("error: cannot open `%s' for reading", data_file_name);
180 if (!strcmp (data_file_type, "BidiMirroring.txt"))
181 read_bidi_mirroring_txt (f);
183 die2 ("error: unknown data-file-type %s", data_file_type);
191 const char *data_file_type
195 const char *key_type;
198 "Generating `" outputname "', it may take up to a few minutes\n");
199 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
200 FRIBIDI_VERSION ")\n" " * from the file %s of Unicode version "
201 FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type);
203 printf ("#define PACKTAB_UINT8 fribidi_uint8\n"
204 "#define PACKTAB_UINT16 fribidi_uint16\n"
205 "#define PACKTAB_UINT32 fribidi_uint32\n\n");
207 key_bytes = max_dist <= 0x7f ? 1 : max_dist < 0x7fff ? 2 : 4;
208 key_type = key_bytes == 1 ? "fribidi_int8" : key_bytes == 2 ?
209 "fribidi_int16" : "fribidi_int32";
212 (table, FRIBIDI_UNICODE_CHARS, key_bytes, 0, max_depth, 1, NULL,
213 key_type, table_name, macro_name "_DELTA", stdout))
214 die ("error: insufficient memory, decrease max_depth");
216 printf ("#undef PACKTAB_UINT8\n"
217 "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n");
219 printf ("#define " macro_name "(x) ((x) + " macro_name "_DELTA(x))\n\n");
221 printf ("/* End of generated " outputname " */\n");
230 const char *data_file_type = "BidiMirroring.txt";
233 die2 ("usage:\n " appname " max-depth /path/to/%s [junk...]",
237 int max_depth = atoi (argv[1]);
238 const char *data_file_name = argv[2];
241 die ("invalid depth");
244 read_data (data_file_type, data_file_name);
245 gen_mirroring_tab (max_depth, data_file_type);