~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/utr11-dump.c

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

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