mkkanji.c
13.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
/*---------------------------------------------------------------------
Copyright (C) 1998 Nintendo.
File mkkanji.c
Coded by Tetsuyuki Ootsuka. July, 1998.
Comments Make kanji font data table
$Id:
---------------------------------------------------------------------*/
#include <stdio.h>
extern unsigned char kanrom[]; /* 漢字 ROM フォント */
/*--- SJIS漢字変換テーブル ---*/
short kantbl[] = {
0x000,0x001,0x002,0x003,0x004,0x005,0x006,0x007,
0x008,0x009,0x00A,0x00B,0x00C,0x00D,0x00E,0x00F,
0x010,0x011,0x012,0x013,0x014,0x015,0x016,0x017,
0x018,0x019,0x01A,0x01B,0x01C,0x01D,0x01E,0x01F,
0x020,0x021,0x022,0x023,0x024,0x025,0x026,0x027,
0x028,0x029,0x02A,0x02B,0x02C,0x02D,0x02E,0x02F,
0x030,0x031,0x032,0x033,0x034,0x035,0x036,0x037,
0x038,0x039,0x03A,0x03B,0x03C,0x03D,0x03E,0x03F,
0x040,0x041,0x042,0x043,0x044,0x045,0x046,0x047,
0x048,0x049,0x04A,0x04B,0x04C,0x04D,0x04E,0x04F,
0x050,0x051,0x052,0x053,0x054,0x055,0x056,0x057,
0x058,0x059,0x05A,0x05B,0x05C,0x05D,0x05E,0x05F,
0x060,0x061,0x062,0x063,0x064,0x065,0x066,0x067,
0x068,0x069,0x06A,0x06B,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x06C,
0x06D,0x06E,0x06F,0x070,0x071,0x072,0x073,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x074,
0x075,0x076,0x077,0x078,0x079,0x07A,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x07B,0x07C,0x07D,0x07E,0x07F,0x080,
0x081,0x082,0x083,0x084,0x085,0x086,0x087,0x088,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x089,
0x08A,0x08B,0x08C,0x08D,0x08E,0x08F,0x090,0x000,
0x000,0x000,0x000,0x091,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x092,0x093,0x094,0x095,0x096,
0x097,0x098,0x099,0x09A,0x09B,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x09C,0x09D,0x09E,0x09F,
0x0A0,0x0A1,0x0A2,0x0A3,0x0A4,0x0A5,0x0A6,0x0A7,
0x0A8,0x0A9,0x0AA,0x0AB,0x0AC,0x0AD,0x0AE,0x0AF,
0x0B0,0x0B1,0x0B2,0x0B3,0x0B4,0x0B5,0x000,0x000,
0x000,0x000,0x000,0x000,0x0B6,0x0B7,0x0B8,0x0B9,
0x0BA,0x0BB,0x0BC,0x0BD,0x0BE,0x0BF,0x0C0,0x0C1,
0x0C2,0x0C3,0x0C4,0x0C5,0x0C6,0x0C7,0x0C8,0x0C9,
0x0CA,0x0CB,0x0CC,0x0CD,0x0CE,0x0CF,0x000,0x000,
0x000,0x000,0x0D0,0x0D1,0x0D2,0x0D3,0x0D4,0x0D5,
0x0D6,0x0D7,0x0D8,0x0D9,0x0DA,0x0DB,0x0DC,0x0DD,
0x0DE,0x0DF,0x0E0,0x0E1,0x0E2,0x0E3,0x0E4,0x0E5,
0x0E6,0x0E7,0x0E8,0x0E9,0x0EA,0x0EB,0x0EC,0x0ED,
0x0EE,0x0EF,0x0F0,0x0F1,0x0F2,0x0F3,0x0F4,0x0F5,
0x0F6,0x0F7,0x0F8,0x0F9,0x0FA,0x0FB,0x0FC,0x0FD,
0x0FE,0x0FF,0x100,0x101,0x102,0x103,0x104,0x105,
0x106,0x107,0x108,0x109,0x10A,0x10B,0x10C,0x10D,
0x10E,0x10F,0x110,0x111,0x112,0x113,0x114,0x115,
0x116,0x117,0x118,0x119,0x11A,0x11B,0x11C,0x11D,
0x11E,0x11F,0x120,0x121,0x122,0x123,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x124,0x125,0x126,0x127,0x128,0x129,0x12A,0x12B,
0x12C,0x12D,0x12E,0x12F,0x130,0x131,0x132,0x133,
0x134,0x135,0x136,0x137,0x138,0x139,0x13A,0x13B,
0x13C,0x13D,0x13E,0x13F,0x140,0x141,0x142,0x143,
0x144,0x145,0x146,0x147,0x148,0x149,0x14A,0x14B,
0x14C,0x14D,0x14E,0x14F,0x150,0x151,0x152,0x153,
0x154,0x155,0x156,0x157,0x158,0x159,0x15A,0x15B,
0x15C,0x15D,0x15E,0x15F,0x160,0x161,0x162,0x163,
0x164,0x165,0x166,0x167,0x168,0x169,0x16A,0x16B,
0x16C,0x16D,0x16E,0x16F,0x170,0x171,0x172,0x173,
0x174,0x175,0x176,0x177,0x178,0x179,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x17A,0x17B,
0x17C,0x17D,0x17E,0x17F,0x180,0x181,0x182,0x183,
0x184,0x185,0x186,0x187,0x188,0x189,0x18A,0x18B,
0x18C,0x18D,0x18E,0x18F,0x190,0x191,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x192,0x193,
0x194,0x195,0x196,0x197,0x198,0x199,0x19A,0x19B,
0x19C,0x19D,0x19E,0x19F,0x1A0,0x1A1,0x1A2,0x1A3,
0x1A4,0x1A5,0x1A6,0x1A7,0x1A8,0x1A9,0x1AA,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x1AB,0x1AC,0x1AD,0x1AE,
0x1AF,0x1B0,0x1B1,0x1B2,0x1B3,0x1B4,0x1B5,0x1B6,
0x1B7,0x1B8,0x1B9,0x1BA,0x1BB,0x1BC,0x1BD,0x1BE,
0x1BF,0x1C0,0x1C1,0x1C2,0x1C3,0x1C4,0x1C5,0x1C6,
0x1C7,0x1C8,0x1C9,0x1CA,0x1CB,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x1CC,0x1CD,0x1CE,0x1CF,
0x1D0,0x1D1,0x1D2,0x1D3,0x1D4,0x1D5,0x1D6,0x1D7,
0x1D8,0x1D9,0x1DA,0x1DB,0x1DC,0x1DD,0x1DE,0x1DF,
0x1E0,0x1E1,0x1E2,0x1E3,0x1E4,0x1E5,0x1E6,0x1E7,
0x1E8,0x1E9,0x1EA,0x1EB,0x1EC,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x1ED,0x1EE,0x1EF,0x1F0,0x1F1,0x1F2,
0x1F3,0x1F4,0x1F5,0x1F6,0x1F7,0x1F8,0x1F9,0x1FA,
0x1FB,0x1FC,0x1FD,0x1FE,0x1FF,0x200,0x201,0x202,
0x203,0x204,0x205,0x206,0x207,0x208,0x209,0x20A,
0x20B,0x20C,0x20D,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x20E,0x20F,0x210,0x211,0x212,0x213,0x214,0x215,
0x216,0x217,0x218,0x219,0x21A,0x21B,0x21C,0x21D,
0x21E,0x21F,0x220,0x221,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x222,0x223,
0x224,0x225,0x226,0x227,0x228,0x229,0x22A,0x22B,
0x22C,0x22D,0x22E,0x22F,0x230,0x231,0x232,0x233,
0x234,0x235,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x236,0x237,0x238,0x239,
0x23A,0x23B,0x23C,0x23D,0x23E,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x23F,0x240,0x241,0x242,0x243,0x244,0x245,0x246,
0x247,0x248,0x000,0x000,0x000,0x000,0x249,0x24A,
0x24B,0x24C,0x24D,0x24E,0x24F,0x250,0x251,0x252,
0x253,0x254,0x255,0x256,0x257,0x000,0x000,0x000,
0x000,0x000,0x258,0x259,0x25A,0x25B,0x25C,0x25D,
0x25E,0x25F,0x260,0x261,0x262,0x263,0x264,0x265,
0x266,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x267,0x268,0x269,0x26A,0x26B,0x26C,
0x26D,0x26E,0x26F,0x270,0x271,0x272,0x273,0x274,
0x275,0x276,0x277,0x278,0x279,0x27A,0x27B,0x27C,
0x27D,0x27E,0x27F,0x280,0x281,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x282,0x283,0x284,0x285,
0x286,0x287,0x288,0x289,0x28A,0x28B,0x28C,0x28D,
0x28E,0x28F,0x290,0x291,0x292,0x293,0x294,0x295,
0x296,0x297,0x298,0x299,0x29A,0x29B,0x29C,0x29D,
0x29E,0x29F,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x2A0,0x2A1,
0x2A2,0x2A3,0x2A4,0x2A5,0x2A6,0x2A7,0x2A8,0x2A9,
0x2AA,0x2AB,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x2AC,0x2AD,
0x2AE,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x2AF,0x2B0,0x2B1,0x2B2,0x2B3,0x2B4,
0x2B5,0x2B6,0x2B7,0x2B8,0x2B9,0x2BA,0x2BB,0x2BC,
0x2BD,0x2BE,0x2BF,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x2C0,0x2C1,0x2C2,0x2C3,0x2C4,0x2C5,0x2C6,0x2C7,
0x2C8,0x2C9,0x2CA,0x2CB,0x2CC,0x2CD,0x2CE,0x2CF,
0x2D0,0x2D1,0x2D2,0x2D3,0x2D4,0x2D5,0x2D6,0x2D7,
0x2D8,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x2D9,0x2DA,0x2DB,0x2DC,0x2DD,0x2DE,0x2DF,0x2E0,
0x2E1,0x2E2,0x2E3,0x2E4,0x2E5,0x2E6,0x2E7,0x2E8,
0x2E9,0x2EA,0x2EB,0x2EC,0x2ED,0x2EE,0x2EF,0x2F0,
0x2F1,0x2F2,0x2F3,0x2F4,0x2F5,0x2F6,0x2F7,0x2F8,
0x2F9,0x2FA,0x2FB,0x2FC,0x2FD,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x2FE,0x2FF,0x300,0x301,
0x302,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x303,0x304,0x305,0x306,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x000,0x000,0x000,0x000,0x000,0x000,0x000,
0x000,0x307,0x308,0x309,
};
void
mkheader(FILE **fp){
fprintf(*fp, "/*\n");
fprintf(*fp, " * Do not edit this file. It was automatically generated");
fprintf(*fp, " by \"mkkanji\"\n");
fprintf(*fp, " */\n\n");
}
unsigned char str[2048];
unsigned int kanji_code[2048];
int
main(int argc, char **argv)
{
int h, i, j, k;
int curr_str, next_str, total_str;
int r4, r5, r6, r7;
unsigned int data = 0, num;
unsigned char c = 0;
FILE *fp1, *fp2, *fp3, *fp4, *fp5;
int now_code = 0, mes_no = 0;
if (argc < 2) {
fprintf(stderr, "usage: mkkanji [file]\n\n");
fprintf(stderr, "【入力】SJISコードで書かれたメッセージファイル\n");
fprintf(stderr, " SJISコードで書かれた認識単語ファイル\n");
fprintf(stderr, "【出力】kfont.c フォントデータ\n");
fprintf(stderr, " mes.c 文字番号配列\n");
fprintf(stderr, " mes.h 文字番号配列用ヘッダ\n");
return(-1);
}
/*--- 入力ファイル(メッセージファイル) ---*/
if((fp1 = fopen(argv[1],"r"))==0){
printf("file open error![%s]\n",argv[1]);
return(-1);
}
/*--- 入力ファイル(認識単語ファイル)---*/
if((fp2 = fopen(argv[2],"r"))==0){
printf("file open error![%s]\n",argv[2]);
return(-1);
}
/*--- 出力ファイル(文字番号テーブル) ---*/
if((fp3 = fopen("mes.c", "w"))==0){
printf("file open error![mes.c]\n");
return(-1);
}
/*--- 出力ファイル(文字番号テーブル用ヘッダ) ---*/
if((fp4 = fopen("mes.h", "w"))==0){
printf("file open error![mes.h]\n");
return(-1);
}
/*--- 出力ファイル(漢字フォント) ---*/
if((fp5 = fopen("kfont.c", "w"))==0){
printf("file open error![kfont.c]\n");
return(-1);
}
#if 0
mkheader(&fp3);
mkheader(&fp4);
mkheader(&fp5);
#endif
/*--- メッセージファイル(mes.txt)から出力ファイルを作成 ---*/
fprintf(fp4, "extern short int mes[][17];\n");
fprintf(fp5, "unsigned char kanji_font[]={\n");
for(i = 0 ; ; i++){
str[i] = fgetc(fp1);
if(feof(fp1)){
break;
}
}
total_str = i;
next_str = 0;
for(h = 0 ; h < total_str; h++){
if(str[h] == '\n'){
str[h] = NULL;
}
else{
continue;
}
curr_str = next_str;
next_str = h+1;
fprintf(fp3, "/*----------------------------------------------------------------\n %s\n----------------------------------------------------------------*/", &str[curr_str]);
fprintf(fp3, "\nshort int mes%d[]={", mes_no);
fprintf(fp4, "extern short int mes%d[];\n",mes_no++);
for (i = 0 ; str[curr_str+i] != NULL ; i+= 2) {
r4 = str[curr_str+i]*256+str[curr_str+i+1];
/*--- SJISコードからテーブル値を参照 ---*/
if (r4 < 0x8140 || r4 > 0x9872) {
return(-1);
}
r6 = 0xbc;
r5 = (r4 >> 8);
r7 = str[curr_str+i+1]-0x40;
if (r7 >= 0x40){
r7 --;
}
if (r4 > 0x8800){
r5 -= 0x88;
r6 *= r5;
r6 &= 0xffff;
r7 += (0x30a+r6);
num = r7*128;
} else {
r5 -= 0x81;
r6 *= r5;
r6 &= 0xffff;
r7 += r6;
num = kantbl[r7]*128;
}
for (j = 0 ; j < now_code ; j++ ) {
if (kanji_code[j] == num) {
break;
}
}
if (j == now_code) {
kanji_code[j] = num;
now_code++;
for (k = 0 ; k < 128 ; k++) {
fprintf(fp5, "0x%02x, ", kanrom[num+k]);
if ((k % 8) == 7) {
fprintf(fp5, "\n");
}
}
}
fprintf(fp3, "%d,", j*128);
}
fprintf(fp3, "-1};\n\n");
}
/*--- 認識単語ファイル(message.c)から出力ファイルを作成 ---*/
for(i = 0 ; ; i++){
str[i] = fgetc(fp2);
if(feof(fp2)){
break;
}
}
total_str = i;
mes_no = 0;
fprintf(fp3, "/*----------------------------------------------------------------\n %s\n----------------------------------------------------\-\-----------*/\n", "認識単語を格納する配列");
fprintf(fp3, "short int mes[][17] = {\n");
for(h = 0 ; h < total_str; h++){
if(str[h] == '"'){
}
else{
continue;
}
curr_str = h+1;
for(i = curr_str ; ; i++){
if(str[i] == '"'){
str[i] = NULL;
break;
}
}
fprintf(fp3, "{ ");
for (i = 0 ; str[curr_str+i] != NULL ; i+= 2) {
r4 = str[curr_str+i]*256+str[curr_str+i+1];
/*--- SJISコードからテーブル値を参照 ---*/
if (r4 < 0x8140 || r4 > 0x9872) {
return(-1);
}
r6 = 0xbc;
r5 = (r4 >> 8);
r7 = str[curr_str+i+1]-0x40;
if (r7 >= 0x40){
r7 --;
}
if (r4 > 0x8800){
r5 -= 0x88;
r6 *= r5;
r6 &= 0xffff;
r7 += (0x30a+r6);
num = r7*128;
} else {
r5 -= 0x81;
r6 *= r5;
r6 &= 0xffff;
r7 += r6;
num = kantbl[r7]*128;
}
for (j = 0 ; j < now_code ; j++ ) {
if (kanji_code[j] == num) {
break;
}
}
if (j == now_code) {
kanji_code[j] = num;
now_code++;
for (k = 0 ; k < 128 ; k++) {
fprintf(fp5, "0x%02x, ", kanrom[num+k]);
if ((k % 8) == 7) {
fprintf(fp5, "\n");
}
}
}
fprintf(fp3, "%d,", j*128);
}
fprintf(fp3, "-1} ,\n");
}
fprintf(fp3, "};\n");
fprintf(fp5, "};\n");
fclose(fp1);
fclose(fp2);
fclose(fp3);
fclose(fp4);
fclose(fp5);
return(0);
}