OSDN Git Service

Replace sprintf() with std::string and/or format(). Does part of the work of resolvi...
[hengbandforosx/hengbandosx.git] / src / birth / history-editor.cpp
index 04d99e8..b85c159 100644 (file)
@@ -6,6 +6,7 @@
 #include "term/screen-processor.h"
 #include "term/term-color-types.h"
 #include "util/int-char-converter.h"
+#include "util/string-processor.h"
 #include "view/display-player.h" // 暫定。後で消す.
 
 /*!
  */
 void edit_history(PlayerType *player_ptr)
 {
-    char old_history[4][60];
+    std::string old_history[4];
     for (int i = 0; i < 4; i++) {
-        sprintf(old_history[i], "%s", player_ptr->history[i]);
+        old_history[i] = player_ptr->history[i];
     }
 
     for (int i = 0; i < 4; i++) {
         /* loop */
         int j;
-        for (j = 0; player_ptr->history[i][j]; j++)
+        for (j = 0; player_ptr->history[i][j]; j++) {
             ;
+        }
 
-        for (; j < 59; j++)
+        for (; j < 59; j++) {
             player_ptr->history[i][j] = ' ';
+        }
         player_ptr->history[i][59] = '\0';
     }
 
@@ -51,37 +54,44 @@ void edit_history(PlayerType *player_ptr)
 
         term_gotoxy(x + 10, y + 12);
         int skey = inkey_special(true);
-        if (!(skey & SKEY_MASK))
+        if (!(skey & SKEY_MASK)) {
             c = (char)skey;
-        else
+        } else {
             c = 0;
+        }
 
         if (skey == SKEY_UP || c == KTRL('p')) {
             y--;
-            if (y < 0)
+            if (y < 0) {
                 y = 3;
+            }
 #ifdef JP
-            if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1)))
+            if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
                 x--;
+            }
 #endif
         } else if (skey == SKEY_DOWN || c == KTRL('n')) {
             y++;
-            if (y > 3)
+            if (y > 3) {
                 y = 0;
+            }
 #ifdef JP
-            if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1)))
+            if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
                 x--;
+            }
 #endif
         } else if (skey == SKEY_RIGHT || c == KTRL('f')) {
 #ifdef JP
-            if (iskanji2(player_ptr->history[y], x))
+            if (iskanji2(player_ptr->history[y], x)) {
                 x++;
+            }
 #endif
             x++;
             if (x > 58) {
                 x = 0;
-                if (y < 3)
+                if (y < 3) {
                     y++;
+                }
             }
         } else if (skey == SKEY_LEFT || c == KTRL('b')) {
             x--;
@@ -89,13 +99,15 @@ void edit_history(PlayerType *player_ptr)
                 if (y) {
                     y--;
                     x = 58;
-                } else
+                } else {
                     x = 0;
+                }
             }
 
 #ifdef JP
-            if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1)))
+            if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
                 x--;
+            }
 #endif
         } else if (c == '\r' || c == '\n') {
             term_erase(0, 11, 255);
@@ -106,7 +118,7 @@ void edit_history(PlayerType *player_ptr)
             clear_from(11);
             put_str(_("(キャラクターの生い立ち)", "(Character Background)"), 11, 25);
             for (int i = 0; i < 4; i++) {
-                sprintf(player_ptr->history[i], "%s", old_history[i]);
+                angband_strcpy(player_ptr->history[i], old_history[i].data(), sizeof(player_ptr->history[i]));
                 put_str(player_ptr->history[i], i + 12, 10);
             }
 
@@ -114,8 +126,9 @@ void edit_history(PlayerType *player_ptr)
         } else if (c == KTRL('A')) {
             if (read_histpref(player_ptr)) {
 #ifdef JP
-                if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1)))
+                if ((x > 0) && (iskanji2(player_ptr->history[y], x - 1))) {
                     x--;
+                }
 #endif
             }
         } else if (c == '\010') {
@@ -124,8 +137,9 @@ void edit_history(PlayerType *player_ptr)
                 if (y) {
                     y--;
                     x = 58;
-                } else
+                } else {
                     x = 0;
+                }
             }
 
             player_ptr->history[y][x] = ' ';
@@ -151,8 +165,9 @@ void edit_history(PlayerType *player_ptr)
                 if (x > 57) {
                     x = 0;
                     y++;
-                    if (y > 3)
+                    if (y > 3) {
                         y = 0;
+                    }
                 }
 
                 if (iskanji2(player_ptr->history[y], x + 1)) {
@@ -168,8 +183,9 @@ void edit_history(PlayerType *player_ptr)
             if (x > 58) {
                 x = 0;
                 y++;
-                if (y > 3)
+                if (y > 3) {
                     y = 0;
+                }
             }
         }
     }