MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
utr11-dump.c
1 /* Copyright (c) 2004, 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 #include <stdio.h>
18 #include <stdlib.h>
19 #include <string.h>
20 
21 
22 /*
23  Dump an EastAsianWidth.txt file.
24  See http://www.unicode.org/reports/tr11/ for details.
25  Character types:
26  F - Full width = 1
27  H - Half width = 0
28  W - Wide = 1
29  Na - Narrow = 0
30  A - Ambiguous = 0
31  N - Neutral = 0
32 */
33 
34 
35 int main(int ac, char **av)
36 {
37  char str[128];
38  int errors= 0;
39  int plane[0x10000];
40  int page[256];
41  int i;
42 
43  memset(plane, 0, sizeof(plane));
44  memset(page, 0, sizeof(page));
45 
46  while (fgets(str, sizeof(str), stdin))
47  {
48  int code1, code2, width;
49  char *end;
50 
51  if (str[0] == '#')
52  continue;
53  code1= strtol(str, &end, 16);
54  if (code1 < 0 || code1 > 0xFFFF)
55  continue;
56  if (end[0] == ';') /* One character */
57  {
58  code2= code1;
59  }
60  else if (end[0] == '.' && end[1] == '.') /* Range */
61  {
62  end+= 2;
63  code2= strtol(end, &end, 16);
64  if (code2 < 0 || code2 > 0xFFFF)
65  continue;
66  if (end[0] != ';')
67  {
68  errors++;
69  fprintf(stderr, "error: %s", str);
70  continue;
71  }
72  }
73  else
74  {
75  errors++;
76  fprintf(stderr, "error: %s", str);
77  continue;
78  }
79 
80  end++;
81  width= (end[0] == 'F' || end[0] == 'W') ? 1 : 0;
82 
83  for ( ; code1 <= code2; code1++)
84  {
85  plane[code1]= width;
86  }
87  }
88 
89  if (errors)
90  return 1;
91 
92  for (i=0; i < 256; i++)
93  {
94  int j;
95  int *p= plane + 256 * i;
96  page[i]= 0;
97  for (j=0; j < 256; j++)
98  {
99  page[i]+= p[j];
100  }
101  if (page[i] != 0 && page[i] != 256)
102  {
103  printf("static char pg%02X[256]=\n{\n", i);
104  for (j=0; j < 256; j++)
105  {
106  printf("%d%s%s", p[j], j < 255 ? "," : "", (j + 1) % 32 ? "" : "\n");
107  }
108  printf("};\n\n");
109  }
110  }
111 
112  printf("static struct {int page; char *p;} utr11_data[256]=\n{\n");
113  for (i=0; i < 256; i++)
114  {
115  if (page[i] == 0 || page[i] == 256)
116  {
117  int width= (page[i] == 256) ? 1 : 0;
118  printf("{%d,NULL}", width);
119  }
120  else
121  {
122  printf("{0,pg%02X}", i);
123  }
124  printf("%s%s", i < 255 ? "," : "", (i+1) % 8 ? "" : "\n");
125  }
126  printf("};\n");
127  return 0;
128 }