OSDN Git Service

Updated comment for init_file_paths() to reflect PHO's patch. Most of the comment...
[hengbandforosx/hengbandosx.git] / src / japanese.c
1 /* File: japanese.c */
2
3
4 #include "angband.h"
5
6 #ifdef JP
7
8 /*ÆüËܸìÆ°»ì³èÍÑ (ÂǤġäÂǤäÆ,ÂǤÁ etc) */
9
10 #define CMPTAIL(y) strncmp(&in[l-strlen(y)],y,strlen(y))
11
12 /* ²¥¤ë,½³¤ë¡ä²¥¤ê,½³¤ë */
13 void jverb1( const char *in , char *out){
14 int l=strlen(in);
15 strcpy(out,in);
16
17 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·");else
18 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤Æ");else
19
20 if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨");else
21 if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±");else
22 if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²");else
23 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»");else
24 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼");else
25 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ");else
26 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç");else
27 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í");else
28 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø");else
29 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù");else
30 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á");else
31 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì");else
32
33 if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤¤");else
34 if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤­");else
35 if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤®");else
36 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·");else
37 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸");else
38 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Á");else
39 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Â");else
40 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Ë");else
41 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ò");else
42 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤Ó");else
43 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ß");else
44 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤ê");else
45
46   sprintf(&out[l],"¤½¤·¤Æ");}
47
48 /* ²¥¤ë,½³¤ë> ²¥¤Ã¤Æ½³¤ë */
49 void jverb2( const char *in , char *out){
50 int l=strlen(in);
51 strcpy(out,in);
52
53 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·¤Æ");else
54 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤Æ");else
55
56 if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨¤Æ");else
57 if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±¤Æ");else
58 if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²¤Æ");else
59 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»¤Æ");else
60 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼¤Æ");else
61 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ¤Ã¤Æ");else
62 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç¤Æ");else
63 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í¤Æ");else
64 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø¤Æ");else
65 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù¤Æ");else
66 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á¤Æ");else
67 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì¤Æ");else
68
69 if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
70 if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤¤¤Æ");else
71 if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤¤¤Ç");else
72 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·¤Æ");else
73 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸¤Æ");else
74 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
75 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
76 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Í¤Æ");else
77 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ø¤Æ");else
78 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤ó¤Ç");else
79 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ó¤Ç");else
80 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
81   sprintf(&out[l],"¤³¤È¤Ë¤è¤ê");}
82
83 /* ²¥¤ë,½³¤ë > ²¥¤Ã¤¿¤ê½³¤Ã¤¿¤ê */
84 void jverb3( const char *in , char *out){
85 int l=strlen(in);
86 strcpy(out,in);
87
88 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·¤¿");else
89 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤¿");else
90
91 if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨¤¿");else
92 if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±¤¿");else
93 if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²¤¿");else
94 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»¤¿");else
95 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼¤¿");else
96 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ¤Ã¤¿");else
97 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç¤¿");else
98 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í¤¿");else
99 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø¤¿");else
100 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù¤¿");else
101 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á¤¿");else
102 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì¤¿");else
103
104 if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤Ã¤¿");else
105 if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤¤¤¿");else
106 if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤¤¤À");else
107 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·¤¿");else
108 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸¤¿");else
109 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Ã¤¿");else
110 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Ã¤¿");else
111 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Í¤¿");else
112 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ø¤¿");else
113 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤ó¤À");else
114 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ó¤À");else
115 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤Ã¤¿");else
116   sprintf(&out[l],"¤³¤È¤ä");}
117
118
119 void jverb( const char *in , char *out , int flag){
120   switch (flag){
121   case JVERB_AND:jverb1(in , out);break;
122   case JVERB_TO :jverb2(in , out);break;
123   case JVERB_OR :jverb3(in , out);break;
124   }
125 }
126
127 char* strstr_j(const char* s, const char* t)
128 {
129         int i, l1, l2;
130
131         l1 = strlen(s);
132         l2 = strlen(t);
133         if (l1 >= l2) {
134                 for(i = 0; i <= l1 - l2; i++) {
135                         if(!strncmp(s + i, t, l2))
136                                 return (char *)s + i;
137                         if (iskanji(*(s + i)))
138                                 i++;
139                 }
140         }
141         return NULL;
142 }
143
144
145 char *strchr_j(const char *ptr, char ch)
146 {
147         for ( ; *ptr != '\0'; ++ptr)
148         {
149                 if (*ptr == ch) return (char *)ptr;
150                 if (iskanji(*ptr)) ++ptr;
151         }
152
153         return NULL;
154 }
155
156
157 /*
158  * Convert SJIS string to EUC string
159  */
160 void sjis2euc(char *str)
161 {
162         int i;
163         unsigned char c1, c2;
164         unsigned char *tmp;
165
166         int len = strlen(str);
167
168         C_MAKE(tmp, len+1, byte);
169
170         for (i = 0; i < len; i++)
171         {
172                 c1 = str[i];
173                 if (c1 & 0x80)
174                 {
175                         i++;
176                         c2 = str[i];
177                         if (c2 >= 0x9f)
178                         {
179                                 c1 = c1 * 2 - (c1 >= 0xe0 ? 0xe0 : 0x60);
180                                 c2 += 2;
181                         }
182                         else
183                         {
184                                 c1 = c1 * 2 - (c1 >= 0xe0 ? 0xe1 : 0x61);
185                                 c2 += 0x60 + (c2 < 0x7f);
186                         }
187                         tmp[i - 1] = c1;
188                         tmp[i] = c2;
189                 }
190                 else
191                         tmp[i] = c1;
192         }
193         tmp[len] = 0;
194         strcpy(str, (char *)tmp);
195
196         C_KILL(tmp, len+1, byte);
197 }  
198
199
200 /*
201  * Convert EUC string to SJIS string
202  */
203 void euc2sjis(char *str)
204 {
205         int i;
206         unsigned char c1, c2;
207         unsigned char *tmp;
208         
209         int len = strlen(str);
210
211         C_MAKE(tmp, len+1, byte);
212
213         for (i = 0; i < len; i++)
214         {
215                 c1 = str[i];
216                 if (c1 & 0x80)
217                 {
218                         i++;
219                         c2 = str[i];
220                         if (c1 % 2)
221                         {
222                                 c1 = (c1 >> 1) + (c1 < 0xdf ? 0x31 : 0x71);
223                                 c2 -= 0x60 + (c2 < 0xe0);
224                         }
225                         else
226                         {
227                                 c1 = (c1 >> 1) + (c1 < 0xdf ? 0x30 : 0x70);
228                                 c2 -= 2;
229                         }
230
231                         tmp[i - 1] = c1;
232                         tmp[i] = c2;
233                 }
234                 else
235                         tmp[i] = c1;
236         }
237         tmp[len] = 0;
238         strcpy(str, (char *)tmp);
239
240         C_KILL(tmp, len+1, byte);
241 }  
242
243
244 /*
245  * str¤ò´Ä¶­¤Ë¹ç¤Ã¤¿Ê¸»ú¥³¡¼¥É¤ËÊÑ´¹¤·¡¢ÊÑ´¹Á°¤Îʸ»ú¥³¡¼¥É¤òÊÖ¤¹¡£
246  * str¤ÎŤµ¤ËÀ©¸Â¤Ï¤Ê¤¤¡£
247  *
248  * 0: Unknown
249  * 1: ASCII (Never known to be ASCII in this function.)
250  * 2: EUC
251  * 3: SJIS
252  */
253 byte codeconv(char *str)
254 {
255         byte code = 0;
256         int i;
257
258         for (i = 0; str[i]; i++)
259         {
260                 unsigned char c1;
261                 unsigned char c2;
262
263                 /* First byte */
264                 c1 = str[i];
265
266                 /* ASCII? */
267                 if (!(c1 & 0x80)) continue;
268
269                 /* Second byte */
270                 i++;
271                 c2 = str[i];
272
273                 if (((0xa1 <= c1 && c1 <= 0xdf) || (0xfd <= c1 && c1 <= 0xfe)) &&
274                     (0xa1 <= c2 && c2 <= 0xfe))
275                 {
276                         /* Only EUC is allowed */
277                         if (!code)
278                         {
279                                 /* EUC */
280                                 code = 2;
281                         }
282
283                         /* Broken string? */
284                         else if (code != 2)
285                         {
286                                 /* No conversion */
287                                 return 0;
288                         }
289                 }
290
291                 else if (((0x81 <= c1 && c1 <= 0x9f) &&
292                           ((0x40 <= c2 && c2 <= 0x7e) || (0x80 <= c2 && c2 <= 0xfc))) ||
293                          ((0xe0 <= c1 && c1 <= 0xfc) &&
294                           (0x40 <= c2 && c2 <= 0x7e)))
295                 {
296                         /* Only SJIS is allowed */
297                         if (!code)
298                         {
299                                 /* SJIS */
300                                 code = 3;
301                         }
302
303                         /* Broken string? */
304                         else if (code != 3)
305                         {
306                                 /* No conversion */
307                                 return 0;
308                         }
309                 }
310         }
311
312
313         switch (code)
314         {
315 #ifdef EUC
316         case 3:
317                 /* SJIS -> EUC */
318                 sjis2euc(str);
319                 break;
320 #endif
321
322 #ifdef SJIS
323         case 2:
324                 /* EUC -> SJIS */
325                 euc2sjis(str);
326
327                 break;
328 #endif
329         }
330
331         /* Return kanji code */
332         return code;
333 }
334
335 /* Ê¸»úÎós¤Îx¥Ð¥¤¥ÈÌܤ¬´Á»ú¤Î1¥Ð¥¤¥ÈÌܤ«¤É¤¦¤«È½Äꤹ¤ë */
336 bool iskanji2(cptr s, int x)
337 {
338         int i;
339
340         for (i = 0; i < x; i++)
341         {
342                 if (iskanji(s[i])) i++;
343         }
344         if ((x == i) && iskanji(s[x])) return TRUE;
345
346         return FALSE;
347 }
348
349 #endif /* JP */
350