2013-11-04 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libjava / gnu / gcj / convert / gen-from-JIS.c
blobd4cca14474ecabbbde43ccce6890363f6a7bb1b2
1 /* Copyright (C) 1999, 2008 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 #include <string.h>
11 #include <stdlib.h>
12 #include "make-trie.h"
14 struct chval
16 unsigned char b1; /* 1st byte */
17 unsigned char b2; /* 2nd byte */
18 unsigned short uc; /* unicode value */
21 #define MAP(B1, B2, C) { B1, B2, C },
23 struct chval chtab_0201[] = {
24 #include "JIS0201.h"
25 { 255, 255, 0}
28 struct chval chtab_0208[] = {
29 #include "JIS0208.h"
30 { 255, 255, 0}
33 struct chval chtab_0212[] = {
34 #include "JIS0212.h"
35 { 255, 255, 0}
37 #undef MAP
39 struct chval sorted[] = {
40 #define MAP(B1, B2, C) { B1, B2, C },
41 #include "JIS0208.h"
42 #undef MAP
43 #define MAP(B1, B2, C) { 0x80|B1, B2, C },
44 #include "JIS0212.h"
45 #undef MAP
48 struct chval *chtab;
50 int
51 compare (void *p1, void *p2)
53 struct chval *c1 = (struct chval *) p1;
54 struct chval *c2 = (struct chval *) p2;
55 return (int) c1->uc - (int) c2->uc;
58 int
59 main(int argc, char** argv)
61 FILE *out = stdout;
62 int min1 = 256, max1 = 0, min2 = 256, max2 = 0, count = 0;
63 int low1_uc = 0xFFFF, high1_uc = 0;
64 int low2_uc = 0xFFFF, high2_uc = 0;
65 int i; int row, col;
66 if (argc < 2)
68 fprintf (stderr, "missing argument!\n");
69 exit (-1);
71 if (strcmp (argv[1], "JIS0208") == 0)
72 chtab = chtab_0208;
73 else if (strcmp (argv[1], "JIS0212") == 0)
74 chtab = chtab_0212;
75 else if (strcmp (argv[1], "toJIS") == 0)
77 int i;
78 for (i = 0; chtab_0201[i].b1 != 255; i++)
80 enter(chtab_0201[i].uc, chtab_0201[i].b2);
82 for (i = 0; i < 0x20; i++)
84 enter (i, i);
86 enter (127, 127);
87 for (i = 0; chtab_0208[i].b1 != 255; i++)
89 enter(chtab_0208[i].uc,
90 (chtab_0208[i].b1 << 8) | chtab_0208[i].b2);
92 for (i = 0; chtab_0212[i].b1 != 255; i++)
94 enter(chtab_0212[i].uc,
95 0x8000 | (chtab_0212[i].b1 << 8) | chtab_0212[i].b2);
97 print_table ("Unicode_to_JIS", stdout);
98 exit(0);
100 else
102 fprintf (stderr, "bad argument!");
103 exit (-1);
105 for (i = 0; chtab[i].b1 != 255; i++)
107 if (chtab[i].b1 < min1) min1 = chtab[i].b1;
108 if (chtab[i].b2 < min2) min2 = chtab[i].b2;
109 if (chtab[i].b1 > max1) max1 = chtab[i].b1;
110 if (chtab[i].b2 > max2) max2 = chtab[i].b2;
111 count++;
113 fprintf(stderr, "1st byte ranges from %d to %d.\n", min1, max1);
114 fprintf(stderr, "2nd byte ranges from %d to %d.\n", min2, max2);
116 fprintf(out,"/* This file is automatically generated from %s.TXT. */\n",
117 argv[1]);
118 fprintf(out,"#pragma GCC java_exceptions\n");
119 fprintf(out, "unsigned short %s_to_Unicode[%d][%d] = {\n",
120 argv[1], max1 - min1 + 1, max2 - min2 + 1);
121 i = 0;
122 for (row = min1; row <= max1; row++)
124 fprintf(out, "/* 1st byte: %d */ { ", row);
125 if (row < chtab[i].b1)
127 fprintf(out, "0 }, /* unused row */\n");
129 else if (row > chtab[i].b1)
131 fprintf (stderr, "error - char table out of order!\n");
132 exit (-1);
134 else
136 fprintf(out, "\n");
137 for (col = min2; col <= max2; col++)
139 if (row == chtab[i].b1 && col == chtab[i].b2)
141 int uc = chtab[i].uc;
142 if (uc < 0x2000)
144 if (uc > high1_uc)
145 high1_uc = uc;
146 if (uc < low1_uc)
147 low1_uc = uc;
149 else
151 if (uc > high2_uc)
152 high2_uc = uc;
153 if (uc < low2_uc)
154 low2_uc = uc;
156 fprintf (out, " /* 2nd byte: %d */ 0x%04x",
157 chtab[i].b2, uc);
158 i++;
160 else if (row < chtab[i].b1
161 || (row == chtab[i].b1 && col < chtab[i].b2))
163 fprintf (out, " 0");
165 else
167 fprintf (stderr, "error - char table out of order!\n");
168 exit (-1);
170 if (col != max2)
171 fprintf (out, ",\n");
173 fprintf(out, row == max1 ? "}\n" : "},\n");
176 fprintf(out, "};\n");
177 fprintf(stderr, "total number of characters is %d.\n", count);
178 fprintf(stderr, "Range is 0x%04x-0x%04x and 0x%04x-0x%04x.\n",
179 low1_uc, high1_uc, low2_uc, high2_uc);
180 return 0;