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. */
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
;
32 unsigned char c
= * (unsigned char *) s
;
35 if (c
>= 'a' && c
<= 'z')
40 fprintf(out1
,"\", ei_%s )\n", c_name
);
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
[])
54 char* aliases_file_name
;
55 char* canonical_file_name
;
60 fprintf(stderr
, "Usage: genaliases2 tag aliases.h canonical.h\n");
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
);
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
);
80 #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
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);
88 #include "encodings_aix.def"
91 #include "encodings_osf1.def"
94 #include "encodings_dos.def"
97 #include "encodings_zos.def"
100 #include "encodings_extra.def"
105 if (ferror(aliases_file
) || fclose(aliases_file
))
107 if (ferror(canonical_file
) || fclose(canonical_file
))