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