You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.3 KiB

26 years ago
26 years ago
26 years ago
26 years ago
  1. /* Copyright (C) 2000-2004 MySQL AB
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License as published by
  4. the Free Software Foundation.
  5. There are special exceptions to the terms and conditions of the GPL as it
  6. is applied to this software.
  7. This program 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
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
  14. /* can't use -lmysys because this prog is used to create -lstrings */
  15. #include <my_global.h>
  16. #include <ctype.h>
  17. #include <string.h>
  18. #include <unistd.h>
  19. #define CHARSETS_SUBDIR "sql/share/charsets"
  20. #define CTYPE_TABLE_SIZE 257
  21. #define TO_LOWER_TABLE_SIZE 256
  22. #define TO_UPPER_TABLE_SIZE 256
  23. #define SORT_ORDER_TABLE_SIZE 256
  24. #define ROW_LEN 16
  25. void print_arrays_for(char *set);
  26. char *prog;
  27. char buf[1024], *p, *endptr;
  28. int
  29. main(int argc, char **argv)
  30. {
  31. prog = *argv;
  32. if (argc < 2) {
  33. fprintf(stderr, "usage: %s source-dir [charset [, charset]]\n", prog);
  34. exit(EXIT_FAILURE);
  35. }
  36. --argc; ++argv; /* skip program name */
  37. if (chdir(*argv) != 0) {
  38. fprintf(stderr, "%s: can't cd to %s\n", prog, *argv);
  39. exit(EXIT_FAILURE);
  40. }
  41. --argc; ++argv;
  42. if (chdir(CHARSETS_SUBDIR) != 0) {
  43. fprintf(stderr, "%s: can't cd to %s\n", prog, CHARSETS_SUBDIR);
  44. exit(EXIT_FAILURE);
  45. }
  46. while (argc--)
  47. print_arrays_for(*argv++);
  48. exit(EXIT_SUCCESS);
  49. }
  50. void
  51. print_array(FILE *f, const char *set, const char *name, int n)
  52. {
  53. int i;
  54. char val[100];
  55. printf("uchar %s_%s[] = {\n", name, set);
  56. p = buf;
  57. *buf = '\0';
  58. for (i = 0; i < n; ++i)
  59. {
  60. /* get a word from f */
  61. endptr = p;
  62. for (;;)
  63. {
  64. while (isspace(*endptr))
  65. ++endptr;
  66. if (*endptr && *endptr != '#') /* not comment */
  67. break;
  68. if ((fgets(buf, sizeof(buf), f)) == NULL)
  69. return; /* XXX: break silently */
  70. endptr = buf;
  71. }
  72. p = val;
  73. while (!isspace(*endptr))
  74. *p++ = *endptr++;
  75. *p = '\0';
  76. p = endptr;
  77. /* write the value out */
  78. if (i == 0 || i % ROW_LEN == n % ROW_LEN)
  79. printf(" ");
  80. printf("%3d", (unsigned char) strtol(val, (char **) NULL, 16));
  81. if (i < n - 1)
  82. printf(",");
  83. if ((i+1) % ROW_LEN == n % ROW_LEN)
  84. printf("\n");
  85. }
  86. printf("};\n\n");
  87. }
  88. void
  89. print_arrays_for(char *set)
  90. {
  91. FILE *f;
  92. sprintf(buf, "%s.conf", set);
  93. if ((f = fopen(buf, "r")) == NULL) {
  94. fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set);
  95. exit(EXIT_FAILURE);
  96. }
  97. printf("\
  98. /* The %s character set. Generated automatically by configure and\n\
  99. * the %s program\n\
  100. */\n\n",
  101. set, prog);
  102. /* it would be nice if this used the code in mysys/charset.c, but... */
  103. print_array(f, set, "ctype", CTYPE_TABLE_SIZE);
  104. print_array(f, set, "to_lower", TO_LOWER_TABLE_SIZE);
  105. print_array(f, set, "to_upper", TO_UPPER_TABLE_SIZE);
  106. print_array(f, set, "sort_order", SORT_ORDER_TABLE_SIZE);
  107. printf("\n");
  108. fclose(f);
  109. return;
  110. }