2 * gen-brackets-type-tab.c - generate brackets.tab.i
5 * Behdad Esfahbod, 2001, 2002, 2004
8 * Copyright (C) 2004 Sharif FarsiWeb, Inc
9 * Copyright (C) 2001,2002,2004 Behdad Esfahbod
10 * Copyright (C) 2017 Dov Grobgeld
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this library, in a file named COPYING; if not, write to the
24 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA
27 * For licensing issues, contact <fribidi.license@gmail.com>.
32 #include <fribidi-unicode.h>
48 # if !STDC_HEADERS && HAVE_MEMORY_H
59 #define appname "gen-brackets-type-tab"
60 #define outputname "brackets-type.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 "Brt"
98 #define macro_name "FRIBIDI_GET_BRACKET_TYPE"
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_brackets_type_txt (
132 read_bidi_brackets_type_txt (
138 init_tab_brackets_type_txt ();
141 while (fgets (buf, sizeof buf, f))
153 if (s[0] == '#' || s[0] == '\0' || s[0] == '\n')
156 k = sscanf (s, "%lx; %lx; %c", &i, &j, &open_close);
157 if (k != 3 || i >= FRIBIDI_UNICODE_CHARS || j >= FRIBIDI_UNICODE_CHARS)
158 die4 ("invalid pair in input at line %ld: %04lX, %04lX", l, i, j);
159 table[i] = 1 + (0x2 * (open_close=='o'));
165 const char *data_file_type,
166 const char *data_file_name
171 if (!(f = fopen (data_file_name, "rt")))
172 die2 ("error: cannot open `%s' for reading", data_file_name);
174 if (!strcmp (data_file_type, "BidiBrackets.txt"))
175 read_bidi_brackets_type_txt (f);
177 die2 ("error: unknown data-file-type %s", data_file_type);
185 const char *data_file_type
189 const char *key_type;
191 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
192 FRIBIDI_VERSION ")\n" " * from the file %s of Unicode version "
193 FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type);
195 printf ("#define PACKTAB_UINT8 uint8_t\n"
196 "#define PACKTAB_UINT16 uint16_t\n"
197 "#define PACKTAB_UINT32 uint32_t\n\n");
200 key_type = key_bytes == 1 ? "int8_t" : key_bytes == 2 ?
201 "int16_t" : "int32_t";
204 (table, FRIBIDI_UNICODE_CHARS, key_bytes, 0, max_depth, 1, NULL,
205 key_type, table_name, macro_name, stdout))
206 die ("error: insufficient memory, decrease max_depth");
208 printf ("#undef PACKTAB_UINT8\n"
209 "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n");
211 printf ("/* End of generated " outputname " */\n");
220 const char *data_file_type = "BidiBrackets.txt";
223 die2 ("usage:\n " appname " max-depth /path/to/%s [junk...]",
227 int max_depth = atoi (argv[1]);
228 const char *data_file_name = argv[2];
231 die ("invalid depth");
234 read_data (data_file_type, data_file_name);
235 gen_brackets_tab (max_depth, data_file_type);