• R/O
  • HTTP
  • SSH
  • HTTPS

hengband: コミット

変愚蛮怒のメインリポジトリです


コミットメタ情報

リビジョンb41d80058d66e301e08ba28c3bd52cb67c380172 (tree)
日時2014-02-19 20:47:37
作者Habu <habu@user...>
コミッターHabu

ログメッセージ

Refactor: change jverb() from stupid 'if-else' enumeration to reference table

変更サマリ

差分

--- a/src/cmd5.c
+++ b/src/cmd5.c
@@ -146,7 +146,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
146146
147147 /* Build a prompt (accept all spells) */
148148 #ifdef JP
149- jverb1( prompt, jverb_buf );
149+ jverb( prompt, jverb_buf, JVERB_AND );
150150 (void) strnfmt(out_val, 78, "(%^s:%c-%c, '*'で一覧, ESCで中断) どの%sを%^sますか? ",
151151 p, I2A(0), I2A(num - 1), p, jverb_buf );
152152 #else
@@ -298,7 +298,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
298298
299299 /* Prompt */
300300 #ifdef JP
301- jverb1( prompt, jverb_buf );
301+ jverb( prompt, jverb_buf, JVERB_AND );
302302 /* 英日切り替え機能に対応 */
303303 (void) strnfmt(tmp_val, 78, "%s(MP%d, 失敗率%d%%)を%sますか? ",
304304 do_spell(use_realm, spell, SPELL_NAME), need_mana,
--- a/src/externs.h
+++ b/src/externs.h
@@ -1821,9 +1821,6 @@ extern void dump_virtues(FILE * OutFile);
18211821 #ifdef JP
18221822 /* japanese.c */
18231823 extern void sindarin_to_kana(char *kana, const char *sindarin);
1824-extern void jverb1( const char *in , char *out);
1825-extern void jverb2( const char *in , char *out);
1826-extern void jverb3( const char *in , char *out);
18271824 extern void jverb( const char *in , char *out , int flag);
18281825 extern void sjis2euc(char *str);
18291826 extern void euc2sjis(char *str);
--- a/src/japanese.c
+++ b/src/japanese.c
@@ -106,122 +106,62 @@ void sindarin_to_kana(char *kana, const char *sindarin)
106106
107107
108108 /*日本語動詞活用 (打つ>打って,打ち etc) */
109+/* JVERB_AND: 殴る,蹴る > 殴り,蹴る */
110+/* JVERB_TO: 殴る,蹴る > 殴って蹴る */
111+/* JVERB_OR: 殴る,蹴る > 殴ったり蹴ったり */
112+
113+static const struct jverb_table_t {
114+ const char* from;
115+ const char* to[3];
116+} jverb_table[] = {
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+ { NULL, {"そして", "ことにより", "ことや"}},
146+};
147+
148+void jverb(const char *in , char *out , int flag)
149+{
150+ const struct jverb_table_t * p;
151+ int in_len = strlen(in);
152+
153+ strcpy(out, in);
154+
155+ for (p = jverb_table; p->from; p++) {
156+ int from_len = strlen(p->from);
157+ if (strncmp(&in[in_len-from_len], p->from, from_len) == 0) {
158+ strcpy(&out[in_len - from_len], p->to[flag - 1]);
159+ break;
160+ }
161+ }
109162
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- }
163+ if (p->from == NULL)
164+ strcpy(&out[in_len], p->to[flag - 1]);
225165 }
226166
227167
旧リポジトリブラウザで表示