~vadim-tk/percona-server/percona-5.5.15-galera

« back to all changes in this revision

Viewing changes to strings/uctypedump.c

  • Committer: root
  • Date: 2011-09-10 16:37:18 UTC
  • Revision ID: root@r815.office.percona.com-20110910163718-ydh4zj8hcdgoyavb
Porting Galera to 5.5.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2006 MySQL AB
 
2
   Use is subject to license terms.
 
3
 
 
4
   This program is free software; you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation; version 2 of the License.
 
7
 
 
8
   This program is distributed in the hope that it will be useful,
 
9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
   GNU General Public License for more details.
 
12
 
 
13
   You should have received a copy of the GNU General Public License
 
14
   along with this program; if not, write to the Free Software
 
15
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
 
16
 
 
17
/*
 
18
#include <stdio.h>
 
19
#include <stdlib.h>
 
20
#include <string.h>
 
21
*/
 
22
#include <my_global.h>
 
23
#include <m_string.h>
 
24
#include <m_ctype.h>
 
25
#include "m_ctype.h"
 
26
 
 
27
 
 
28
typedef struct my_ctype_name_st
 
29
{
 
30
  const char *name;
 
31
  int val;
 
32
} MY_CTYPE_NAME_ST;
 
33
 
 
34
 
 
35
static MY_CTYPE_NAME_ST my_ctype_name[]=
 
36
{
 
37
  {"Lu", _MY_U},                /* Letter, Uppercase          */
 
38
  {"Ll", _MY_L},                /* Letter, Lowercase          */
 
39
  {"Lt", _MY_U},                /* Letter, Titlecase          */
 
40
  {"Lm", _MY_L},                /* Letter, Modifier           */
 
41
  {"Lo", _MY_L},                /* Letter, other              */
 
42
  
 
43
  {"Nd", _MY_NMR},              /* Number, Decimal Digit      */
 
44
  {"Nl", _MY_NMR|_MY_U|_MY_L},  /* Number, Letter             */
 
45
  {"No", _MY_NMR|_MY_PNT},      /* Number, Other              */
 
46
  
 
47
  {"Mn", _MY_L|_MY_PNT},        /* Mark, Nonspacing           */
 
48
  {"Mc", _MY_L|_MY_PNT},        /* Mark, Spacing Combining    */
 
49
  {"Me", _MY_L|_MY_PNT},        /* Mark, Enclosing            */
 
50
  
 
51
  {"Pc", _MY_PNT},              /* Punctuation, Connector     */
 
52
  {"Pd", _MY_PNT},              /* Punctuation, Dash          */
 
53
  {"Ps", _MY_PNT},              /* Punctuation, Open          */
 
54
  {"Pe", _MY_PNT},              /* Punctuation, Close         */
 
55
  {"Pi", _MY_PNT},              /* Punctuation, Initial quote */
 
56
  {"Pf", _MY_PNT},              /* Punctuation, Final quote   */
 
57
  {"Po", _MY_PNT},              /* Punctuation, Other         */
 
58
  
 
59
  {"Sm", _MY_PNT},              /* Symbol, Math               */
 
60
  {"Sc", _MY_PNT},              /* Symbol, Currency           */
 
61
  {"Sk", _MY_PNT},              /* Symbol, Modifier           */
 
62
  {"So", _MY_PNT},              /* Symbol, Other              */
 
63
  
 
64
  {"Zs", _MY_SPC},              /* Separator, Space           */
 
65
  {"Zl", _MY_SPC},              /* Separator, Line            */
 
66
  {"Zp", _MY_SPC},              /* Separator, Paragraph       */
 
67
  
 
68
  {"Cc", _MY_CTR},              /* Other, Control             */
 
69
  {"Cf", _MY_CTR},              /* Other, Format              */
 
70
  {"Cs", _MY_CTR},              /* Other, Surrogate           */
 
71
  {"Co", _MY_CTR},              /* Other, Private Use         */
 
72
  {"Cn", _MY_CTR},              /* Other, Not Assigned        */
 
73
  {NULL, 0}
 
74
};
 
75
 
 
76
 
 
77
static int
 
78
ctypestr2num(const char *tok)
 
79
{
 
80
  MY_CTYPE_NAME_ST *p;
 
81
  for (p= my_ctype_name; p->name; p++)
 
82
  {
 
83
    if (!strncasecmp(p->name, tok, 2))
 
84
      return p->val;
 
85
  }
 
86
  return 0;
 
87
}
 
88
 
 
89
 
 
90
int main(int ac, char ** av)
 
91
{
 
92
  char str[1024];
 
93
  unsigned char ctypea[64*1024];
 
94
  size_t i;
 
95
  size_t plane;
 
96
  MY_UNI_CTYPE uctype[256];
 
97
  FILE *f= stdin;
 
98
 
 
99
  if (ac > 1 && av[1] && !(f= fopen(av[1],"r")))
 
100
  {
 
101
    fprintf(stderr, "Can't open file %s\n", av[1]);
 
102
    exit(1);
 
103
  }
 
104
  bzero(&ctypea,sizeof(ctypea));
 
105
  bzero(&uctype, sizeof(uctype));
 
106
  
 
107
  printf("/*\n");
 
108
  printf("  Unicode ctype data\n");
 
109
  printf("  Generated from %s\n", av[1] ? av[1] : "stdin");
 
110
  printf("*/\n");
 
111
  
 
112
  while(fgets(str, sizeof(str), f))
 
113
  {
 
114
    size_t n= 0, code= 0;
 
115
    char *s,*e;
 
116
    int ctype= 0;
 
117
    
 
118
    for(s= str; s; )
 
119
    {
 
120
      char *end;
 
121
      char tok[1024]="";
 
122
      e=strchr(s,';');
 
123
      if(e)
 
124
      {
 
125
        strncpy(tok,s,(unsigned int)(e-s));
 
126
        tok[e-s]=0;
 
127
      }
 
128
      else
 
129
      {
 
130
        strcpy(tok,s);
 
131
      }
 
132
      
 
133
      end=tok+strlen(tok);
 
134
      
 
135
      switch(n)
 
136
      {
 
137
        case 0: code= strtol(tok,&end,16);break;
 
138
        case 2: ctype= ctypestr2num(tok);break;
 
139
      }
 
140
      
 
141
      n++;
 
142
      if(e)  s=e+1;
 
143
      else  s=e;
 
144
    }
 
145
    if(code<=0xFFFF)
 
146
    {
 
147
      ctypea[code]= ctype;
 
148
    }
 
149
  }
 
150
  
 
151
  /* Fill digits */
 
152
  for (i= '0'; i <= '9'; i++)
 
153
    ctypea[i]= _MY_NMR;
 
154
    
 
155
  for (i= 'a'; i <= 'z'; i++)
 
156
    ctypea[i]|= _MY_X;
 
157
  for (i= 'A'; i <= 'Z'; i++)
 
158
    ctypea[i]|= _MY_X;
 
159
  
 
160
  
 
161
  /* Fill ideographs  */
 
162
  
 
163
  /* CJK Ideographs Extension A (U+3400 - U+4DB5) */
 
164
  for(i=0x3400;i<=0x4DB5;i++)
 
165
  {
 
166
    ctypea[i]= _MY_L | _MY_U;
 
167
  }
 
168
  
 
169
  /* CJK Ideographs (U+4E00 - U+9FA5) */
 
170
  for(i=0x4E00;i<=0x9FA5;i++){
 
171
    ctypea[i]= _MY_L | _MY_U;
 
172
  }
 
173
  
 
174
  /* Hangul Syllables (U+AC00 - U+D7A3)  */
 
175
  for(i=0xAC00;i<=0xD7A3;i++)
 
176
  {
 
177
    ctypea[i]= _MY_L | _MY_U;
 
178
  }
 
179
  
 
180
  
 
181
  /* Calc plane parameters */
 
182
  for(plane=0;plane<256;plane++)
 
183
  {
 
184
    size_t character;
 
185
    uctype[plane].ctype= ctypea+plane*256;
 
186
    
 
187
    uctype[plane].pctype= uctype[plane].ctype[0];
 
188
    for(character=1;character<256;character++)
 
189
    {
 
190
      if (uctype[plane].ctype[character] != uctype[plane].pctype)
 
191
      {
 
192
        uctype[plane].pctype= 0; /* Mixed plane */
 
193
        break;
 
194
      }
 
195
    }
 
196
    if (character==256) /* All the same, no needs to dump whole plane */
 
197
      uctype[plane].ctype= NULL; 
 
198
  }
 
199
  
 
200
  /* Dump mixed planes */
 
201
  for(plane=0;plane<256;plane++)
 
202
  {
 
203
    if(uctype[plane].ctype)
 
204
    {
 
205
      int charnum=0;
 
206
      int num=0;
 
207
      
 
208
      printf("static unsigned char uctype_page%02X[256]=\n{\n",plane);
 
209
      
 
210
      for(charnum=0;charnum<256;charnum++)
 
211
      {
 
212
        int cod;
 
213
        
 
214
        cod=(plane<<8)+charnum;
 
215
        printf(" %2d%s",uctype[plane].ctype[charnum],charnum<255?",":"");
 
216
      
 
217
        num++;
 
218
        if(num==16)
 
219
        {
 
220
          printf("\n");
 
221
          num=0;
 
222
        }
 
223
      }
 
224
      printf("};\n\n");
 
225
    }
 
226
  }
 
227
  
 
228
  
 
229
  /* Dump plane index */
 
230
  printf("MY_UNI_CTYPE my_uni_ctype[256]={\n");
 
231
  for(plane=0;plane<256;plane++)
 
232
  {
 
233
    char plane_name[128]="NULL";
 
234
    if(uctype[plane].ctype){
 
235
      sprintf(plane_name,"uctype_page%02X",plane);
 
236
    }
 
237
    printf("\t{%d,%s}%s\n",uctype[plane].pctype,plane_name,plane<255?",":"");
 
238
  }
 
239
  printf("};\n");
 
240
  
 
241
  return 0;
 
242
}