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

1.1       misho       1: /* Copyright (C) 1999-2001, 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 aliases.gperf table. */
                     20: 
                     21: #include <stdio.h>
                     22: #include <stdlib.h>
                     23: 
                     24: static void emit_alias (FILE* out1, const char* alias, const char* c_name)
                     25: {
                     26:   /* Output alias in upper case. */
                     27:   const char* s = alias;
                     28:   for (; *s; s++) {
                     29:     unsigned char c = * (unsigned char *) s;
                     30:     if (c >= 0x80)
                     31:       exit(1);
                     32:     if (c >= 'a' && c <= 'z')
                     33:       c -= 'a'-'A';
                     34:     putc(c, out1);
                     35:   }
                     36:   fprintf(out1,", ei_%s\n", c_name);
                     37: }
                     38: 
                     39: static void emit_encoding (FILE* out1, FILE* out2, const char* const* names, size_t n, const char* c_name)
                     40: {
                     41:   fprintf(out2,"grep 'sizeof(\"");
                     42:   /* Output *names in upper case. */
                     43:   {
                     44:     const char* s = *names;
                     45:     for (; *s; s++) {
                     46:       unsigned char c = * (unsigned char *) s;
                     47:       if (c >= 0x80)
                     48:         exit(1);
                     49:       if (c >= 'a' && c <= 'z')
                     50:         c -= 'a'-'A';
                     51:       putc(c, out2);
                     52:     }
                     53:   }
                     54:   fprintf(out2,"\")' tmp.h | sed -e 's|^.*\\(stringpool_str[0-9]*\\).*$|  (int)(long)\\&((struct stringpool_t *)0)->\\1,|'\n");
                     55:   for (; n > 0; names++, n--)
                     56:     emit_alias(out1, *names, c_name);
                     57: }
                     58: 
                     59: int main ()
                     60: {
                     61:   FILE* stdout2;
                     62: 
                     63:   printf("struct alias { int name; unsigned int encoding_index; };\n");
                     64:   printf("%%struct-type\n");
                     65:   printf("%%language=ANSI-C\n");
                     66:   printf("%%define hash-function-name aliases_hash\n");
                     67:   printf("%%define lookup-function-name aliases_lookup\n");
                     68:   printf("%%7bit\n");
                     69:   printf("%%readonly-tables\n");
                     70:   printf("%%global-table\n");
                     71:   printf("%%define word-array-name aliases\n");
                     72:   printf("%%pic\n");
                     73:   printf("%%%%\n");
                     74: 
                     75: #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
                     76:   {                                                           \
                     77:     static const char* const names[] = BRACIFY xxx_names;     \
                     78:     emit_encoding(stdout,stdout2,names,sizeof(names)/sizeof(names[0]),#xxx); \
                     79:   }
                     80: #define BRACIFY(...) { __VA_ARGS__ }
                     81: #define DEFALIAS(xxx_alias,xxx) emit_alias(stdout,xxx_alias,#xxx);
                     82: 
                     83:   stdout2 = fdopen(3, "w");
                     84:   if (stdout2 == NULL)
                     85:     exit(1);
                     86: #include "encodings.def"
                     87:   if (fclose(stdout2))
                     88:     exit(1);
                     89: 
                     90:   stdout2 = fdopen(4, "w");
                     91:   if (stdout2 == NULL)
                     92:     exit(1);
                     93: #include "encodings_local.def"
                     94:   if (fclose(stdout2))
                     95:     exit(1);
                     96: 
                     97: #undef DEFALIAS
                     98: #undef BRACIFY
                     99: #undef DEFENCODING
                    100: 
                    101:   if (ferror(stdout) || fclose(stdout))
                    102:     exit(1);
                    103:   exit(0);
                    104: }

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