1 /* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23 /* Prints case-convert and sort-convert tabell on stdout. This is used to
24 make _ctype.c easyer */
25
26 #ifdef DBUG_OFF
27 #undef DBUG_OFF
28 #endif
29
30 #include <my_global.h>
31 #include <ctype.h>
32 #include <my_sys.h>
33 #include "m_string.h"
34
35 uchar to_upper[256];
36 uchar to_lower[256], sort_order[256];
37
38 static int ascii_output=1;
39 static string tab_names[]={ "to_lower[]={","to_upper[]={","sort_order[]={" };
40 static uchar* tabell[]= {to_lower,to_upper,sort_order};
41
42 void get_options(),init_case_convert();
43
main(argc,argv)44 main(argc,argv)
45 int argc;
46 char *argv[];
47 {
48 int i,j,ch;
49 DBUG_ENTER ("main");
50 DBUG_PROCESS (argv[0]);
51
52 get_options(&argc,&argv);
53 init_case_convert();
54 puts("Tabells for caseconverts and sorttest of characters\n");
55 for (i=0 ; i < 3 ; i++)
56 {
57 printf("uchar %s\n",tab_names[i]);
58 for (j=0 ; j <= 255 ; j++)
59 {
60 ch=(int) tabell[i][j];
61 if (ascii_output && isprint(ch) && ! (ch & 128))
62 {
63 if (strchr("\\'",(char) ch))
64 printf("'\\%c', ",ch);
65 else
66 printf("'%c', ",ch);
67 }
68 else
69 printf("'\\%03o',",ch);
70 if ((j+1 & 7) == 0)
71 puts("");
72 }
73 puts("};\n");
74 }
75 DBUG_RETURN(0);
76 } /* main */
77
78 /* Read options */
79
get_options(argc,argv)80 void get_options(argc,argv)
81 int *argc;
82 char **argv[];
83 {
84 int help,version;
85 char *pos,*progname;
86
87 progname= (*argv)[0];
88 help=0; ascii_output=1;
89 while (--*argc >0 && *(pos = *(++*argv)) == '-' )
90 {
91 while (*++pos)
92 {
93 version=0;
94 switch(*pos) {
95 case 'n': /* Numeric output */
96 ascii_output=0;
97 break;
98 case '#':
99 DBUG_PUSH (++pos);
100 *(pos--) = '\0'; /* Skippa argument */
101 break;
102 case 'V':
103 version=1;
104 case 'I':
105 case '?':
106 printf("%s Ver 1.0\n",progname);
107 if (version)
108 break;
109 puts("Output tabells of to_lower[], to_upper[] and sortorder[]\n");
110 printf("Usage: %s [-n?I]\n",progname);
111 puts("Options: -? or -I \"Info\" -n \"numeric output\"");
112 break;
113 default:
114 fprintf(stderr,"illegal option: -%c\n",*pos);
115 break;
116 }
117 }
118 }
119 return;
120 } /* get_options */
121
122
123 /* set up max character for which isupper() and toupper() gives */
124 /* right answer. Is usually 127 or 255 */
125
126 #ifdef USE_INTERNAL_CTYPE
127 #define MAX_CHAR_OK CHAR_MAX /* All chars is right */
128 #else
129 #define MAX_CHAR_OK 127 /* 7 Bit ascii */
130 #endif
131
132 /* Initiate arrays for case-conversation */
133
init_case_convert()134 void init_case_convert()
135 {
136 int16 i;
137 uchar *higher_pos,*lower_pos;
138 DBUG_ENTER("init_case_convert");
139
140 for (i=0 ; i <= MAX_CHAR_OK ; i++)
141 {
142 to_upper[i]= sort_order[i]= (islower(i) ? toupper(i) : (char) i);
143 to_lower[i]= (isupper(i) ? tolower(i) : (char) i);
144 }
145 #if MAX_CHAR_OK != 255
146 for (i--; i++ < 255 ;)
147 to_upper[i]= sort_order[i]= to_lower[i]= (char) i;
148 #endif
149
150 #if defined(HPUX10)
151 higher_pos= (uchar *) "\xd0\xd8\xda\xdb\xdc\xd3";
152 lower_pos= (uchar *) "\xd4\xcc\xce\xdf\xc9\xd7";
153 #else
154 #ifdef USE_INTERNAL_CTYPE
155 higher_pos=lower_pos= (uchar* ) ""; /* System converts chars */
156 #else
157 #if defined(DEC_MULTINATIONAL_CHAR) || defined(HP_MULTINATIONAL_CHAR)
158 higher_pos= (uchar *) "\305\304\326\311\334";
159 lower_pos= (uchar *) "\345\344\366\351\374";
160 #else
161 higher_pos= (uchar *) "[]\\@^";
162 lower_pos= (uchar *) "{}|`~";
163 #endif
164 #endif /* USE_INTERNAL_CTYPE */
165 #endif /* HPUX10 */
166
167 while (*higher_pos)
168 {
169 to_upper[ *lower_pos ] = sort_order[ *lower_pos ] = (char) *higher_pos;
170 to_lower[ *higher_pos++ ] = (char) *lower_pos++;
171 }
172
173 /* sets upp sortorder; higer_pos character (upper and lower) is */
174 /* changed to lower_pos character */
175
176 #if defined(HPUX10)
177 higher_pos= lower_pos= (uchar *) ""; /* Tecknen i r{tt ordning */
178 #else
179 #ifdef USE_ISO_8859_1 /* As in USG5 ICL-386 */
180 higher_pos= (uchar *) "\305\304\326\334\311";
181 lower_pos= (uchar *) "\304\305\326YE";
182 #else
183 higher_pos= (uchar *) "][\\~`"; /* R{tt ordning p} tecknen */
184 lower_pos= (uchar *) "[\\]YE"; /* Ordning enligt ascii */
185 #endif /* USE_ISO_8859_1 */
186 #endif /* HPUX10 */
187
188 while (*higher_pos)
189 {
190 sort_order[ *higher_pos ] =
191 sort_order[(uchar)to_lower[*higher_pos]] = *lower_pos;
192 higher_pos++; lower_pos++;
193 }
194 DBUG_VOID_RETURN;
195 } /* init_case_convert */
196