~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000 MySQL AB
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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
#ifdef USE_INTERNAL_CTYPE
144
  higher_pos=lower_pos= (uchar* ) "";		/* System converts chars */
145
#else
146
  higher_pos= (uchar *) "[]\\@^";
147
  lower_pos=  (uchar *) "{}|`~";
148
#endif /* USE_INTERNAL_CTYPE */
149
150
  while (*higher_pos)
151
  {
152
    to_upper[ *lower_pos ] = sort_order[ *lower_pos ] = (char) *higher_pos;
153
    to_lower[ *higher_pos++ ] = (char) *lower_pos++;
154
  }
155
156
	/* sets upp sortorder; higer_pos character (upper and lower) is */
157
	/* changed to lower_pos character */
158
159
#ifdef USE_ISO_8859_1				/* As in USG5 ICL-386 */
160
  higher_pos= (uchar *) "\305\304\326\334\311";
161
  lower_pos=  (uchar *) "\304\305\326YE";
162
#else
163
  higher_pos= (uchar *) "][\\~`";		/* R{tt ordning p} tecknen */
164
  lower_pos= (uchar *)	"[\\]YE";		/* Ordning enligt ascii */
165
#endif /* USE_ISO_8859_1 */
166
167
  while (*higher_pos)
168
  {
169
    sort_order[ *higher_pos ] =
170
      sort_order[(uchar)to_lower[*higher_pos]] = *lower_pos;
171
    higher_pos++; lower_pos++;
172
  }
173
  DBUG_VOID_RETURN;
174
} /* init_case_convert */