2 * gen-unicode-version.c - generate fribidi-unicode-version.h
4 * $Id: gen-unicode-version.c,v 1.12 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-unicode-version.c,v $
11 * Behdad Esfahbod, 2001, 2002, 2004
13 * Copyright (C) 2004 Sharif FarsiWeb, Inc
14 * Copyright (C) 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>.
46 # if !STDC_HEADERS && HAVE_MEMORY_H
57 #define appname "gen-unicode-version"
58 #define outputname "fribidi-unicode-version.h"
65 fprintf (stderr, appname ": %s\n", msg);
75 fprintf (stderr, appname ": ");
76 fprintf (stderr, fmt, p);
77 fprintf (stderr, "\n");
81 int version_major, version_minor, version_micro;
82 char unicode_version[100];
90 version_major = version_minor = version_micro = 0;
91 strcpy (unicode_version, "(unknown)");
94 #define READ_VERSION(prefix) ((where = strstr(buf, prefix)) && \
95 (3 == sscanf (where, \
96 prefix"%d.%d.%d", &version_major, &version_minor, &version_micro)))
107 while (fgets (buf, sizeof buf, f))
111 if (READ_VERSION ("Version ") || READ_VERSION ("Unicode "))
121 sprintf (unicode_version, "%d.%d.%d", version_major, version_minor,
128 const char *data_file_type,
129 const char *data_file_name
135 fprintf (stderr, "Reading `%s'\n", data_file_name);
136 if (!(f = fopen (data_file_name, "rt")))
137 die2 ("error: cannot open `%s' for reading", data_file_name);
139 status = read_file (f);
147 gen_unicode_version (
148 const char *data_file_type
151 fprintf (stderr, "Generating `" outputname "'\n");
152 printf ("/* " outputname "\n * generated by " appname " (" FRIBIDI_NAME " "
153 FRIBIDI_VERSION ")\n" " * from the file %s */\n\n", data_file_type);
155 printf ("#define FRIBIDI_UNICODE_VERSION \"%s\"\n"
156 "#define FRIBIDI_UNICODE_MAJOR_VERSION %d\n"
157 "#define FRIBIDI_UNICODE_MINOR_VERSION %d\n"
158 "#define FRIBIDI_UNICODE_MICRO_VERSION %d\n"
159 "#define FRIBIDI_UNICODE_NAMESPACE(SYMBOL) \\\n"
160 " FRIBIDI_NAMESPACE(SYMBOL##_unicode_%d_%d_%d)\n"
161 "#define FRIBIDI_UNICODE_PRIVATESPACE(SYMBOL) \\\n"
162 " FRIBIDI_PRIVATESPACE(SYMBOL##_unicode_%d_%d_%d)\n"
165 version_major, version_minor, version_micro,
166 version_major, version_minor, version_micro,
167 version_major, version_minor, version_micro);
169 printf ("/* End of generated " outputname " */\n");
178 const char *data_file_type;
183 die ("usage:\n " appname
184 " /path/to/a/UCD/file [/path/to/more/UCD/files ...]");
187 const char *data_file_name;
190 for (i = 1; i < argc && !found; i++)
192 data_file_name = argv[i];
193 data_file_type = strrchr (data_file_name, '/');
197 data_file_type = data_file_name;
198 found = read_data (data_file_type, data_file_name);
201 die ("error: version not found");
202 gen_unicode_version (data_file_type);