Annotation of embedaddon/libiconv/lib/genaliases2.c, revision 1.1.1.1

1.1       misho       1: /* Copyright (C) 1999-2003, 2005, 2008 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, write to the Free Software Foundation, Inc., 51 Franklin Street,
                     17:    Fifth Floor, Boston, MA 02110-1301, USA.  */
                     18: 
                     19: /* Creates the aliases2.h table. */
                     20: 
                     21: #include <stdio.h>
                     22: #include <stdlib.h>
                     23: 
                     24: static unsigned int counter = 0;
                     25: 
                     26: static void emit_alias (FILE* out1, const char* tag, const char* alias, const char* c_name)
                     27: {
                     28:   fprintf(out1,"  S(%s_%u, \"",tag,counter);
                     29:   /* Output alias in upper case. */
                     30:   {
                     31:     const char* s = alias;
                     32:     for (; *s; s++) {
                     33:       unsigned char c = * (unsigned char *) s;
                     34:       if (c >= 0x80)
                     35:         exit(1);
                     36:       if (c >= 'a' && c <= 'z')
                     37:         c -= 'a'-'A';
                     38:       putc(c, out1);
                     39:     }
                     40:   }
                     41:   fprintf(out1,"\", ei_%s )\n", c_name);
                     42:   counter++;
                     43: }
                     44: 
                     45: static void emit_encoding (FILE* out1, FILE* out2, const char* tag, const char* const* names, size_t n, const char* c_name)
                     46: {
                     47:   fprintf(out2,"  (int)(long)&((struct stringpool2_t *)0)->stringpool_%s_%u,\n",tag,counter);
                     48:   for (; n > 0; names++, n--)
                     49:     emit_alias(out1, tag, *names, c_name);
                     50: }
                     51: 
                     52: int main (int argc, char* argv[])
                     53: {
                     54:   const char * tag = (argc > 1 ? argv[1] : "xxx");
                     55:   FILE * stdout2 = fdopen(3, "w");
                     56:   if (stdout2 == NULL)
                     57:     exit(1);
                     58: #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
                     59:   {                                                           \
                     60:     static const char* const names[] = BRACIFY xxx_names;     \
                     61:     emit_encoding(stdout,stdout2,tag,names,sizeof(names)/sizeof(names[0]),#xxx); \
                     62:   }
                     63: #define BRACIFY(...) { __VA_ARGS__ }
                     64: #define DEFALIAS(xxx_alias,xxx) emit_alias(stdout,tag,xxx_alias,#xxx);
                     65: #ifdef USE_AIX
                     66: #include "encodings_aix.def"
                     67: #endif
                     68: #ifdef USE_OSF1
                     69: #include "encodings_osf1.def"
                     70: #endif
                     71: #ifdef USE_DOS
                     72: #include "encodings_dos.def"
                     73: #endif
                     74: #ifdef USE_EXTRA
                     75: #include "encodings_extra.def"
                     76: #endif
                     77: #undef DEFALIAS
                     78: #undef BRACIFY
                     79: #undef DEFENCODING
                     80:   if (ferror(stdout) || fclose(stdout) || ferror(stdout2) || fclose(stdout2))
                     81:     exit(1);
                     82:   exit(0);
                     83: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>