2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / gnu / gcj / convert / gen-from-JIS.c
blob13745805ab8875c02916a21cefd2b8903884313e
1 /* Copyright (C) 1999 Free Software Foundation
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 #include <stdio.h>
10 struct chval
12 unsigned char b1; /* 1st byte */
13 unsigned char b2; /* 2nd byte */
14 unsigned short uc; /* unicode value */
17 #define MAP(B1, B2, C) { B1, B2, C },
19 struct chval chtab_0201[] = {
20 #include "JIS0201.h"
21 { 255, 255, 0}
24 struct chval chtab_0208[] = {
25 #include "JIS0208.h"
26 { 255, 255, 0}
29 struct chval chtab_0212[] = {
30 #include "JIS0212.h"
31 { 255, 255, 0}
33 #undef MAP
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
44 struct chval *chtab;
46 int
47 compare (void *p1, void *p2)
49 struct chval *c1 = (struct chval *) p1;
50 struct chval *c2 = (struct chval *) p2;
51 return (int) c1->uc - (int) c2->uc;
54 int
55 main(int argc, char** argv)
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)
68 int i;
69 for (i = 0; chtab_0201[i].b1 != 255; i++)
71 enter(chtab_0201[i].uc, chtab_0201[i].b2);
73 for (i = 0; i < 0x20; i++)
75 enter (i, i);
77 enter (127, 127);
78 for (i = 0; chtab_0208[i].b1 != 255; i++)
80 enter(chtab_0208[i].uc,
81 (chtab_0208[i].b1 << 8) | chtab_0208[i].b2);
83 for (i = 0; chtab_0212[i].b1 != 255; i++)
85 enter(chtab_0212[i].uc,
86 0x8000 | (chtab_0212[i].b1 << 8) | chtab_0212[i].b2);
88 print_table ("Unicode_to_JIS", stdout);
89 exit(0);
91 else
93 fprintf (stderr, "bad argument!");
94 exit (-1);
96 for (i = 0; chtab[i].b1 != 255; i++)
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++;
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);
107 fprintf(out,"/* This file is automatically generated from %s.TXT. */\n",
108 argv[1]);
109 fprintf(out,"#pragma GCC java_exceptions\n",
110 argv[1]);
111 fprintf(out, "unsigned short %s_to_Unicode[%d][%d] = {\n",
112 argv[1], max1 - min1 + 1, max2 - min2 + 1);
113 i = 0;
114 for (row = min1; row <= max1; row++)
116 fprintf(out, "/* 1st byte: %d */ { ", row);
117 if (row < chtab[i].b1)
119 fprintf(out, "0 }, /* unused row */\n");
121 else if (row > chtab[i].b1)
123 fprintf (stderr, "error - char table out of order!\n");
124 exit (-1);
126 else
128 fprintf(out, "\n");
129 for (col = min2; col <= max2; col++)
131 if (row == chtab[i].b1 && col == chtab[i].b2)
133 int uc = chtab[i].uc;
134 if (uc < 0x2000)
136 if (uc > high1_uc)
137 high1_uc = uc;
138 if (uc < low1_uc)
139 low1_uc = uc;
141 else
143 if (uc > high2_uc)
144 high2_uc = uc;
145 if (uc < low2_uc)
146 low2_uc = uc;
148 fprintf (out, " /* 2nd byte: %d */ 0x%04x",
149 chtab[i].b2, uc);
150 i++;
152 else if (row < chtab[i].b1
153 || (row == chtab[i].b1 && col < chtab[i].b2))
155 fprintf (out, " 0");
157 else
159 fprintf (stderr, "error - char table our of order!\n");
160 exit (-1);
162 if (col != max2)
163 fprintf (out, ",\n");
165 fprintf(out, row == max1 ? "}\n" : "},\n");
168 fprintf(out, "};\n");
169 fprintf(stderr, "total number of characters is %d.\n", count);
170 fprintf(stderr, "Range is 0x%04x-0x%04x and 0x%04x-0x%04x.\n",
171 low1_uc, high1_uc, low2_uc, high2_uc);
172 return 0;