1
/* Copyright (C) 2000-2004 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation.
7
There are special exceptions to the terms and conditions of the GPL as it
8
is applied to this software. View the full text of the exception in file
9
EXCEPTIONS-CLIENT in the directory of this software distribution.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20
/* can't use -lmysys because this prog is used to create -lstrings */
23
#include <my_global.h>
28
#define CHARSETS_SUBDIR "sql/share/charsets"
29
#define CTYPE_TABLE_SIZE 257
30
#define TO_LOWER_TABLE_SIZE 256
31
#define TO_UPPER_TABLE_SIZE 256
32
#define SORT_ORDER_TABLE_SIZE 256
35
void print_arrays_for(char *set);
38
char buf[1024], *p, *endptr;
41
main(int argc, char **argv)
46
fprintf(stderr, "usage: %s source-dir [charset [, charset]]\n", prog);
50
--argc; ++argv; /* skip program name */
52
if (chdir(*argv) != 0) {
53
fprintf(stderr, "%s: can't cd to %s\n", prog, *argv);
58
if (chdir(CHARSETS_SUBDIR) != 0) {
59
fprintf(stderr, "%s: can't cd to %s\n", prog, CHARSETS_SUBDIR);
64
print_arrays_for(*argv++);
70
print_array(FILE *f, const char *set, const char *name, int n)
75
printf("uchar %s_%s[] = {\n", name, set);
79
for (i = 0; i < n; ++i)
81
/* get a word from f */
85
while (isspace(*endptr))
87
if (*endptr && *endptr != '#') /* not comment */
89
if ((fgets(buf, sizeof(buf), f)) == NULL)
90
return; /* XXX: break silently */
95
while (!isspace(*endptr))
100
/* write the value out */
102
if (i == 0 || i % ROW_LEN == n % ROW_LEN)
105
printf("%3d", (unsigned char) strtol(val, (char **) NULL, 16));
110
if ((i+1) % ROW_LEN == n % ROW_LEN)
118
print_arrays_for(char *set)
122
sprintf(buf, "%s.conf", set);
124
if ((f = fopen(buf, "r")) == NULL) {
125
fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set);
130
/* The %s character set. Generated automatically by configure and\n\
135
/* it would be nice if this used the code in mysys/charset.c, but... */
136
print_array(f, set, "ctype", CTYPE_TABLE_SIZE);
137
print_array(f, set, "to_lower", TO_LOWER_TABLE_SIZE);
138
print_array(f, set, "to_upper", TO_UPPER_TABLE_SIZE);
139
print_array(f, set, "sort_order", SORT_ORDER_TABLE_SIZE);