OSDN Git Service

[refactor] 正式なbool型の導入
authorHabu <habu1010+github@gmail.com>
Thu, 25 Feb 2021 15:04:50 +0000 (00:04 +0900)
committerHabu <habu1010+github@gmail.com>
Thu, 25 Feb 2021 15:08:41 +0000 (00:08 +0900)
すでにC99準拠の書き方が使われている(コードブロックの途中で
変数宣言を行う、for文の中で変数宣言を行う等)ので、
typedef char bool ではなく、C99で正式に採用された bool 型を
定義する <stdbool.h> を導入する。
すでにC99準拠以上でなくてはコンパイルが通らなくなっている
はずだが、一応 __STDC_VERSION__ をチェックしてC99以上の時のみ
インクルードする。
また、正式な bool 型を導入した事で bool 型をインクリメント/
デクリメントしているコードやbool型でswitchしているコード、
bool型に0を連続で代入しているコードが見つかったので、
合わせて修正する。

src/cmd-building/cmd-building.c
src/main-gcu.c
src/mspell/mspell-attack-util.h
src/system/h-type.h
src/term/screen-processor.c
src/term/z-term.c

index 6f37a35..a7140b8 100644 (file)
@@ -358,7 +358,7 @@ void do_cmd_building(player_type *player_ptr)
 
        forget_lite(player_ptr->current_floor_ptr);
        forget_view(player_ptr->current_floor_ptr);
-       current_world_ptr->character_icky++;
+       current_world_ptr->character_icky = TRUE;
 
        command_arg = 0;
        command_rep = 0;
@@ -408,7 +408,7 @@ void do_cmd_building(player_type *player_ptr)
 
        if (reinit_wilderness) player_ptr->leaving = TRUE;
 
-       current_world_ptr->character_icky--;
+       current_world_ptr->character_icky = FALSE;
        term_clear();
 
        player_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_BONUS | PU_LITE | PU_MON_LITE);
index 20ba0bf..15dd718 100644 (file)
 /*
  * Hack -- play games with "bool"
  */
+#if __STDC_VERSION__ < 199901L
 #undef bool
+#endif
 
 /*
  * Include the proper "header" file
index 9ab777d..9bce2b9 100644 (file)
@@ -24,7 +24,7 @@ typedef struct msa_type {
     POSITION y;
     POSITION x_br_lite;
     POSITION y_br_lite;
-    bool do_spell;
+    mspell_lite_type do_spell;
     bool in_no_magic_dungeon;
     bool success;
     byte mspells[96];
index ab0ac06..a875a52 100644 (file)
@@ -63,7 +63,11 @@ typedef int errr;
 /* A signed byte of memory */
 /* typedef signed char syte; */
 typedef unsigned char byte; /*!< byte型をunsighned charとして定義 / Note that unsigned values can cause math problems / An unsigned byte of memory */
+#if __STDC_VERSION__ >= 199901L
+#include <stdbool.h>
+#else
 typedef char bool; /*!< bool型をcharとして定義 / Note that a bool is smaller than a full "int" / Simple True/False type */
+#endif
 typedef unsigned int uint; /* uint型をintとして定義 /  An unsigned, "standard" integer (often pre-defined) */
 
 /* The largest possible unsigned integer */
index c7a1944..bbc0fba 100644 (file)
@@ -34,7 +34,7 @@ void screen_save()
     if (screen_depth++ == 0)
         term_save();
 
-    current_world_ptr->character_icky++;
+    current_world_ptr->character_icky = TRUE;
 }
 
 /*
@@ -48,7 +48,7 @@ void screen_load()
     if (--screen_depth == 0)
         term_load();
 
-    current_world_ptr->character_icky--;
+    current_world_ptr->character_icky = FALSE;
 }
 
 /*
index 46d6c9d..431602f 100644 (file)
@@ -1067,7 +1067,8 @@ errr term_fresh(void)
         term_xtra(TERM_XTRA_CLEAR, 0);
 
         /* clear all "cursor" data */
-        old->cv = old->cu = old->cx = old->cy = 0;
+        old->cv = old->cu = FALSE;
+        old->cx = old->cy = 0;
 
         /* Wipe each row */
         for (TERM_LEN y = 0; y < h; y++) {