genaliases2.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright (C) 1999-2003, 2005, 2008 Free Software Foundation, Inc.
  2. This file is part of the GNU LIBICONV Library.
  3. The GNU LIBICONV Library is free software; you can redistribute it
  4. and/or modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. The GNU LIBICONV Library is distributed in the hope that it will be
  8. useful, 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 LIBICONV Library; see the file COPYING.LIB.
  13. If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
  14. Fifth Floor, Boston, MA 02110-1301, USA. */
  15. /* Creates the aliases2.h table. */
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. static unsigned int counter = 0;
  19. static void emit_alias (FILE* out1, const char* tag, const char* alias, const char* c_name)
  20. {
  21. fprintf(out1," S(%s_%u, \"",tag,counter);
  22. /* Output alias in upper case. */
  23. {
  24. const char* s = alias;
  25. for (; *s; s++) {
  26. unsigned char c = * (unsigned char *) s;
  27. if (c >= 0x80)
  28. exit(1);
  29. if (c >= 'a' && c <= 'z')
  30. c -= 'a'-'A';
  31. putc(c, out1);
  32. }
  33. }
  34. fprintf(out1,"\", ei_%s )\n", c_name);
  35. counter++;
  36. }
  37. static void emit_encoding (FILE* out1, FILE* out2, const char* tag, const char* const* names, size_t n, const char* c_name)
  38. {
  39. fprintf(out2," (int)(long)&((struct stringpool2_t *)0)->stringpool_%s_%u,\n",tag,counter);
  40. for (; n > 0; names++, n--)
  41. emit_alias(out1, tag, *names, c_name);
  42. }
  43. int main (int argc, char* argv[])
  44. {
  45. const char * tag = (argc > 1 ? argv[1] : "xxx");
  46. FILE * stdout2 = fdopen(3, "w");
  47. if (stdout2 == NULL)
  48. exit(1);
  49. #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
  50. { \
  51. static const char* const names[] = BRACIFY xxx_names; \
  52. emit_encoding(stdout,stdout2,tag,names,sizeof(names)/sizeof(names[0]),#xxx); \
  53. }
  54. #define BRACIFY(...) { __VA_ARGS__ }
  55. #define DEFALIAS(xxx_alias,xxx) emit_alias(stdout,tag,xxx_alias,#xxx);
  56. #ifdef USE_AIX
  57. #include "encodings_aix.def"
  58. #endif
  59. #ifdef USE_OSF1
  60. #include "encodings_osf1.def"
  61. #endif
  62. #ifdef USE_DOS
  63. #include "encodings_dos.def"
  64. #endif
  65. #ifdef USE_EXTRA
  66. #include "encodings_extra.def"
  67. #endif
  68. #undef DEFALIAS
  69. #undef BRACIFY
  70. #undef DEFENCODING
  71. if (ferror(stdout) || fclose(stdout) || ferror(stdout2) || fclose(stdout2))
  72. exit(1);
  73. exit(0);
  74. }