source: trunk/gcc/libjava/gnu/gcj/convert/gen-from-JIS.c

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.9 KB
Line 
1/* Copyright (C) 1999 Free Software Foundation
2
3 This file is part of libgcj.
4
5This software is copyrighted work licensed under the terms of the
6Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7details. */
8
9#include <stdio.h>
10struct 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
19struct chval chtab_0201[] = {
20#include "JIS0201.h"
21 { 255, 255, 0}
22};
23
24struct chval chtab_0208[] = {
25#include "JIS0208.h"
26 { 255, 255, 0}
27};
28
29struct chval chtab_0212[] = {
30#include "JIS0212.h"
31 { 255, 255, 0}
32};
33#undef MAP
34
35struct 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
44struct chval *chtab;
45
46int
47compare (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
54int
55main(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,"#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++)
115 {
116 fprintf(out, "/* 1st byte: %d */ { ", row);
117 if (row < chtab[i].b1)
118 {
119 fprintf(out, "0 }, /* unused row */\n");
120 }
121 else if (row > chtab[i].b1)
122 {
123 fprintf (stderr, "error - char table out of order!\n");
124 exit (-1);
125 }
126 else
127 {
128 fprintf(out, "\n");
129 for (col = min2; col <= max2; col++)
130 {
131 if (row == chtab[i].b1 && col == chtab[i].b2)
132 {
133 int uc = chtab[i].uc;
134 if (uc < 0x2000)
135 {
136 if (uc > high1_uc)
137 high1_uc = uc;
138 if (uc < low1_uc)
139 low1_uc = uc;
140 }
141 else
142 {
143 if (uc > high2_uc)
144 high2_uc = uc;
145 if (uc < low2_uc)
146 low2_uc = uc;
147 }
148 fprintf (out, " /* 2nd byte: %d */ 0x%04x",
149 chtab[i].b2, uc);
150 i++;
151 }
152 else if (row < chtab[i].b1
153 || (row == chtab[i].b1 && col < chtab[i].b2))
154 {
155 fprintf (out, " 0");
156 }
157 else
158 {
159 fprintf (stderr, "error - char table our of order!\n");
160 exit (-1);
161 }
162 if (col != max2)
163 fprintf (out, ",\n");
164 }
165 fprintf(out, row == max1 ? "}\n" : "},\n");
166 }
167 }
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;
173}
Note: See TracBrowser for help on using the repository browser.