~stewart/drizzle/embedded-innodb-create-select-transaction-arrgh

« back to all changes in this revision

Viewing changes to strings/do_ctype.c

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 MSDOS
 
144
  higher_pos= (uchar *) "\217\216\231\232\220"; /* Extra chars to konv. */
 
145
  lower_pos=  (uchar *) "\206\204\224\201\202";
 
146
#else
 
147
#if defined(HPUX10) && ASCII_BITS_USED == 8
 
148
  higher_pos= (uchar *) "\xd0\xd8\xda\xdb\xdc\xd3";
 
149
  lower_pos=  (uchar *) "\xd4\xcc\xce\xdf\xc9\xd7";
 
150
#else
 
151
#ifdef USE_INTERNAL_CTYPE
 
152
  higher_pos=lower_pos= (uchar* ) "";           /* System converts chars */
 
153
#else
 
154
#if defined(DEC_MULTINATIONAL_CHAR) || defined(HP_MULTINATIONAL_CHAR)
 
155
  higher_pos= (uchar *) "\305\304\326\311\334";
 
156
  lower_pos=  (uchar *) "\345\344\366\351\374";
 
157
#else
 
158
  higher_pos= (uchar *) "[]\\@^";
 
159
  lower_pos=  (uchar *) "{}|`~";
 
160
#endif
 
161
#endif /* USE_INTERNAL_CTYPE */
 
162
#endif /* HPUX10 */
 
163
#endif /* MSDOS */
 
164
 
 
165
  while (*higher_pos)
 
166
  {
 
167
    to_upper[ *lower_pos ] = sort_order[ *lower_pos ] = (char) *higher_pos;
 
168
    to_lower[ *higher_pos++ ] = (char) *lower_pos++;
 
169
  }
 
170
 
 
171
        /* sets upp sortorder; higer_pos character (upper and lower) is */
 
172
        /* changed to lower_pos character */
 
173
 
 
174
#ifdef MSDOS
 
175
  higher_pos= (uchar *) "\217\216\231\232\220";
 
176
  lower_pos=  (uchar *) "\216\217\231YE";
 
177
#else
 
178
#if defined(HPUX10) && ASCII_BITS_USED == 8
 
179
  higher_pos= lower_pos= (uchar *) "";          /* Tecknen i r{tt ordning */
 
180
#else
 
181
#ifdef USE_ISO_8859_1                           /* As in USG5 ICL-386 */
 
182
  higher_pos= (uchar *) "\305\304\326\334\311";
 
183
  lower_pos=  (uchar *) "\304\305\326YE";
 
184
#else
 
185
  higher_pos= (uchar *) "][\\~`";               /* R{tt ordning p} tecknen */
 
186
  lower_pos= (uchar *)  "[\\]YE";               /* Ordning enligt ascii */
 
187
#endif /* USE_ISO_8859_1 */
 
188
#endif /* HPUX10 */
 
189
#endif /* MSDOS */
 
190
 
 
191
  while (*higher_pos)
 
192
  {
 
193
    sort_order[ *higher_pos ] =
 
194
      sort_order[(uchar)to_lower[*higher_pos]] = *lower_pos;
 
195
    higher_pos++; lower_pos++;
 
196
  }
 
197
  DBUG_VOID_RETURN;
 
198
} /* init_case_convert */