OSDN Git Service

Refactor: change jverb() from stupid 'if-else' enumeration to reference table
authorHabu <habu@users.sourceforge.jp>
Wed, 19 Feb 2014 11:47:37 +0000 (20:47 +0900)
committerHabu <habu@users.sourceforge.jp>
Wed, 19 Feb 2014 11:47:37 +0000 (20:47 +0900)
src/cmd5.c
src/externs.h
src/japanese.c

index 193fd6f..38b5682 100644 (file)
@@ -146,7 +146,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
 
        /* Build a prompt (accept all spells) */
 #ifdef JP
-       jverb1( prompt, jverb_buf );
+       jverb( prompt, jverb_buf, JVERB_AND );
        (void) strnfmt(out_val, 78, "(%^s:%c-%c, '*'¤Ç°ìÍ÷, ESC¤ÇÃæÃÇ) ¤É¤Î%s¤ò%^s¤Þ¤¹¤«? ",
                p, I2A(0), I2A(num - 1), p, jverb_buf );
 #else
@@ -298,7 +298,7 @@ static int get_spell(int *sn, cptr prompt, int sval, bool learned, int use_realm
 
                        /* Prompt */
 #ifdef JP
-                       jverb1( prompt, jverb_buf );
+                       jverb( prompt, jverb_buf, JVERB_AND );
                        /* ±ÑÆüÀÚ¤êÂؤ¨µ¡Ç½¤ËÂбþ */
                        (void) strnfmt(tmp_val, 78, "%s(MP%d, ¼ºÇÔΨ%d%%)¤ò%s¤Þ¤¹¤«? ",
                                do_spell(use_realm, spell, SPELL_NAME), need_mana,
index 80e9141..5b9c2b3 100644 (file)
@@ -1821,9 +1821,6 @@ extern void dump_virtues(FILE * OutFile);
 #ifdef JP
 /* japanese.c */
 extern void sindarin_to_kana(char *kana, const char *sindarin);
-extern void jverb1( const char *in , char *out);
-extern void jverb2( const char *in , char *out);
-extern void jverb3( const char *in , char *out);
 extern void jverb( const char *in , char *out , int flag);
 extern void sjis2euc(char *str);
 extern void euc2sjis(char *str);
index b746e11..49d0a37 100644 (file)
@@ -106,122 +106,62 @@ void sindarin_to_kana(char *kana, const char *sindarin)
 
 
 /*ÆüËܸìÆ°»ì³èÍÑ (ÂǤġäÂǤäÆ,ÂǤÁ etc) */
+/* JVERB_AND: ²¥¤ë,½³¤ë > ²¥¤ê,½³¤ë */
+/* JVERB_TO:  ²¥¤ë,½³¤ë > ²¥¤Ã¤Æ½³¤ë */
+/* JVERB_OR:  ²¥¤ë,½³¤ë > ²¥¤Ã¤¿¤ê½³¤Ã¤¿¤ê */
+
+static const struct jverb_table_t {
+       const char* from;
+       const char* to[3];
+} jverb_table[] = {
+       { "¤¹¤ë", {"¤·", "¤·¤Æ", "¤·¤¿"}},
+       { "¤¤¤ë", {"¤¤¤Æ", "¤¤¤Æ", "¤¤¤¿"}},
+
+       { "¤¨¤ë", {"¤¨", "¤¨¤Æ", "¤¨¤¿"}},
+       { "¤±¤ë", {"¤±", "¤±¤Æ", "¤±¤¿"}},
+       { "¤²¤ë", {"¤²", "¤¨¤Æ", "¤²¤¿"}},
+       { "¤»¤ë", {"¤»", "¤»¤Æ", "¤»¤¿"}},
+       { "¤¼¤ë", {"¤¼", "¤¼¤Æ", "¤¼¤¿"}},
+       { "¤Æ¤ë", {"¤Æ", "¤Æ¤Ã¤Æ", "¤Æ¤Ã¤¿"}},
+       { "¤Ç¤ë", {"¤Ç", "¤Ç¤Æ", "¤Ç¤¿"}},
+       { "¤Í¤ë", {"¤Í", "¤Í¤Æ", "¤Í¤¿"}},
+       { "¤Ø¤ë", {"¤Ø", "¤Ø¤Æ", "¤Ø¤¿"}},
+       { "¤Ù¤ë", {"¤Ù", "¤Ù¤Æ", "¤Ù¤¿"}},
+       { "¤á¤ë", {"¤á", "¤á¤Æ", "¤á¤¿"}},
+       { "¤ì¤ë", {"¤ì", "¤ì¤Æ", "¤ì¤¿"}},
+
+       { "¤¦", {"¤¤", "¤Ã¤Æ", "¤Ã¤¿"}},
+       { "¤¯", {"¤­", "¤¤¤Æ", "¤¤¤¿"}},
+       { "¤°", {"¤®", "¤¤¤Ç", "¤¤¤À"}},
+       { "¤¹", {"¤·", "¤·¤Æ", "¤·¤¿"}},
+       { "¤º", {"¤¸", "¤¸¤Æ", "¤¸¤¿"}},
+       { "¤Ä", {"¤Á", "¤Ã¤Æ", "¤Ã¤¿"}},
+       { "¤Å", {"¤Â", "¤Ã¤Æ", "¤Ã¤¿"}},
+       { "¤Ì", {"¤Ë", "¤Í¤Æ", "¤Í¤¿"}},
+       { "¤Õ", {"¤Ò", "¤Ø¤Æ", "¤Ø¤¿"}},
+       { "¤Ö", {"¤Ó", "¤ó¤Ç", "¤ó¤À"}},
+       { "¤à", {"¤ß", "¤ó¤Ç", "¤ó¤À"}},
+       { "¤ë", {"¤ê", "¤Ã¤Æ", "¤Ã¤¿"}},
+       { NULL, {"¤½¤·¤Æ", "¤³¤È¤Ë¤è¤ê", "¤³¤È¤ä"}},
+};
+
+void jverb(const char *in , char *out , int flag)
+{
+       const struct jverb_table_t * p;
+       int in_len = strlen(in);
+
+       strcpy(out, in);
+
+       for (p = jverb_table; p->from; p++) {
+               int from_len = strlen(p->from);
+               if (strncmp(&in[in_len-from_len], p->from, from_len) == 0) {
+                       strcpy(&out[in_len - from_len], p->to[flag - 1]);
+                       break;
+               }
+       }
 
-#define CMPTAIL(y) strncmp(&in[l-(int)strlen(y)],y,strlen(y))
-
-/* ²¥¤ë,½³¤ë¡ä²¥¤ê,½³¤ë */
-void jverb1( const char *in , char *out){
-int l=strlen(in);
-strcpy(out,in);
-
-if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·");else
-if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤Æ");else
-
-if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨");else
-if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±");else
-if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²");else
-if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»");else
-if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼");else
-if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ");else
-if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç");else
-if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í");else
-if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø");else
-if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù");else
-if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á");else
-if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì");else
-
-if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤¤");else
-if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤­");else
-if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤®");else
-if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·");else
-if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸");else
-if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Á");else
-if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Â");else
-if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Ë");else
-if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ò");else
-if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤Ó");else
-if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ß");else
-if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤ê");else
-
-  sprintf(&out[l],"¤½¤·¤Æ");}
-
-/* ²¥¤ë,½³¤ë> ²¥¤Ã¤Æ½³¤ë */
-void jverb2( const char *in , char *out){
-int l=strlen(in);
-strcpy(out,in);
-
-if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·¤Æ");else
-if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤Æ");else
-
-if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨¤Æ");else
-if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±¤Æ");else
-if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²¤Æ");else
-if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»¤Æ");else
-if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼¤Æ");else
-if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ¤Ã¤Æ");else
-if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç¤Æ");else
-if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í¤Æ");else
-if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø¤Æ");else
-if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù¤Æ");else
-if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á¤Æ");else
-if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì¤Æ");else
-
-if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
-if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤¤¤Æ");else
-if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤¤¤Ç");else
-if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·¤Æ");else
-if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸¤Æ");else
-if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
-if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
-if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Í¤Æ");else
-if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ø¤Æ");else
-if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤ó¤Ç");else
-if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ó¤Ç");else
-if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤Ã¤Æ");else
-  sprintf(&out[l],"¤³¤È¤Ë¤è¤ê");}
-
-/* ²¥¤ë,½³¤ë > ²¥¤Ã¤¿¤ê½³¤Ã¤¿¤ê */
-void jverb3( const char *in , char *out){
-int l=strlen(in);
-strcpy(out,in);
-
-if( CMPTAIL("¤¹¤ë")==0) sprintf(&out[l-4],"¤·¤¿");else
-if( CMPTAIL("¤¤¤ë")==0) sprintf(&out[l-4],"¤¤¤¿");else
-
-if( CMPTAIL("¤¨¤ë")==0) sprintf(&out[l-4],"¤¨¤¿");else
-if( CMPTAIL("¤±¤ë")==0) sprintf(&out[l-4],"¤±¤¿");else
-if( CMPTAIL("¤²¤ë")==0) sprintf(&out[l-4],"¤²¤¿");else
-if( CMPTAIL("¤»¤ë")==0) sprintf(&out[l-4],"¤»¤¿");else
-if( CMPTAIL("¤¼¤ë")==0) sprintf(&out[l-4],"¤¼¤¿");else
-if( CMPTAIL("¤Æ¤ë")==0) sprintf(&out[l-4],"¤Æ¤Ã¤¿");else
-if( CMPTAIL("¤Ç¤ë")==0) sprintf(&out[l-4],"¤Ç¤¿");else
-if( CMPTAIL("¤Í¤ë")==0) sprintf(&out[l-4],"¤Í¤¿");else
-if( CMPTAIL("¤Ø¤ë")==0) sprintf(&out[l-4],"¤Ø¤¿");else
-if( CMPTAIL("¤Ù¤ë")==0) sprintf(&out[l-4],"¤Ù¤¿");else
-if( CMPTAIL("¤á¤ë")==0) sprintf(&out[l-4],"¤á¤¿");else
-if( CMPTAIL("¤ì¤ë")==0) sprintf(&out[l-4],"¤ì¤¿");else
-
-if( CMPTAIL("¤¦")==0) sprintf(&out[l-2],"¤Ã¤¿");else
-if( CMPTAIL("¤¯")==0) sprintf(&out[l-2],"¤¤¤¿");else
-if( CMPTAIL("¤°")==0) sprintf(&out[l-2],"¤¤¤À");else
-if( CMPTAIL("¤¹")==0) sprintf(&out[l-2],"¤·¤¿");else
-if( CMPTAIL("¤º")==0) sprintf(&out[l-2],"¤¸¤¿");else
-if( CMPTAIL("¤Ä")==0) sprintf(&out[l-2],"¤Ã¤¿");else
-if( CMPTAIL("¤Å")==0) sprintf(&out[l-2],"¤Ã¤¿");else
-if( CMPTAIL("¤Ì")==0) sprintf(&out[l-2],"¤Í¤¿");else
-if( CMPTAIL("¤Õ")==0) sprintf(&out[l-2],"¤Ø¤¿");else
-if( CMPTAIL("¤Ö")==0) sprintf(&out[l-2],"¤ó¤À");else
-if( CMPTAIL("¤à")==0) sprintf(&out[l-2],"¤ó¤À");else
-if( CMPTAIL("¤ë")==0) sprintf(&out[l-2],"¤Ã¤¿");else
-  sprintf(&out[l],"¤³¤È¤ä");}
-
-
-void jverb( const char *in , char *out , int flag){
-  switch (flag){
-  case JVERB_AND:jverb1(in , out);break;
-  case JVERB_TO :jverb2(in , out);break;
-  case JVERB_OR :jverb3(in , out);break;
-  }
+       if (p->from == NULL)
+               strcpy(&out[in_len], p->to[flag - 1]);
 }