00001 /* Copyright (C) 2000-2004 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation. 00006 00007 There are special exceptions to the terms and conditions of the GPL as it 00008 is applied to this software. View the full text of the exception in file 00009 EXCEPTIONS-CLIENT in the directory of this software distribution. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00019 00020 /* can't use -lmysys because this prog is used to create -lstrings */ 00021 00022 00023 #include <my_global.h> 00024 #include <ctype.h> 00025 #include <string.h> 00026 #include <unistd.h> 00027 00028 #define CHARSETS_SUBDIR "sql/share/charsets" 00029 #define CTYPE_TABLE_SIZE 257 00030 #define TO_LOWER_TABLE_SIZE 256 00031 #define TO_UPPER_TABLE_SIZE 256 00032 #define SORT_ORDER_TABLE_SIZE 256 00033 #define ROW_LEN 16 00034 00035 void print_arrays_for(char *set); 00036 00037 char *prog; 00038 char buf[1024], *p, *endptr; 00039 00040 int 00041 main(int argc, char **argv) 00042 { 00043 prog = *argv; 00044 00045 if (argc < 2) { 00046 fprintf(stderr, "usage: %s source-dir [charset [, charset]]\n", prog); 00047 exit(EXIT_FAILURE); 00048 } 00049 00050 --argc; ++argv; /* skip program name */ 00051 00052 if (chdir(*argv) != 0) { 00053 fprintf(stderr, "%s: can't cd to %s\n", prog, *argv); 00054 exit(EXIT_FAILURE); 00055 } 00056 --argc; ++argv; 00057 00058 if (chdir(CHARSETS_SUBDIR) != 0) { 00059 fprintf(stderr, "%s: can't cd to %s\n", prog, CHARSETS_SUBDIR); 00060 exit(EXIT_FAILURE); 00061 } 00062 00063 while (argc--) 00064 print_arrays_for(*argv++); 00065 00066 exit(EXIT_SUCCESS); 00067 } 00068 00069 void 00070 print_array(FILE *f, const char *set, const char *name, int n) 00071 { 00072 int i; 00073 char val[100]; 00074 00075 printf("uchar %s_%s[] = {\n", name, set); 00076 00077 p = buf; 00078 *buf = '\0'; 00079 for (i = 0; i < n; ++i) 00080 { 00081 /* get a word from f */ 00082 endptr = p; 00083 for (;;) 00084 { 00085 while (isspace(*endptr)) 00086 ++endptr; 00087 if (*endptr && *endptr != '#') /* not comment */ 00088 break; 00089 if ((fgets(buf, sizeof(buf), f)) == NULL) 00090 return; /* XXX: break silently */ 00091 endptr = buf; 00092 } 00093 00094 p = val; 00095 while (!isspace(*endptr)) 00096 *p++ = *endptr++; 00097 *p = '\0'; 00098 p = endptr; 00099 00100 /* write the value out */ 00101 00102 if (i == 0 || i % ROW_LEN == n % ROW_LEN) 00103 printf(" "); 00104 00105 printf("%3d", (unsigned char) strtol(val, (char **) NULL, 16)); 00106 00107 if (i < n - 1) 00108 printf(","); 00109 00110 if ((i+1) % ROW_LEN == n % ROW_LEN) 00111 printf("\n"); 00112 } 00113 00114 printf("};\n\n"); 00115 } 00116 00117 void 00118 print_arrays_for(char *set) 00119 { 00120 FILE *f; 00121 00122 sprintf(buf, "%s.conf", set); 00123 00124 if ((f = fopen(buf, "r")) == NULL) { 00125 fprintf(stderr, "%s: can't read conf file for charset %s\n", prog, set); 00126 exit(EXIT_FAILURE); 00127 } 00128 00129 printf("\ 00130 /* The %s character set. Generated automatically by configure and\n\ 00131 * the %s program\n\ 00132 */\n\n", 00133 set, prog); 00134 00135 /* it would be nice if this used the code in mysys/charset.c, but... */ 00136 print_array(f, set, "ctype", CTYPE_TABLE_SIZE); 00137 print_array(f, set, "to_lower", TO_LOWER_TABLE_SIZE); 00138 print_array(f, set, "to_upper", TO_UPPER_TABLE_SIZE); 00139 print_array(f, set, "sort_order", SORT_ORDER_TABLE_SIZE); 00140 printf("\n"); 00141 00142 fclose(f); 00143 00144 return; 00145 }
1.4.7

