]> git.lyx.org Git - lyx.git/blob - 3rdparty/libiconv/1.15/lib/genaliases2.c
Implement auto-nesting.
[lyx.git] / 3rdparty / libiconv / 1.15 / lib / genaliases2.c
1 /* Copyright (C) 1999-2003, 2005, 2008, 2012 Free Software Foundation, Inc.
2    This file is part of the GNU LIBICONV Library.
3
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.
8
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.
13
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/>.  */
17
18 /* Creates the aliases2.h table. */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22
23 static unsigned int counter = 0;
24
25 static void emit_alias (FILE* out1, const char* tag, const char* alias, const char* c_name)
26 {
27   fprintf(out1,"  S(%s_%u, \"",tag,counter);
28   /* Output alias in upper case. */
29   {
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);
38     }
39   }
40   fprintf(out1,"\", ei_%s )\n", c_name);
41   counter++;
42 }
43
44 static void emit_encoding (FILE* out1, FILE* out2, const char* tag, const char* const* names, size_t n, const char* c_name)
45 {
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);
49 }
50
51 int main (int argc, char* argv[])
52 {
53   const char* tag;
54   char* aliases_file_name;
55   char* canonical_file_name;
56   FILE* aliases_file;
57   FILE* canonical_file;
58
59   if (argc != 4) {
60     fprintf(stderr, "Usage: genaliases2 tag aliases.h canonical.h\n");
61     exit(1);
62   }
63
64   tag = argv[1];
65   aliases_file_name = argv[2];
66   canonical_file_name = argv[3];
67
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);
72   }
73
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);
78   }
79
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); \
84   }
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_EXTRA
97 #include "encodings_extra.def"
98 #endif
99 #undef DEFALIAS
100 #undef BRACIFY
101 #undef DEFENCODING
102   if (ferror(aliases_file) || fclose(aliases_file))
103     exit(1);
104   if (ferror(canonical_file) || fclose(canonical_file))
105     exit(1);
106   exit(0);
107 }