OSDN Git Service

Suppress gcc warning
[hengband/hengband.git] / src / japanese.c
1 /* File: japanese.c */
2
3
4 #include "angband.h"
5
6 #ifdef JP
7
8 typedef struct convert_key convert_key;
9
10 struct convert_key
11 {
12         cptr key1;
13         cptr key2;
14 };
15
16 static const convert_key s2j_table[] = {
17         {"mb","nb"}, {"mp","np"}, {"mv","nv"}, {"mm","nm"},
18         {"x","ks"},
19         /* sindar:¥·¥ó¥À¡¼¥ë  parantir:¥Ñ¥é¥ó¥Æ¥£¥¢  feanor:¥Õ¥§¥¢¥Î¡¼¥ë */
20         {"ar$","a-ru$"}, {"ir$","ia$"}, {"or$","o-ru$"},
21         {"ra","¥é"}, {"ri","¥ê"}, {"ru","¥ë"}, {"re","¥ì"}, {"ro","¥í"},
22         {"ir","ia"}, {"ur","ua"}, {"er","ea"}, {"ar","a¥ë"},
23         {"sha","¥·¥ã"}, {"shi","¥·"}, {"shu","¥·¥å"}, {"she","¥·¥§"}, {"sho","¥·¥ç"},
24         {"tha","¥µ"}, {"thi","¥·"}, {"thu","¥¹"}, {"the","¥»"}, {"tho","¥½"},
25         {"cha","¥Ï"}, {"chi","¥Ò"}, {"chu","¥Õ"}, {"che","¥Ø"}, {"cho","¥Û"},
26         {"dha","¥¶"}, {"dhi","¥¸"}, {"dhu","¥º"}, {"dhe","¥¼"}, {"dho","¥¾"},
27         {"ba","¥Ð"}, {"bi","¥Ó"}, {"bu","¥Ö"}, {"be","¥Ù"}, {"bo","¥Ü"},
28         {"ca","¥«"}, {"ci","¥­"}, {"cu","¥¯"}, {"ce","¥±"}, {"co","¥³"},
29         {"da","¥À"}, {"di","¥Ç¥£"}, {"du","¥É¥¥"}, {"de","¥Ç"}, {"do","¥É"},
30         {"fa","¥Õ¥¡"}, {"fi","¥Õ¥£"}, {"fu","¥Õ"}, {"fe","¥Õ¥§"}, {"fo","¥Õ¥©"},
31         {"ga","¥¬"}, {"gi","¥®"}, {"gu","¥°"}, {"ge","¥²"}, {"go","¥´"},
32         {"ha","¥Ï"}, {"hi","¥Ò"}, {"hu","¥Õ"}, {"he","¥Ø"}, {"ho","¥Û"},
33         {"ja","¥¸¥ã"}, {"ji","¥¸"}, {"ju","¥¸¥å"}, {"je","¥¸¥§"}, {"jo","¥¸¥ç"},
34         {"ka","¥«"}, {"ki","¥­"}, {"ku","¥¯"}, {"ke","¥±"}, {"ko","¥³"},
35         {"la","¥é"}, {"li","¥ê"}, {"lu","¥ë"}, {"le","¥ì"}, {"lo","¥í"},
36         {"ma","¥Þ"}, {"mi","¥ß"}, {"mu","¥à"}, {"me","¥á"}, {"mo","¥â"},
37         {"na","¥Ê"}, {"ni","¥Ë"}, {"nu","¥Ì"}, {"ne","¥Í"}, {"no","¥Î"},
38         {"pa","¥Ñ"}, {"pi","¥Ô"}, {"pu","¥×"}, {"pe","¥Ú"}, {"po","¥Ý"},
39         {"qu","¥¯"},
40         {"sa","¥µ"}, {"si","¥·"}, {"su","¥¹"}, {"se","¥»"}, {"so","¥½"},
41         {"ta","¥¿"}, {"ti","¥Æ¥£"}, {"tu","¥È¥¥"}, {"te","¥Æ"}, {"to","¥È"},
42         {"va","¥ô¥¡"}, {"vi","¥ô¥£"}, {"vu","¥ô"}, {"ve","¥ô¥§"}, {"vo","¥ô¥©"},
43         {"wa","¥ï"}, {"wi","¥¦¥£"}, {"wu","¥¦"}, {"we","¥¦¥§"}, {"wo","¥¦¥©"},
44         {"ya","¥ä"}, {"yu","¥æ"}, {"yo","¥è"},
45         {"za","¥¶"}, {"zi","¥¸"}, {"zu","¥º"}, {"ze","¥¼"}, {"zo","¥¾"},
46         {"dh","¥º"}, {"ch","¥Õ"}, {"th","¥¹"},
47         {"b","¥Ö"}, {"c","¥¯"}, {"d","¥É"}, {"f","¥Õ"}, {"g","¥°"},
48         {"h","¥Õ"}, {"j","¥¸¥å"}, {"k","¥¯"}, {"l","¥ë"}, {"m","¥à"},
49         {"n","¥ó"}, {"p","¥×"}, {"q","¥¯"}, {"r","¥ë"}, {"s","¥¹"},
50         {"t","¥È"}, {"v","¥ô"}, {"w","¥¦"}, {"y","¥¤"},
51         {"a","¥¢"}, {"i","¥¤"}, {"u","¥¦"}, {"e","¥¨"}, {"o","¥ª"},
52         {"-","¡¼"},
53         {NULL,NULL}
54 };
55
56 /* ¥·¥ó¥À¥ê¥ó¤òÆüËܸì¤ÎÆɤߤËÊÑ´¹¤¹¤ë */
57 void sindarin_to_kana(char *kana, const char *sindarin)
58 {
59         char buf[256];
60         int idx;
61
62         sprintf(kana, "%s$", sindarin);
63         for (idx = 0; kana[idx]; idx++)
64                 if (isupper(kana[idx])) kana[idx] = tolower(kana[idx]);
65
66         for (idx = 0; s2j_table[idx].key1 != NULL; idx++)
67         {
68                 cptr pat1 = s2j_table[idx].key1;
69                 cptr pat2 = s2j_table[idx].key2;
70                 int len = strlen(pat1);
71                 char *src = kana;
72                 char *dest = buf;
73
74                 while (*src)
75                 {
76                         if (strncmp(src, pat1, len) == 0)
77                         {
78                                 strcpy(dest, pat2);
79                                 src += len;
80                                 dest += strlen(pat2);
81                         }
82                         else
83                         {
84                                 if (iskanji(*src))
85                                 {
86                                         *dest = *src;
87                                         src++;
88                                         dest++;
89                                 }
90                                 *dest = *src;
91                                 src++;
92                                 dest++;
93                         }
94                 }
95
96                 *dest = 0;
97                 strcpy(kana, buf);
98         }
99
100         idx = 0;
101
102         while (kana[idx] != '$') idx++;
103
104         kana[idx] = '\0';
105 }
106
107
108 /*ÆüËܸìÆ°»ì³èÍÑ (ÂǤġäÂǤäÆ,ÂǤÁ etc) */
109
110 #define CMPTAIL(y) strncmp(&in[l-(int)strlen(y)],y,strlen(y))
111
112 /* ²¥¤ë,½³¤ë¡ä²¥¤ê,½³¤ë */
113 void jverb1( const char *in , char *out){
114 int l=strlen(in);
115 strcpy(out,in);
116
117 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·");else
118 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤Æ");else
119
120 if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨");else
121 if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±");else
122 if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²");else
123 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»");else
124 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼");else
125 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ");else
126 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç");else
127 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í");else
128 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø");else
129 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù");else
130 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á");else
131 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì");else
132
133 if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤¤");else
134 if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤­");else
135 if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤®");else
136 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·");else
137 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸");else
138 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Á");else
139 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Â");else
140 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Ë");else
141 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ò");else
142 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤Ó");else
143 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ß");else
144 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤ê");else
145
146   sprintf(&out[l],"¤½¤·¤Æ");}
147
148 /* ²¥¤ë,½³¤ë> ²¥¤Ã¤Æ½³¤ë */
149 void jverb2( const char *in , char *out){
150 int l=strlen(in);
151 strcpy(out,in);
152
153 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·¤Æ");else
154 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤Æ");else
155
156 if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨¤Æ");else
157 if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±¤Æ");else
158 if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²¤Æ");else
159 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»¤Æ");else
160 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼¤Æ");else
161 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ¤Ã¤Æ");else
162 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç¤Æ");else
163 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í¤Æ");else
164 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø¤Æ");else
165 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù¤Æ");else
166 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á¤Æ");else
167 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì¤Æ");else
168
169 if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
170 if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤¤¤Æ");else
171 if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤¤¤Ç");else
172 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·¤Æ");else
173 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸¤Æ");else
174 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
175 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
176 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Í¤Æ");else
177 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ø¤Æ");else
178 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤ó¤Ç");else
179 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ó¤Ç");else
180 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
181   sprintf(&out[l],"¤³¤È¤Ë¤è¤ê");}
182
183 /* ²¥¤ë,½³¤ë > ²¥¤Ã¤¿¤ê½³¤Ã¤¿¤ê */
184 void jverb3( const char *in , char *out){
185 int l=strlen(in);
186 strcpy(out,in);
187
188 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·¤¿");else
189 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤¿");else
190
191 if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨¤¿");else
192 if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±¤¿");else
193 if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²¤¿");else
194 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»¤¿");else
195 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼¤¿");else
196 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ¤Ã¤¿");else
197 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç¤¿");else
198 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í¤¿");else
199 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø¤¿");else
200 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù¤¿");else
201 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á¤¿");else
202 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì¤¿");else
203
204 if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤Ã¤¿");else
205 if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤¤¤¿");else
206 if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤¤¤À");else
207 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·¤¿");else
208 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸¤¿");else
209 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Ã¤¿");else
210 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Ã¤¿");else
211 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Í¤¿");else
212 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ø¤¿");else
213 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤ó¤À");else
214 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ó¤À");else
215 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤Ã¤¿");else
216   sprintf(&out[l],"¤³¤È¤ä");}
217
218
219 void jverb( const char *in , char *out , int flag){
220   switch (flag){
221   case JVERB_AND:jverb1(in , out);break;
222   case JVERB_TO :jverb2(in , out);break;
223   case JVERB_OR :jverb3(in , out);break;
224   }
225 }
226
227
228 /*
229  * Convert SJIS string to EUC string
230  */
231 void sjis2euc(char *str)
232 {
233         int i;
234         unsigned char c1, c2;
235         unsigned char *tmp;
236
237         int len = strlen(str);
238
239         C_MAKE(tmp, len+1, byte);
240
241         for (i = 0; i < len; i++)
242         {
243                 c1 = str[i];
244                 if (c1 & 0x80)
245                 {
246                         i++;
247                         c2 = str[i];
248                         if (c2 >= 0x9f)
249                         {
250                                 c1 = c1 * 2 - (c1 >= 0xe0 ? 0xe0 : 0x60);
251                                 c2 += 2;
252                         }
253                         else
254                         {
255                                 c1 = c1 * 2 - (c1 >= 0xe0 ? 0xe1 : 0x61);
256                                 c2 += 0x60 + (c2 < 0x7f);
257                         }
258                         tmp[i - 1] = c1;
259                         tmp[i] = c2;
260                 }
261                 else
262                         tmp[i] = c1;
263         }
264         tmp[len] = 0;
265         strcpy(str, (char *)tmp);
266
267         C_KILL(tmp, len+1, byte);
268 }  
269
270
271 /*
272  * Convert EUC string to SJIS string
273  */
274 void euc2sjis(char *str)
275 {
276         int i;
277         unsigned char c1, c2;
278         unsigned char *tmp;
279         
280         int len = strlen(str);
281
282         C_MAKE(tmp, len+1, byte);
283
284         for (i = 0; i < len; i++)
285         {
286                 c1 = str[i];
287                 if (c1 & 0x80)
288                 {
289                         i++;
290                         c2 = str[i];
291                         if (c1 % 2)
292                         {
293                                 c1 = (c1 >> 1) + (c1 < 0xdf ? 0x31 : 0x71);
294                                 c2 -= 0x60 + (c2 < 0xe0);
295                         }
296                         else
297                         {
298                                 c1 = (c1 >> 1) + (c1 < 0xdf ? 0x30 : 0x70);
299                                 c2 -= 2;
300                         }
301
302                         tmp[i - 1] = c1;
303                         tmp[i] = c2;
304                 }
305                 else
306                         tmp[i] = c1;
307         }
308         tmp[len] = 0;
309         strcpy(str, (char *)tmp);
310
311         C_KILL(tmp, len+1, byte);
312 }  
313
314
315 /*
316  * str¤ò´Ä¶­¤Ë¹ç¤Ã¤¿Ê¸»ú¥³¡¼¥É¤ËÊÑ´¹¤·¡¢ÊÑ´¹Á°¤Îʸ»ú¥³¡¼¥É¤òÊÖ¤¹¡£
317  * str¤ÎŤµ¤ËÀ©¸Â¤Ï¤Ê¤¤¡£
318  *
319  * 0: Unknown
320  * 1: ASCII (Never known to be ASCII in this function.)
321  * 2: EUC
322  * 3: SJIS
323  */
324 byte codeconv(char *str)
325 {
326         byte code = 0;
327         int i;
328
329         for (i = 0; str[i]; i++)
330         {
331                 unsigned char c1;
332                 unsigned char c2;
333
334                 /* First byte */
335                 c1 = str[i];
336
337                 /* ASCII? */
338                 if (!(c1 & 0x80)) continue;
339
340                 /* Second byte */
341                 i++;
342                 c2 = str[i];
343
344                 if (((0xa1 <= c1 && c1 <= 0xdf) || (0xfd <= c1 && c1 <= 0xfe)) &&
345                     (0xa1 <= c2 && c2 <= 0xfe))
346                 {
347                         /* Only EUC is allowed */
348                         if (!code)
349                         {
350                                 /* EUC */
351                                 code = 2;
352                         }
353
354                         /* Broken string? */
355                         else if (code != 2)
356                         {
357                                 /* No conversion */
358                                 return 0;
359                         }
360                 }
361
362                 else if (((0x81 <= c1 && c1 <= 0x9f) &&
363                           ((0x40 <= c2 && c2 <= 0x7e) || (0x80 <= c2 && c2 <= 0xfc))) ||
364                          ((0xe0 <= c1 && c1 <= 0xfc) &&
365                           (0x40 <= c2 && c2 <= 0x7e)))
366                 {
367                         /* Only SJIS is allowed */
368                         if (!code)
369                         {
370                                 /* SJIS */
371                                 code = 3;
372                         }
373
374                         /* Broken string? */
375                         else if (code != 3)
376                         {
377                                 /* No conversion */
378                                 return 0;
379                         }
380                 }
381         }
382
383
384         switch (code)
385         {
386 #ifdef EUC
387         case 3:
388                 /* SJIS -> EUC */
389                 sjis2euc(str);
390                 break;
391 #endif
392
393 #ifdef SJIS
394         case 2:
395                 /* EUC -> SJIS */
396                 euc2sjis(str);
397
398                 break;
399 #endif
400         }
401
402         /* Return kanji code */
403         return code;
404 }
405
406 /* Ê¸»úÎós¤Îx¥Ð¥¤¥ÈÌܤ¬´Á»ú¤Î1¥Ð¥¤¥ÈÌܤ«¤É¤¦¤«È½Äꤹ¤ë */
407 bool iskanji2(cptr s, int x)
408 {
409         int i;
410
411         for (i = 0; i < x; i++)
412         {
413                 if (iskanji(s[i])) i++;
414         }
415         if ((x == i) && iskanji(s[x])) return TRUE;
416
417         return FALSE;
418 }
419
420 #endif /* JP */
421