File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libiconv / lib / genaliases.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 13:38:46 2021 UTC (3 years, 7 months ago) by misho
Branches: libiconv, MAIN
CVS tags: v1_16p0, HEAD
libiconv 1.16

    1: /* Copyright (C) 1999-2001, 2003, 2005, 2008, 2012, 2017 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 <https://www.gnu.org/licenses/>.  */
   17: 
   18: /* Creates the aliases.gperf table. */
   19: 
   20: #include <stdio.h>
   21: #include <stdlib.h>
   22: 
   23: static void emit_alias (FILE* out1, const char* alias, const char* c_name)
   24: {
   25:   /* Output alias in upper case. */
   26:   const char* s = alias;
   27:   for (; *s; s++) {
   28:     unsigned char c = * (unsigned char *) s;
   29:     if (c >= 0x80)
   30:       exit(1);
   31:     if (c >= 'a' && c <= 'z')
   32:       c -= 'a'-'A';
   33:     putc(c, out1);
   34:   }
   35:   fprintf(out1,", ei_%s\n", c_name);
   36: }
   37: 
   38: static void emit_encoding (FILE* out1, FILE* out2, const char* const* names, size_t n, const char* c_name)
   39: {
   40:   fprintf(out2,"grep 'sizeof(\"");
   41:   /* Output *names in upper case. */
   42:   {
   43:     const char* s = *names;
   44:     for (; *s; s++) {
   45:       unsigned char c = * (unsigned char *) s;
   46:       if (c >= 0x80)
   47:         exit(1);
   48:       if (c >= 'a' && c <= 'z')
   49:         c -= 'a'-'A';
   50:       putc(c, out2);
   51:     }
   52:   }
   53:   fprintf(out2,"\")' tmp.h | sed -e 's|^.*\\(stringpool_str[0-9]*\\).*$|  (int)(long)\\&((struct stringpool_t *)0)->\\1,|'\n");
   54:   for (; n > 0; names++, n--)
   55:     emit_alias(out1, *names, c_name);
   56: }
   57: 
   58: int main (int argc, char* argv[])
   59: {
   60:   char* aliases_file_name;
   61:   char* canonical_sh_file_name;
   62:   char* canonical_local_sh_file_name;
   63:   FILE* aliases_file;
   64:   FILE* canonical_sh_file;
   65: 
   66:   if (argc != 4) {
   67:     fprintf(stderr, "Usage: genaliases aliases.gperf canonical.sh canonical_local.sh\n");
   68:     exit(1);
   69:   }
   70: 
   71:   aliases_file_name = argv[1];
   72:   canonical_sh_file_name = argv[2];
   73:   canonical_local_sh_file_name = argv[3];
   74: 
   75:   aliases_file = fopen(aliases_file_name, "w");
   76:   if (aliases_file == NULL) {
   77:     fprintf(stderr, "Could not open '%s' for writing\n", aliases_file_name);
   78:     exit(1);
   79:   }
   80: 
   81:   fprintf(aliases_file, "struct alias { int name; unsigned int encoding_index; };\n");
   82:   fprintf(aliases_file, "%%struct-type\n");
   83:   fprintf(aliases_file, "%%language=ANSI-C\n");
   84:   fprintf(aliases_file, "%%define hash-function-name aliases_hash\n");
   85:   fprintf(aliases_file, "%%define lookup-function-name aliases_lookup\n");
   86:   fprintf(aliases_file, "%%7bit\n");
   87:   fprintf(aliases_file, "%%readonly-tables\n");
   88:   fprintf(aliases_file, "%%global-table\n");
   89:   fprintf(aliases_file, "%%define word-array-name aliases\n");
   90:   fprintf(aliases_file, "%%pic\n");
   91:   fprintf(aliases_file, "%%%%\n");
   92: 
   93: #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
   94:   {                                                           \
   95:     static const char* const names[] = BRACIFY xxx_names;     \
   96:     emit_encoding(aliases_file,canonical_sh_file,names,sizeof(names)/sizeof(names[0]),#xxx); \
   97:   }
   98: #define BRACIFY(...) { __VA_ARGS__ }
   99: #define DEFALIAS(xxx_alias,xxx) emit_alias(aliases_file,xxx_alias,#xxx);
  100: 
  101:   canonical_sh_file = fopen(canonical_sh_file_name, "wb");
  102:   if (canonical_sh_file == NULL) {
  103:     fprintf(stderr, "Could not open '%s' for writing\n", canonical_sh_file_name);
  104:     exit(1);
  105:   }
  106: #include "encodings.def"
  107:   if (ferror(canonical_sh_file) || fclose(canonical_sh_file))
  108:     exit(1);
  109: 
  110:   canonical_sh_file = fopen(canonical_local_sh_file_name, "wb");
  111:   if (canonical_sh_file == NULL) {
  112:     fprintf(stderr, "Could not open '%s' for writing\n", canonical_local_sh_file_name);
  113:     exit(1);
  114:   }
  115: #include "encodings_local.def"
  116:   if (ferror(canonical_sh_file) || fclose(canonical_sh_file))
  117:     exit(1);
  118: 
  119: #undef DEFALIAS
  120: #undef BRACIFY
  121: #undef DEFENCODING
  122: 
  123:   if (ferror(aliases_file) || fclose(aliases_file))
  124:     exit(1);
  125:   exit(0);
  126: }

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