OSDN Git Service

4df25bc5444619eb314ed0a5624e7afa333b7eea
[pf3gnuchains/gcc-fork.git] / libjava / gnu / gcj / convert / gen-from-JIS.c
1 /* Copyright (C) 1999  Cygnus Solutions
2
3    This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7 details.  */
8
9 #include <stdio.h>
10 struct chval
11 {
12   unsigned char b1;            /* 1st byte */
13   unsigned char b2;            /* 2nd byte */
14   unsigned short uc;  /* unicode value */
15 };
16
17 #define MAP(B1, B2, C) { B1, B2, C },
18
19 struct chval chtab_0201[] = {
20 #include "JIS0201.h"
21   { 255, 255, 0}
22 };
23
24 struct chval chtab_0208[] = {
25 #include "JIS0208.h"
26   { 255, 255, 0}
27 };
28
29 struct chval chtab_0212[] = {
30 #include "JIS0212.h"
31   { 255, 255, 0}
32 };
33 #undef MAP
34
35 struct chval sorted[] = {
36 #define MAP(B1, B2, C) { B1, B2, C },
37 #include "JIS0208.h"
38 #undef MAP
39 #define MAP(B1, B2, C) { 0x80|B1, B2, C },
40 #include "JIS0212.h"
41 #undef MAP
42 };
43
44 struct chval *chtab;
45
46 int
47 compare (void *p1, void *p2)
48 {
49   struct chval *c1 = (struct chval *) p1;
50   struct chval *c2 = (struct chval *) p2;
51   return (int) c1->uc - (int) c2->uc;
52 }
53
54 int
55 main(int argc, char** argv)
56 {
57   FILE *out = stdout;
58   int min1 = 256, max1 = 0, min2 = 256, max2 = 0, count = 0;
59   int low1_uc = 0xFFFF, high1_uc = 0;
60   int low2_uc = 0xFFFF, high2_uc = 0;
61   int i;  int row, col;
62   if (strcmp (argv[1], "JIS0208") == 0)
63     chtab = chtab_0208;
64   else if (strcmp (argv[1], "JIS0212") == 0)
65     chtab = chtab_0212;
66   else if (strcmp (argv[1], "toJIS") == 0)
67     {
68       int i;
69       for (i = 0;  chtab_0201[i].b1 != 255;  i++)
70         {
71           enter(chtab_0201[i].uc, chtab_0201[i].b2);
72         }
73       for (i = 0;  i < 0x20;  i++)
74         {
75           enter (i, i);
76         }
77       enter (127, 127);
78       for (i = 0;  chtab_0208[i].b1 != 255;  i++)
79         {
80           enter(chtab_0208[i].uc,
81                 (chtab_0208[i].b1 << 8) | chtab_0208[i].b2);
82         }
83       for (i = 0;  chtab_0212[i].b1 != 255;  i++)
84         {
85           enter(chtab_0212[i].uc,
86                 0x8000 | (chtab_0212[i].b1 << 8) | chtab_0212[i].b2);
87         }
88       print_table ("Unicode_to_JIS", stdout);
89       exit(0);
90     }
91   else
92     {
93       fprintf (stderr, "bad argument!");
94       exit (-1);
95     }
96   for (i = 0;  chtab[i].b1 != 255; i++)
97     {
98       if (chtab[i].b1 < min1) min1 = chtab[i].b1;
99       if (chtab[i].b2 < min2) min2 = chtab[i].b2;
100       if (chtab[i].b1 > max1) max1 = chtab[i].b1;
101       if (chtab[i].b2 > max2) max2 = chtab[i].b2;
102       count++;
103     }
104   fprintf(stderr, "1st byte ranges from %d to %d.\n", min1, max1);
105   fprintf(stderr, "2nd byte ranges from %d to %d.\n", min2, max2);
106
107   fprintf(out,"/* This file is automatically generated from %s.TXT. */\n",
108           argv[1]);
109   fprintf(out, "unsigned short %s_to_Unicode[%d][%d] = {\n",
110           argv[1], max1 - min1 + 1,  max2 - min2 + 1);
111   i = 0;
112   for (row = min1;  row <= max1;  row++)
113     {
114       fprintf(out, "/* 1st byte: %d */ { ", row);
115       if (row < chtab[i].b1)
116         {
117           fprintf(out, "0 }, /* unused row */\n");
118         }
119       else if (row > chtab[i].b1)
120         {
121           fprintf (stderr, "error - char table out of order!\n");
122           exit (-1);
123         }
124       else
125         {
126           fprintf(out, "\n");
127           for (col = min2;  col <= max2;  col++)
128             {
129               if (row == chtab[i].b1 && col == chtab[i].b2)
130                 {
131                   int uc = chtab[i].uc;
132                   if (uc < 0x2000)
133                     {
134                       if (uc > high1_uc)
135                         high1_uc = uc;
136                       if (uc < low1_uc)
137                         low1_uc = uc;
138                     }
139                   else
140                     {
141                       if (uc > high2_uc)
142                         high2_uc = uc;
143                       if (uc < low2_uc)
144                         low2_uc = uc;
145                     }
146                   fprintf (out, "  /* 2nd byte: %d */ 0x%04x",
147                            chtab[i].b2, uc);
148                   i++;
149                 }
150               else if (row < chtab[i].b1
151                   || (row == chtab[i].b1 && col < chtab[i].b2))
152                 {
153                   fprintf (out, "  0");
154                 }
155               else
156                 {
157                   fprintf (stderr, "error - char table our of order!\n");
158                   exit (-1);
159                 }
160               if (col != max2)
161                 fprintf (out, ",\n");
162             }
163           fprintf(out, row == max1 ? "}\n" : "},\n");
164         }
165     }
166   fprintf(out, "};\n");
167   fprintf(stderr, "total number of characters is %d.\n", count);
168   fprintf(stderr, "Range is 0x%04x-0x%04x and 0x%04x-0x%04x.\n",
169           low1_uc, high1_uc, low2_uc, high2_uc);
170   return 0;
171 }