OSDN Git Service

a352a92bf570659af4d898fead28eaddb0e6e580
[hengband/hengband.git] / src / japanese.c
1 /* File: japanese.c */
2
3
4 #include "angband.h"
5
6 #ifdef JP
7
8 typedef struct sindarin2j sindarin2j;
9
10 struct sindarin2j {
11   char *sindarin;
12   char *kana;
13 };
14
15 static const sindarin2j s2j_table[]= {
16 {"mb","nb"},{"mp","np"},{"mv","nv"},{"mm","nm"},
17 {"x","ks"},
18 {"ar$","a-ru$"},{"ir$","ia$"},{"or$","o-ru$"},
19 {"ra","¥é"},{"ri","¥ê"},{"ru","¥ë"},{"re","¥ì"},{"ro","¥í"},
20 {"ir","ia"},{"ur","ua"},{"er","ea"},
21 {"ar","a¥ë"},
22 {"sha","¥·¥ã"},{"shi","¥·"},{"shu","¥·¥å"},{"she","¥·¥§"},{"sho","¥·¥ç"},
23 {"tha","¥µ"},{"thi","¥·"},{"thu","¥¹"},{"the","¥»"},{"tho","¥½"},
24 {"cha","¥Ï"},{"chi","¥Ò"},{"chu","¥Õ"},{"che","¥Ø"},{"cho","¥Û"},
25 {"dha","¥¶"},{"dhi","¥¸"},{"dhu","¥º"},{"dhe","¥¼"},{"dho","¥¾"},
26 {"ba","¥Ð"},{"bi","¥Ó"},{"bu","¥Ö"},{"be","¥Ù"},{"bo","¥Ü"},
27 {"ca","¥«"},{"ci","¥­"},{"cu","¥¯"},{"ce","¥±"},{"co","¥³"},
28 {"da","¥À"},{"di","¥Ç¥£"},{"du","¥É¥¥"},{"de","¥Ç"},{"do","¥É"},
29 {"fa","¥Õ¥¡"},{"fi","¥Õ¥£"},{"fu","¥Õ"},{"fe","¥Õ¥§"},{"fo","¥Õ¥©"},
30 {"ga","¥¬"},{"gi","¥®"},{"gu","¥°"},{"ge","¥²"},{"go","¥´"},
31 {"ha","¥Ï"},{"hi","¥Ò"},{"hu","¥Õ"},{"he","¥Ø"},{"ho","¥Û"},
32 {"ja","¥¸¥ã"},{"ji","¥¸"},{"ju","¥¸¥å"},{"je","¥¸¥§"},{"jo","¥¸¥ç"},
33 {"ka","¥«"},{"ki","¥­"},{"ku","¥¯"},{"ke","¥±"},{"ko","¥³"},
34 {"la","¥é"},{"li","¥ê"},{"lu","¥ë"},{"le","¥ì"},{"lo","¥í"},
35 {"ma","¥Þ"},{"mi","¥ß"},{"mu","¥à"},{"me","¥á"},{"mo","¥â"},
36 {"na","¥Ê"},{"ni","¥Ë"},{"nu","¥Ì"},{"ne","¥Í"},{"no","¥Î"},
37 {"pa","¥Ñ"},{"pi","¥Ô"},{"pu","¥×"},{"pe","¥Ú"},{"po","¥Ý"},
38 {"qu","¥¯"},
39 {"sa","¥µ"},{"si","¥·"},{"su","¥¹"},{"se","¥»"},{"so","¥½"},
40 {"ta","¥¿"},{"ti","¥Æ¥£"},{"tu","¥È¥¥"},{"te","¥Æ"},{"to","¥È"},
41 {"va","¥ô¥¡"},{"vi","¥ô¥£"},{"vu","¥ô"},{"ve","¥ô¥§"},{"vo","¥ô¥©"},
42 {"wa","¥ï"},{"wi","¥¦¥£"},{"wu","¥¦"},{"we","¥¦¥§"},{"wo","¥¦¥©"},
43 {"ya","¥ä"},{"yu","¥æ"},{"yo","¥è"},
44 {"za","¥¶"},{"zi","¥¸"},{"zu","¥º"},{"ze","¥¼"},{"zo","¥¾"},
45 {"dh","¥º"},
46 {"ch","¥Õ"},
47 {"th","¥¹"},
48 {"b","¥Ö"},
49 {"c","¥¯"},
50 {"d","¥É"},
51 {"f","¥Õ"},
52 {"g","¥°"},
53 {"h","¥Õ"},
54 {"j","¥¸¥å"},
55 {"k","¥¯"},
56 {"l","¥ë"},
57 {"m","¥à"},
58 {"n","¥ó"},
59 {"p","¥×"},
60 {"q","¥¯"},
61 {"r","¥ë"},
62 {"s","¥¹"},
63 {"t","¥È"},
64 {"v","¥ô"},
65 {"w","¥¦"},
66 {"y","¥¤"},
67 {"a","¥¢"},
68 {"i","¥¤"},
69 {"u","¥¦"},
70 {"e","¥¨"},
71 {"o","¥ª"},
72 {"-","¡¼"},
73 {NULL,NULL}
74 };
75
76 unsigned char *sindarin_to_kana( unsigned char *sindarin ){
77 static unsigned char buf1[256], buf2[256];
78 int idx;
79
80 sprintf(buf1,"%s$",sindarin);
81 for(idx=0;buf1[idx];idx++) if( isupper(buf1[idx]))buf1[idx]=tolower(buf1[idx]);
82
83 for(idx=0; s2j_table[idx].sindarin != NULL;idx++){
84   unsigned char *pat1 = s2j_table[idx].sindarin;
85   unsigned char *pat2 = s2j_table[idx].kana;
86   int len=strlen(pat1);
87   unsigned char *dest = buf2;
88   unsigned char *src = buf1;
89  
90   for( ; *src ; ){
91     if( strncmp( src, pat1, len)==0 ){
92      strcpy( dest, pat2 );
93      src+=len;
94      dest+= strlen(pat2);
95     }
96     else
97       if( iskanji(*src) ){
98         *dest = *src;
99         dest++; src++;
100         *dest=*src;
101         dest++; src++;
102       } 
103       else{
104         *dest=*src;
105         dest++; src++;
106       }    
107   }  
108   *dest=0;
109   strcpy(buf1,buf2);
110 }
111 idx=0;
112 while( buf1[idx] != '$' ) idx++;
113 buf1[idx]=0;
114 return(buf1);
115 }
116
117 /*ÆüËܸìÆ°»ì³èÍÑ (ÂǤġäÂǤäÆ,ÂǤÁ etc) */
118
119 #define CMPTAIL(y) strncmp(&in[l-strlen(y)],y,strlen(y))
120
121 /* ²¥¤ë,½³¤ë¡ä²¥¤ê,½³¤ë */
122 void jverb1( const char *in , char *out){
123 int l=strlen(in);
124 strcpy(out,in);
125
126 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·");else
127 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤Æ");else
128
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 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»");else
133 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼");else
134 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ");else
135 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç");else
136 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í");else
137 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø");else
138 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù");else
139 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á");else
140 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì");else
141
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 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·");else
146 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸");else
147 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Á");else
148 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Â");else
149 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Ë");else
150 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ò");else
151 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤Ó");else
152 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ß");else
153 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤ê");else
154
155   sprintf(&out[l],"¤½¤·¤Æ");}
156
157 /* ²¥¤ë,½³¤ë> ²¥¤Ã¤Æ½³¤ë */
158 void jverb2( const char *in , char *out){
159 int l=strlen(in);
160 strcpy(out,in);
161
162 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·¤Æ");else
163 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤Æ");else
164
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 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»¤Æ");else
169 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼¤Æ");else
170 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ¤Ã¤Æ");else
171 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç¤Æ");else
172 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í¤Æ");else
173 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø¤Æ");else
174 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù¤Æ");else
175 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á¤Æ");else
176 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì¤Æ");else
177
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 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·¤Æ");else
182 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸¤Æ");else
183 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
184 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
185 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Í¤Æ");else
186 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ø¤Æ");else
187 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤ó¤Ç");else
188 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ó¤Ç");else
189 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
190   sprintf(&out[l],"¤³¤È¤Ë¤è¤ê");}
191
192 /* ²¥¤ë,½³¤ë > ²¥¤Ã¤¿¤ê½³¤Ã¤¿¤ê */
193 void jverb3( const char *in , char *out){
194 int l=strlen(in);
195 strcpy(out,in);
196
197 if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·¤¿");else
198 if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤¿");else
199
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 if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»¤¿");else
204 if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼¤¿");else
205 if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ¤Ã¤¿");else
206 if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç¤¿");else
207 if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í¤¿");else
208 if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø¤¿");else
209 if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù¤¿");else
210 if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á¤¿");else
211 if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì¤¿");else
212
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 if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·¤¿");else
217 if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸¤¿");else
218 if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Ã¤¿");else
219 if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Ã¤¿");else
220 if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Í¤¿");else
221 if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ø¤¿");else
222 if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤ó¤À");else
223 if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ó¤À");else
224 if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤Ã¤¿");else
225   sprintf(&out[l],"¤³¤È¤ä");}
226
227
228 void jverb( const char *in , char *out , int flag){
229   switch (flag){
230   case JVERB_AND:jverb1(in , out);break;
231   case JVERB_TO :jverb2(in , out);break;
232   case JVERB_OR :jverb3(in , out);break;
233   }
234 }
235
236 char* strstr_j(const char* s, const char* t)
237 {
238         int i, l1, l2;
239
240         l1 = strlen(s);
241         l2 = strlen(t);
242         if (l1 >= l2) {
243                 for(i = 0; i <= l1 - l2; i++) {
244                         if(!strncmp(s + i, t, l2))
245                                 return (char *)s + i;
246                         if (iskanji(*(s + i)))
247                                 i++;
248                 }
249         }
250         return NULL;
251 }
252
253 /* 2¥Ð¥¤¥Èʸ»ú¤ò¹Íθ¤·¤Ê¤¬¤éºÇÂç n ¥Ð¥¤¥Èʸ»úÎó¤ò¥³¥Ô¡¼¤¹¤ë */
254 size_t mb_strlcpy(char *dst, const char *src, size_t size)
255 {
256         unsigned char *d = (unsigned char*)dst;
257         const unsigned char *s = (unsigned char*)src;
258         size_t n = 0;
259
260         /* reserve for NUL termination */
261         size--;
262
263         /* Copy as many bytes as will fit */
264         while(n < size) {
265                 if (iskanji(*d)) {
266                         if(n + 2 >= size || !*(d+1)) break;
267                         *d++ = *s++;
268                         *d++ = *s++;
269                         n += 2;
270                 } else {
271                         *d++ = *s++;
272                         n++;
273                 }
274         }
275         *d = '\0';
276         while(*s++) n++;
277         return n;
278 }
279
280 #endif /* JP */
281