1 /* Copyright (C) 1999-2001, 2003, 2005, 2008, 2012 Free Software Foundation, Inc.
2 This file is part of the GNU LIBICONV Library.
4 The GNU LIBICONV Library is free software; you can redistribute it
5 and/or modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 The GNU LIBICONV Library is distributed in the hope that it will be
10 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU LIBICONV Library; see the file COPYING.LIB.
16 If not, see <http://www.gnu.org/licenses/>. */
18 /* Creates the aliases.gperf table. */
23 static void emit_alias (FILE* out1, const char* alias, const char* c_name)
25 /* Output alias in upper case. */
26 const char* s = alias;
28 unsigned char c = * (unsigned char *) s;
31 if (c >= 'a' && c <= 'z')
35 fprintf(out1,", ei_%s\n", c_name);
38 static void emit_encoding (FILE* out1, FILE* out2, const char* const* names, size_t n, const char* c_name)
40 fprintf(out2,"grep 'sizeof(\"");
41 /* Output *names in upper case. */
43 const char* s = *names;
45 unsigned char c = * (unsigned char *) s;
48 if (c >= 'a' && c <= 'z')
53 fprintf(out2,"\")' tmp.h | sed -e 's|^.*\\(stringpool_str[0-9]*\\).*$| (int)(long)\\&((struct stringpool_t *)0)->\\1,|'\n");
54 for (; n > 0; names++, n--)
55 emit_alias(out1, *names, c_name);
58 int main (int argc, char* argv[])
60 char* aliases_file_name;
61 char* canonical_sh_file_name;
62 char* canonical_local_sh_file_name;
64 FILE* canonical_sh_file;
67 fprintf(stderr, "Usage: genaliases aliases.gperf canonical.sh canonical_local.sh\n");
71 aliases_file_name = argv[1];
72 canonical_sh_file_name = argv[2];
73 canonical_local_sh_file_name = argv[3];
75 aliases_file = fopen(aliases_file_name, "w");
76 if (aliases_file == NULL) {
77 fprintf(stderr, "Could not open '%s' for writing\n", aliases_file_name);
81 fprintf(aliases_file, "struct alias { int name; unsigned int encoding_index; };\n");
82 fprintf(aliases_file, "%%struct-type\n");
83 fprintf(aliases_file, "%%language=ANSI-C\n");
84 fprintf(aliases_file, "%%define hash-function-name aliases_hash\n");
85 fprintf(aliases_file, "%%define lookup-function-name aliases_lookup\n");
86 fprintf(aliases_file, "%%7bit\n");
87 fprintf(aliases_file, "%%readonly-tables\n");
88 fprintf(aliases_file, "%%global-table\n");
89 fprintf(aliases_file, "%%define word-array-name aliases\n");
90 fprintf(aliases_file, "%%pic\n");
91 fprintf(aliases_file, "%%%%\n");
93 #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
95 static const char* const names[] = BRACIFY xxx_names; \
96 emit_encoding(aliases_file,canonical_sh_file,names,sizeof(names)/sizeof(names[0]),#xxx); \
98 #define BRACIFY(...) { __VA_ARGS__ }
99 #define DEFALIAS(xxx_alias,xxx) emit_alias(aliases_file,xxx_alias,#xxx);
101 canonical_sh_file = fopen(canonical_sh_file_name, "w");
102 if (canonical_sh_file == NULL) {
103 fprintf(stderr, "Could not open '%s' for writing\n", canonical_sh_file_name);
106 #include "encodings.def"
107 if (ferror(canonical_sh_file) || fclose(canonical_sh_file))
110 canonical_sh_file = fopen(canonical_local_sh_file_name, "w");
111 if (canonical_sh_file == NULL) {
112 fprintf(stderr, "Could not open '%s' for writing\n", canonical_local_sh_file_name);
115 #include "encodings_local.def"
116 if (ferror(canonical_sh_file) || fclose(canonical_sh_file))
123 if (ferror(aliases_file) || fclose(aliases_file))