genaliases2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* Copyright (C) 1999-2003, 2005, 2008, 2012, 2022 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 Lesser General Public
  5. License as published by the Free Software Foundation; either version 2.1
  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. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU LIBICONV Library; see the file COPYING.LIB.
  13. If not, see <https://www.gnu.org/licenses/>. */
  14. /* Creates the aliases2.h table. */
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. static unsigned int counter = 0;
  18. static void emit_alias (FILE* out1, const char* tag, const char* alias, const char* c_name)
  19. {
  20. fprintf(out1," S(%s_%u, \"",tag,counter);
  21. /* Output alias in upper case. */
  22. {
  23. const char* s = alias;
  24. for (; *s; s++) {
  25. unsigned char c = * (unsigned char *) s;
  26. if (c >= 0x80)
  27. exit(1);
  28. if (c >= 'a' && c <= 'z')
  29. c -= 'a'-'A';
  30. putc(c, out1);
  31. }
  32. }
  33. fprintf(out1,"\", ei_%s )\n", c_name);
  34. counter++;
  35. }
  36. static void emit_encoding (FILE* out1, FILE* out2, const char* tag, const char* const* names, size_t n, const char* c_name)
  37. {
  38. fprintf(out2," (int)(long)&((struct stringpool2_t *)0)->stringpool_%s_%u,\n",tag,counter);
  39. for (; n > 0; names++, n--)
  40. emit_alias(out1, tag, *names, c_name);
  41. }
  42. int main (int argc, char* argv[])
  43. {
  44. const char* tag;
  45. char* aliases_file_name;
  46. char* canonical_file_name;
  47. FILE* aliases_file;
  48. FILE* canonical_file;
  49. if (argc != 4) {
  50. fprintf(stderr, "Usage: genaliases2 tag aliases.h canonical.h\n");
  51. exit(1);
  52. }
  53. tag = argv[1];
  54. aliases_file_name = argv[2];
  55. canonical_file_name = argv[3];
  56. aliases_file = fopen(aliases_file_name, "w");
  57. if (aliases_file == NULL) {
  58. fprintf(stderr, "Could not open '%s' for writing\n", aliases_file_name);
  59. exit(1);
  60. }
  61. canonical_file = fopen(canonical_file_name, "w");
  62. if (canonical_file == NULL) {
  63. fprintf(stderr, "Could not open '%s' for writing\n", canonical_file_name);
  64. exit(1);
  65. }
  66. #define DEFENCODING(xxx_names,xxx,xxx_ifuncs1,xxx_ifuncs2,xxx_ofuncs1,xxx_ofuncs2) \
  67. { \
  68. static const char* const names[] = BRACIFY xxx_names; \
  69. emit_encoding(aliases_file,canonical_file,tag,names,sizeof(names)/sizeof(names[0]),#xxx); \
  70. }
  71. #define BRACIFY(...) { __VA_ARGS__ }
  72. #define DEFALIAS(xxx_alias,xxx) emit_alias(aliases_file,tag,xxx_alias,#xxx);
  73. #ifdef USE_AIX
  74. #include "encodings_aix.def"
  75. #endif
  76. #ifdef USE_OSF1
  77. #include "encodings_osf1.def"
  78. #endif
  79. #ifdef USE_DOS
  80. #include "encodings_dos.def"
  81. #endif
  82. #ifdef USE_ZOS
  83. #include "encodings_zos.def"
  84. #endif
  85. #ifdef USE_EXTRA
  86. #include "encodings_extra.def"
  87. #endif
  88. #undef DEFALIAS
  89. #undef BRACIFY
  90. #undef DEFENCODING
  91. if (ferror(aliases_file) || fclose(aliases_file))
  92. exit(1);
  93. if (ferror(canonical_file) || fclose(canonical_file))
  94. exit(1);
  95. exit(0);
  96. }