genaliases.c
Upload User: yingmei828
Upload Date: 2007-01-01
Package Size: 1646k
Code Size: 2k
Development Platform:

Unix_Linux

  1. /* Copyright (C) 1999 Free Software Foundation, Inc.
  2.    This file is part of the GNU ICONV Library.
  3.    The GNU ICONV Library is free software; you can redistribute it and/or
  4.    modify it under the terms of the GNU Library General Public License as
  5.    published by the Free Software Foundation; either version 2 of the
  6.    License, or (at your option) any later version.
  7.    The GNU ICONV Library is distributed in the hope that it will be useful,
  8.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  10.    Library General Public License for more details.
  11.    You should have received a copy of the GNU Library General Public
  12.    License along with the GNU ICONV Library; see the file COPYING.LIB.  If not,
  13.    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14.    Boston, MA 02111-1307, USA.  */
  15. /* Creates the aliases.gperf table. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. static void emit_encoding (const char* const* names, size_t n, const char* c_name)
  19. {
  20.   for (; n > 0; names++, n--) {
  21.     /* Output *names in upper case. */
  22.     const char* s = *names;
  23.     for (; *s; s++) {
  24.       unsigned char c = * (unsigned char *) s;
  25.       if (c >= 0x80)
  26.         exit(1);
  27.       if (c >= 'a' && c <= 'z')
  28.         c -= 'a'-'A';
  29.       putc(c, stdout);
  30.     }
  31.     printf(", ei_%sn", c_name);
  32.   }
  33. }
  34. int main ()
  35. {
  36.   printf("struct alias { const char* name; unsigned int encoding_index; };n");
  37.   printf("%%%%n");
  38. #define DEFENCODING(xxx_names,xxx,xxx_ifuncs,xxx_ofuncs1,xxx_ofuncs2) 
  39.   {                                                           
  40.     static const char* const names[] = BRACIFY xxx_names;     
  41.     emit_encoding(names,sizeof(names)/sizeof(names[0]),#xxx); 
  42.   }
  43. #define BRACIFY(...) { __VA_ARGS__ }
  44. #include "encodings.def"
  45. #undef BRACIFY
  46. #undef DEFENCODING
  47.   fflush(stdout);
  48.   if (ferror(stdout))
  49.     exit(1);
  50.   exit(0);
  51. }