INSTALL.windows: Fix MSVC instructions.
[libiconv.git] / lib / genaliases2.c
blob51a951cc87c0d2c95e446b93734e766aa04abd95
1 /* Copyright (C) 1999-2003, 2005, 2008, 2012, 2022 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 Lesser General Public
6 License as published by the Free Software Foundation; either version 2.1
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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU LIBICONV Library; see the file COPYING.LIB.
16 If not, see <https://www.gnu.org/licenses/>. */
18 /* Creates the aliases2.h table. */
20 #include <stdio.h>
21 #include <stdlib.h>
23 static unsigned int counter = 0;
25 static void emit_alias (FILE* out1, const char* tag, const char* alias, const char* c_name)
27 fprintf(out1," S(%s_%u, \"",tag,counter);
28 /* Output alias in upper case. */
30 const char* s = alias;
31 for (; *s; s++) {
32 unsigned char c = * (unsigned char *) s;
33 if (c >= 0x80)
34 exit(1);
35 if (c >= 'a' && c <= 'z')
36 c -= 'a'-'A';
37 putc(c, out1);
40 fprintf(out1,"\", ei_%s )\n", c_name);
41 counter++;
44 static void emit_encoding (FILE* out1, FILE* out2, const char* tag, const char* const* names, size_t n, const char* c_name)
46 fprintf(out2," (int)(long)&((struct stringpool2_t *)0)->stringpool_%s_%u,\n",tag,counter);
47 for (; n > 0; names++, n--)
48 emit_alias(out1, tag, *names, c_name);
51 int main (int argc, char* argv[])
53 const char* tag;
54 char* aliases_file_name;
55 char* canonical_file_name;
56 FILE* aliases_file;
57 FILE* canonical_file;
59 if (argc != 4) {
60 fprintf(stderr, "Usage: genaliases2 tag aliases.h canonical.h\n");
61 exit(1);
64 tag = argv[1];
65 aliases_file_name = argv[2];
66 canonical_file_name = argv[3];
68 aliases_file = fopen(aliases_file_name, "w");
69 if (aliases_file == NULL) {
70 fprintf(stderr, "Could not open '%s' for writing\n", aliases_file_name);
71 exit(1);
74 canonical_file = fopen(canonical_file_name, "w");
75 if (canonical_file == NULL) {
76 fprintf(stderr, "Could not open '%s' for writing\n", canonical_file_name);
77 exit(1);
80 #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
81 { \
82 static const char* const names[] = BRACIFY xxx_names; \
83 emit_encoding(aliases_file,canonical_file,tag,names,sizeof(names)/sizeof(names[0]),#xxx); \
85 #define BRACIFY(...) { __VA_ARGS__ }
86 #define DEFALIAS(xxx_alias,xxx) emit_alias(aliases_file,tag,xxx_alias,#xxx);
87 #ifdef USE_AIX
88 #include "encodings_aix.def"
89 #endif
90 #ifdef USE_OSF1
91 #include "encodings_osf1.def"
92 #endif
93 #ifdef USE_DOS
94 #include "encodings_dos.def"
95 #endif
96 #ifdef USE_ZOS
97 #include "encodings_zos.def"
98 #endif
99 #ifdef USE_EXTRA
100 #include "encodings_extra.def"
101 #endif
102 #undef DEFALIAS
103 #undef BRACIFY
104 #undef DEFENCODING
105 if (ferror(aliases_file) || fclose(aliases_file))
106 exit(1);
107 if (ferror(canonical_file) || fclose(canonical_file))
108 exit(1);
109 exit(0);