OSDN Git Service

Replace sprintf() simply. Does part of the work to resolve https://github.com/hengba...
[hengbandforosx/hengbandosx.git] / src / io / pref-file-expressor.cpp
index 5d01586..2d4348b 100644 (file)
@@ -1,16 +1,17 @@
 #include "io/pref-file-expressor.h"
 #include "game-option/runtime-arguments.h"
-#include "player/player-class.h"
-#include "player/player-race.h"
+#include "player-info/class-info.h"
+#include "player-info/race-info.h"
 #include "realm/realm-names-table.h"
-#include "system/system-variables.h"
 #include "system/player-type-definition.h"
+#include "system/system-variables.h"
+#include "term/z-form.h"
 #include "util/string-processor.h"
 
 /*!
  * @brief process_pref_fileのサブルーチンとして条件分岐処理の解釈と結果を返す
  * Helper function for "process_pref_file()"
- * @param creature_ptr プレーヤーへの参照ポインタ
+ * @param player_ptr プレイヤーへの参照ポインタ
  * @param sp テキスト文字列の参照ポインタ
  * @param fp 再帰中のポインタ参照
  * @return
  *   result
  * </pre>
  */
-concptr process_pref_file_expr(player_type *creature_ptr, char **sp, char *fp)
+concptr process_pref_file_expr(PlayerType *player_ptr, char **sp, char *fp)
 {
     char *s;
     s = (*sp);
-    while (iswspace(*s))
+    while (iswspace(*s)) {
         s++;
+    }
 
     char *b;
     b = s;
@@ -48,73 +50,81 @@ concptr process_pref_file_expr(player_type *creature_ptr, char **sp, char *fp)
         s++;
 
         /* First */
-        t = process_pref_file_expr(creature_ptr, &s, &f);
+        t = process_pref_file_expr(player_ptr, &s, &f);
 
         if (!*t) {
         } else if (streq(t, "IOR")) {
             v = "0";
             while (*s && (f != b2)) {
-                t = process_pref_file_expr(creature_ptr, &s, &f);
-                if (*t && !streq(t, "0"))
+                t = process_pref_file_expr(player_ptr, &s, &f);
+                if (*t && !streq(t, "0")) {
                     v = "1";
+                }
             }
         } else if (streq(t, "AND")) {
             v = "1";
             while (*s && (f != b2)) {
-                t = process_pref_file_expr(creature_ptr, &s, &f);
-                if (*t && streq(t, "0"))
+                t = process_pref_file_expr(player_ptr, &s, &f);
+                if (*t && streq(t, "0")) {
                     v = "0";
+                }
             }
         } else if (streq(t, "NOT")) {
             v = "1";
             while (*s && (f != b2)) {
-                t = process_pref_file_expr(creature_ptr, &s, &f);
-                if (*t && streq(t, "1"))
+                t = process_pref_file_expr(player_ptr, &s, &f);
+                if (*t && streq(t, "1")) {
                     v = "0";
+                }
             }
         } else if (streq(t, "EQU")) {
             v = "0";
             if (*s && (f != b2)) {
-                t = process_pref_file_expr(creature_ptr, &s, &f);
+                t = process_pref_file_expr(player_ptr, &s, &f);
             }
             while (*s && (f != b2)) {
-                p = process_pref_file_expr(creature_ptr, &s, &f);
-                if (streq(t, p))
+                p = process_pref_file_expr(player_ptr, &s, &f);
+                if (streq(t, p)) {
                     v = "1";
+                }
             }
         } else if (streq(t, "LEQ")) {
             v = "1";
             if (*s && (f != b2)) {
-                t = process_pref_file_expr(creature_ptr, &s, &f);
+                t = process_pref_file_expr(player_ptr, &s, &f);
             }
             while (*s && (f != b2)) {
                 p = t;
-                t = process_pref_file_expr(creature_ptr, &s, &f);
-                if (*t && atoi(p) > atoi(t))
+                t = process_pref_file_expr(player_ptr, &s, &f);
+                if (*t && atoi(p) > atoi(t)) {
                     v = "0";
+                }
             }
         } else if (streq(t, "GEQ")) {
             v = "1";
             if (*s && (f != b2)) {
-                t = process_pref_file_expr(creature_ptr, &s, &f);
+                t = process_pref_file_expr(player_ptr, &s, &f);
             }
             while (*s && (f != b2)) {
                 p = t;
-                t = process_pref_file_expr(creature_ptr, &s, &f);
-                if (*t && atoi(p) < atoi(t))
+                t = process_pref_file_expr(player_ptr, &s, &f);
+                if (*t && atoi(p) < atoi(t)) {
                     v = "0";
+                }
             }
         } else {
             while (*s && (f != b2)) {
-                t = process_pref_file_expr(creature_ptr, &s, &f);
+                t = process_pref_file_expr(player_ptr, &s, &f);
             }
         }
 
-        if (f != b2)
+        if (f != b2) {
             v = "?x?x?";
+        }
 
-        if ((f = *s) != '\0')
+        if ((f = *s) != '\0') {
             *s++ = '\0';
+        }
 
         *fp = f;
         *sp = s;
@@ -124,17 +134,20 @@ concptr process_pref_file_expr(player_type *creature_ptr, char **sp, char *fp)
     /* Accept all printables except spaces and brackets */
 #ifdef JP
     while (iskanji(*s) || (isprint(*s) && !angband_strchr(" []", *s))) {
-        if (iskanji(*s))
+        if (iskanji(*s)) {
             s++;
+        }
         s++;
     }
 #else
-    while (isprint(*s) && !angband_strchr(" []", *s))
+    while (isprint(*s) && !angband_strchr(" []", *s)) {
         ++s;
+    }
 #endif
 
-    if ((f = *s) != '\0')
+    if ((f = *s) != '\0') {
         *s++ = '\0';
+    }
 
     if (*b != '$') {
         v = b;
@@ -150,10 +163,11 @@ concptr process_pref_file_expr(player_type *creature_ptr, char **sp, char *fp)
     } else if (streq(b + 1, "GRAF")) {
         v = ANGBAND_GRAF;
     } else if (streq(b + 1, "MONOCHROME")) {
-        if (arg_monochrome)
+        if (arg_monochrome) {
             v = "ON";
-        else
+        } else {
             v = "OFF";
+        }
     } else if (streq(b + 1, "RACE")) {
 #ifdef JP
         v = rp_ptr->E_title;
@@ -169,7 +183,7 @@ concptr process_pref_file_expr(player_type *creature_ptr, char **sp, char *fp)
     } else if (streq(b + 1, "PLAYER")) {
         static char tmp_player_name[32];
         char *pn, *tpn;
-        for (pn = creature_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++) {
+        for (pn = player_ptr->name, tpn = tmp_player_name; *pn; pn++, tpn++) {
 #ifdef JP
             if (iskanji(*pn)) {
                 *(tpn++) = *(pn++);
@@ -184,26 +198,27 @@ concptr process_pref_file_expr(player_type *creature_ptr, char **sp, char *fp)
         v = tmp_player_name;
     } else if (streq(b + 1, "REALM1")) {
 #ifdef JP
-        v = E_realm_names[creature_ptr->realm1];
+        v = E_realm_names[player_ptr->realm1];
 #else
-        v = realm_names[creature_ptr->realm1];
+        v = realm_names[player_ptr->realm1];
 #endif
     } else if (streq(b + 1, "REALM2")) {
 #ifdef JP
-        v = E_realm_names[creature_ptr->realm2];
+        v = E_realm_names[player_ptr->realm2];
 #else
-        v = realm_names[creature_ptr->realm2];
+        v = realm_names[player_ptr->realm2];
 #endif
     } else if (streq(b + 1, "LEVEL")) {
-        sprintf(tmp, "%02d", creature_ptr->lev);
+        strnfmt(tmp, sizeof(tmp), "%02d", player_ptr->lev);
         v = tmp;
     } else if (streq(b + 1, "AUTOREGISTER")) {
-        if (creature_ptr->autopick_autoregister)
+        if (player_ptr->autopick_autoregister) {
             v = "1";
-        else
+        } else {
             v = "0";
+        }
     } else if (streq(b + 1, "MONEY")) {
-        sprintf(tmp, "%09ld", (long int)creature_ptr->au);
+        strnfmt(tmp, sizeof(tmp), "%09ld", (long int)player_ptr->au);
         v = tmp;
     }