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>
44 # if !STDC_HEADERS && HAVE_MEMORY_H
55 #define appname "gen-brackets-type-tab"
56 #define outputname "brackets-type.tab.i"
63 fprintf (stderr, appname ": %s\n", msg);
73 fprintf (stderr, appname ": ");
74 fprintf (stderr, fmt, p);
75 fprintf (stderr, "\n");
87 fprintf (stderr, appname ": ");
88 fprintf (stderr, fmt, l, p, q);
89 fprintf (stderr, "\n");
93 #define table_name "Brt"
94 #define macro_name "FRIBIDI_GET_BRACKET_TYPE"
96 static signed int table[FRIBIDI_UNICODE_CHARS];
97 static char buf[4000];
98 static signed long max_dist;
113 register FriBidiChar c;
115 for (c = 0; c < FRIBIDI_UNICODE_CHARS; c++)
120 init_tab_brackets_type_txt (
128 read_bidi_brackets_type_txt (
134 init_tab_brackets_type_txt ();
137 while (fgets (buf, sizeof buf, f))
149 if (s[0] == '#' || s[0] == '\0' || s[0] == '\n')
152 k = sscanf (s, "%lx; %lx; %c", &i, &j, &open_close);
153 if (k != 3 || i >= FRIBIDI_UNICODE_CHARS || j >= FRIBIDI_UNICODE_CHARS)
154 die4 ("invalid pair in input at line %ld: %04lX, %04lX", l, i, j);
155 table[i] = 1 + (0x2 * (open_close=='o'));
161 const char *data_file_type,
162 const char *data_file_name
167 if (!(f = fopen (data_file_name, "rt")))
168 die2 ("error: cannot open `%s' for reading", data_file_name);
170 if (!strcmp (data_file_type, "BidiBrackets.txt"))
171 read_bidi_brackets_type_txt (f);
173 die2 ("error: unknown data-file-type %s", data_file_type);
181 const char *data_file_type
185 const char *key_type;
187 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
188 FRIBIDI_VERSION ")\n" " * from the file %s of Unicode version "
189 FRIBIDI_UNICODE_VERSION ". */\n\n", data_file_type);
191 printf ("#define PACKTAB_UINT8 uint8_t\n"
192 "#define PACKTAB_UINT16 uint16_t\n"
193 "#define PACKTAB_UINT32 uint32_t\n\n");
196 key_type = key_bytes == 1 ? "int8_t" : key_bytes == 2 ?
197 "int16_t" : "int32_t";
200 (table, FRIBIDI_UNICODE_CHARS, key_bytes, 0, max_depth, 1, NULL,
201 key_type, table_name, macro_name, stdout))
202 die ("error: insufficient memory, decrease max_depth");
204 printf ("#undef PACKTAB_UINT8\n"
205 "#undef PACKTAB_UINT16\n" "#undef PACKTAB_UINT32\n\n");
207 printf ("/* End of generated " outputname " */\n");
216 const char *data_file_type = "BidiBrackets.txt";
219 die2 ("usage:\n " appname " max-depth /path/to/%s [junk...]",
223 int max_depth = atoi (argv[1]);
224 const char *data_file_name = argv[2];
227 die ("invalid depth");
230 read_data (data_file_type, data_file_name);
231 gen_brackets_tab (max_depth, data_file_type);