OSDN Git Service

[Refactor] #39962 Separated read-pref-file.c/h from files.c/h
authorHourier <hourier@users.sourceforge.jp>
Sun, 1 Mar 2020 12:38:08 +0000 (21:38 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 1 Mar 2020 12:38:08 +0000 (21:38 +0900)
13 files changed:
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/autopick.c
src/birth.c
src/cmd/cmd-dump.c
src/core.c
src/files.c
src/files.h
src/init.c
src/io/read-pref-file.c [new file with mode: 0644]
src/io/read-pref-file.h [new file with mode: 0644]
src/object1.c

index bd54099..a51e2b4 100644 (file)
     <ClCompile Include="..\..\src\init.c" />\r
     <ClCompile Include="..\..\src\io\gf-descriptions.c" />\r
     <ClCompile Include="..\..\src\io\process-pref-file.c" />\r
+    <ClCompile Include="..\..\src\io\read-pref-file.c" />\r
     <ClCompile Include="..\..\src\io\tokenizer.c" />\r
     <ClCompile Include="..\..\src\monster-dist-offsets.c" />\r
     <ClCompile Include="..\..\src\monster-process.c" />\r
     <ClInclude Include="..\..\src\horror-descriptions.h" />\r
     <ClInclude Include="..\..\src\io\gf-descriptions.h" />\r
     <ClInclude Include="..\..\src\io\process-pref-file.h" />\r
+    <ClInclude Include="..\..\src\io\read-pref-file.h" />\r
     <ClInclude Include="..\..\src\io\tokenizer.h" />\r
     <ClInclude Include="..\..\src\monster-dist-offsets.h" />\r
     <ClInclude Include="..\..\src\object-flavor.h" />\r
index 4c699dd..1f34f04 100644 (file)
     <ClCompile Include="..\..\src\core\show-file.c">
       <Filter>core</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\io\read-pref-file.c">
+      <Filter>io</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\core\show-file.h">
       <Filter>core</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\io\read-pref-file.h">
+      <Filter>io</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index d5d1f27..62ca146 100644 (file)
@@ -30,6 +30,7 @@ hengband_SOURCES = \
        io/gf-descriptions.c io/gf-descriptions.h \
        io/tokenizer.c io/tokenizer.h \
        io/process-pref-file.c io/process-pref-file.h \
+       io/read-pref-file.c io/read-pref-file.h \
        io/exit-panic.c io/exit-panic.h \
        signal-handlers.c signal-handlers.h uid-checker.c uid-checker.h \
        character-dump.c character-dump.h core.c core.h files.c files.h \
index 12ac66c..5cd1689 100644 (file)
@@ -18,6 +18,7 @@
 #include "core.h"
 #include "core/show-file.h"
 #include "cmd/cmd-save.h"
+#include "io/read-pref-file.h"
 
 #include "mind.h"
 
index a165883..a860be4 100644 (file)
@@ -16,6 +16,7 @@
 #include "bldg.h"
 #include "core.h"
 #include "core/show-file.h"
+#include "io/read-pref-file.h"
 #include "term.h"
 
 #include "object-ego.h"
index f73dad0..a428bc5 100644 (file)
@@ -44,6 +44,7 @@
 #include "term.h"
 #include "core.h"
 #include "core/show-file.h"
+#include "io/read-pref-file.h"
 #include "chuukei.h"
 
 #include "autopick.h"
index d899b6f..b7a9c8c 100644 (file)
@@ -38,7 +38,7 @@
 #include "cmd/cmd-zaprod.h"
 #include "cmd/cmd-zapwand.h"
 #include "cmd/cmd-pet.h"
-#include "cmd-basic.h"
+#include "cmd/cmd-basic.h"
 #include "racial.h"
 #include "snipe.h"
 #include "dungeon.h"
@@ -89,6 +89,7 @@
 #include "dungeon-file.h"
 #include "uid-checker.h"
 #include "player/process-death.h"
+#include "io/read-pref-file.h"
 #include "files.h"
 #include "scores.h"
 #include "autopick.h"
index db1763b..07ad1b3 100644 (file)
 
 #include "character-dump.h"
 #include "world.h"
-#include "view-mainwindow.h"
-#include "autopick.h"
+#include "view-mainwindow.h" // 暫定。後で消す.
 #include "io/process-pref-file.h" // 暫定。依存性の向きがこれで良いか要確認.
-
-#define PREF_TYPE_NORMAL   0
-#define PREF_TYPE_AUTOPICK 1
-#define PREF_TYPE_HISTPREF 2
+#include "io/process-pref-file.h"
+#include "io/read-pref-file.h"
 
 concptr ANGBAND_DIR; //!< Path name: The main "lib" directory This variable is not actually used anywhere in the code
 concptr ANGBAND_DIR_APEX; //!< High score files (binary) These files may be portable between platforms
@@ -296,137 +293,6 @@ concptr process_pref_file_expr(player_type *creature_ptr, char **sp, char *fp)
 
 
 /*!
- * @brief process_pref_fileのサブルーチン /
- * Open the "user pref file" and parse it.
- * @param creature_ptr プレーヤーへの参照ポインタ
- * @param name 読み込むファイル名
- * @param preftype prefファイルのタイプ
- * @return エラーコード
- * @details
- * <pre>
- * Input:
- *   v: output buffer array
- *   f: final character
- * Output:
- *   result
- * </pre>
- */
-static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int preftype)
-{
-       FILE *fp;
-       fp = my_fopen(name, "r");
-       if (!fp) return -1;
-
-       char buf[1024];
-       char old[1024];
-       int line = -1;
-       errr err = 0;
-       bool bypass = FALSE;
-       while (my_fgets(fp, buf, sizeof(buf)) == 0)
-       {
-               line++;
-               if (!buf[0]) continue;
-
-#ifdef JP
-               if (!iskanji(buf[0]))
-#endif
-                       if (iswspace(buf[0])) continue;
-
-               if (buf[0] == '#') continue;
-               strcpy(old, buf);
-
-               /* Process "?:<expr>" */
-               if ((buf[0] == '?') && (buf[1] == ':'))
-               {
-                       char f;
-                       char *s;
-                       s = buf + 2;
-                       concptr v = process_pref_file_expr(creature_ptr, &s, &f);
-                       bypass = streq(v, "0");
-                       continue;
-               }
-
-               if (bypass) continue;
-
-               /* Process "%:<file>" */
-               if (buf[0] == '%')
-               {
-                       static int depth_count = 0;
-                       if (depth_count > 20) continue;
-
-                       depth_count++;
-                       switch (preftype)
-                       {
-                       case PREF_TYPE_AUTOPICK:
-                               (void)process_autopick_file(creature_ptr, buf + 2);
-                               break;
-                       case PREF_TYPE_HISTPREF:
-                               (void)process_histpref_file(creature_ptr, buf + 2);
-                               break;
-                       default:
-                               (void)process_pref_file(creature_ptr, buf + 2);
-                               break;
-                       }
-
-                       depth_count--;
-                       continue;
-               }
-
-               err = process_pref_file_command(creature_ptr, buf);
-               if (err != 0)
-               {
-                       if (preftype != PREF_TYPE_AUTOPICK)
-                               break;
-                       err = process_autopick_file_command(buf);
-               }
-       }
-
-       if (err != 0)
-       {
-               /* Print error message */
-               /* ToDo: Add better error messages */
-               msg_format(_("ファイル'%s'の%d行でエラー番号%dのエラー。", "Error %d in line %d of file '%s'."),
-                       _(name, err), line, _(err, name));
-               msg_format(_("('%s'を解析中)", "Parsing '%s'"), old);
-               msg_print(NULL);
-       }
-
-       my_fclose(fp);
-       return (err);
-}
-
-
-/*!
- * @brief pref設定ファイルを読み込み設定を反映させる /
- * Process the "user pref file" with the given name
- * @param creature_ptr プレーヤーへの参照ポインタ
- * @param name 読み込むファイル名
- * @return エラーコード
- * @details
- * <pre>
- * See the functions above for a list of legal "commands".
- * We also accept the special "?" and "%" directives, which
- * allow conditional evaluation and filename inclusion.
- * </pre>
- */
-errr process_pref_file(player_type *creature_ptr, concptr name)
-{
-       char buf[1024];
-       path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
-
-       errr err1 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL);
-       if (err1 > 0) return err1;
-
-       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
-       errr err2 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL);
-       if (err2 < 0 && !err1)
-               return -2;
-
-       return err2;
-}
-
-
-/*!
  * @brief プレイヤーステータスをファイルダンプ出力する
  * Hack -- Dump a character description file
  * @param creature_ptr プレーヤーへの参照ポインタ
@@ -579,43 +445,6 @@ errr get_rnd_line_jonly(concptr file_name, int entry, char *output, int count)
 
 
 /*!
- * @brief 自動拾いファイルを読み込む /
- * @param creature_ptr プレーヤーへの参照ポインタ
- * @param name ファイル名
- * @details
- */
-errr process_autopick_file(player_type *creature_ptr, concptr name)
-{
-       char buf[1024];
-       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
-       errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_AUTOPICK);
-       return err;
-}
-
-
-/*!
- * @brief プレイヤーの生い立ちファイルを読み込む /
- * Process file for player's history editor.
- * @param creature_ptr プレーヤーへの参照ポインタ
- * @param name ファイル名
- * @return エラーコード
- * @details
- */
-errr process_histpref_file(player_type *creature_ptr, concptr name)
-{
-       bool old_character_xtra = current_world_ptr->character_xtra;
-       char buf[1024];
-       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
-
-       /* Hack -- prevent modification birth options in this file */
-       current_world_ptr->character_xtra = TRUE;
-       errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_HISTPREF);
-       current_world_ptr->character_xtra = old_character_xtra;
-       return err;
-}
-
-
-/*!
  * @brief ファイル位置をシーク /
  * @param creature_ptr プレーヤーへの参照ポインタ
  * @param fd ファイルディスクリプタ
index 9b58cf6..427ad29 100644 (file)
@@ -22,9 +22,6 @@ typedef void(*display_player_pf)(player_type*, int, map_name_pf);
 
 extern errr file_character(player_type *creature_ptr, concptr name, display_player_pf display_player, map_name_pf map_name);
 extern concptr process_pref_file_expr(player_type *creature_ptr, char **sp, char *fp);
-extern errr process_pref_file(player_type *creature_ptr, concptr name);
-extern errr process_autopick_file(player_type *creature_ptr, concptr name);
-extern errr process_histpref_file(player_type *creature_ptr, concptr name);
 extern errr get_rnd_line(concptr file_name, int entry, char *output);
 void read_dead_file(char* buf, size_t buf_size);
 
index 286499c..4146c76 100644 (file)
@@ -35,6 +35,7 @@
 #include "uid-checker.h"
 #include "files.h"
 #include "core.h"
+#include "io/read-pref-file.h"
 #include "term.h"
 
 #include "artifact.h"
diff --git a/src/io/read-pref-file.c b/src/io/read-pref-file.c
new file mode 100644 (file)
index 0000000..f318542
--- /dev/null
@@ -0,0 +1,170 @@
+#include "io/read-pref-file.h"
+#include "io/process-pref-file.h"
+#include "autopick.h"
+#include "files.h" // 暫定。コールバック化して後で消す.
+#include "world.h"
+
+// todo コールバック関数に変更するので、いずれ消す.
+#define PREF_TYPE_NORMAL   0
+#define PREF_TYPE_AUTOPICK 1
+#define PREF_TYPE_HISTPREF 2
+
+/*!
+ * todo 関数名を変更する
+ * @brief process_pref_fileのサブルーチン /
+ * Open the "user pref file" and parse it.
+ * @param creature_ptr プレーヤーへの参照ポインタ
+ * @param name 読み込むファイル名
+ * @param preftype prefファイルのタイプ
+ * @return エラーコード
+ */
+static errr process_pref_file_aux(player_type *creature_ptr, concptr name, int preftype)
+{
+       FILE *fp;
+       fp = my_fopen(name, "r");
+       if (!fp) return -1;
+
+       char buf[1024];
+       char old[1024];
+       int line = -1;
+       errr err = 0;
+       bool bypass = FALSE;
+       while (my_fgets(fp, buf, sizeof(buf)) == 0)
+       {
+               line++;
+               if (!buf[0]) continue;
+
+#ifdef JP
+               if (!iskanji(buf[0]))
+#endif
+                       if (iswspace(buf[0])) continue;
+
+               if (buf[0] == '#') continue;
+               strcpy(old, buf);
+
+               /* Process "?:<expr>" */
+               if ((buf[0] == '?') && (buf[1] == ':'))
+               {
+                       char f;
+                       char *s;
+                       s = buf + 2;
+                       concptr v = process_pref_file_expr(creature_ptr, &s, &f);
+                       bypass = streq(v, "0");
+                       continue;
+               }
+
+               if (bypass) continue;
+
+               /* Process "%:<file>" */
+               if (buf[0] == '%')
+               {
+                       static int depth_count = 0;
+                       if (depth_count > 20) continue;
+
+                       depth_count++;
+                       switch (preftype)
+                       {
+                       case PREF_TYPE_AUTOPICK:
+                               (void)process_autopick_file(creature_ptr, buf + 2);
+                               break;
+                       case PREF_TYPE_HISTPREF:
+                               (void)process_histpref_file(creature_ptr, buf + 2);
+                               break;
+                       default:
+                               (void)process_pref_file(creature_ptr, buf + 2);
+                               break;
+                       }
+
+                       depth_count--;
+                       continue;
+               }
+
+               err = process_pref_file_command(creature_ptr, buf);
+               if (err != 0)
+               {
+                       if (preftype != PREF_TYPE_AUTOPICK)
+                               break;
+                       err = process_autopick_file_command(buf);
+               }
+       }
+
+       if (err != 0)
+       {
+               /* Print error message */
+               /* ToDo: Add better error messages */
+               msg_format(_("ファイル'%s'の%d行でエラー番号%dのエラー。", "Error %d in line %d of file '%s'."),
+                       _(name, err), line, _(err, name));
+               msg_format(_("('%s'を解析中)", "Parsing '%s'"), old);
+               msg_print(NULL);
+       }
+
+       my_fclose(fp);
+       return (err);
+}
+
+
+/*!
+ * @brief pref設定ファイルを読み込み設定を反映させる /
+ * Process the "user pref file" with the given name
+ * @param creature_ptr プレーヤーへの参照ポインタ
+ * @param name 読み込むファイル名
+ * @return エラーコード
+ * @details
+ * <pre>
+ * See the functions above for a list of legal "commands".
+ * We also accept the special "?" and "%" directives, which
+ * allow conditional evaluation and filename inclusion.
+ * </pre>
+ */
+errr process_pref_file(player_type *creature_ptr, concptr name)
+{
+       char buf[1024];
+       path_build(buf, sizeof(buf), ANGBAND_DIR_PREF, name);
+
+       errr err1 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL);
+       if (err1 > 0) return err1;
+
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
+       errr err2 = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_NORMAL);
+       if (err2 < 0 && !err1)
+               return -2;
+
+       return err2;
+}
+
+
+/*!
+ * @brief 自動拾いファイルを読み込む /
+ * @param creature_ptr プレーヤーへの参照ポインタ
+ * @param name ファイル名
+ * @details
+ */
+errr process_autopick_file(player_type *creature_ptr, concptr name)
+{
+       char buf[1024];
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
+       errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_AUTOPICK);
+       return err;
+}
+
+
+/*!
+ * @brief プレイヤーの生い立ちファイルを読み込む /
+ * Process file for player's history editor.
+ * @param creature_ptr プレーヤーへの参照ポインタ
+ * @param name ファイル名
+ * @return エラーコード
+ * @details
+ */
+errr process_histpref_file(player_type *creature_ptr, concptr name)
+{
+       bool old_character_xtra = current_world_ptr->character_xtra;
+       char buf[1024];
+       path_build(buf, sizeof(buf), ANGBAND_DIR_USER, name);
+
+       /* Hack -- prevent modification birth options in this file */
+       current_world_ptr->character_xtra = TRUE;
+       errr err = process_pref_file_aux(creature_ptr, buf, PREF_TYPE_HISTPREF);
+       current_world_ptr->character_xtra = old_character_xtra;
+       return err;
+}
diff --git a/src/io/read-pref-file.h b/src/io/read-pref-file.h
new file mode 100644 (file)
index 0000000..03aa856
--- /dev/null
@@ -0,0 +1,7 @@
+#pragma once
+
+#include "angband.h"
+
+extern errr process_pref_file(player_type *creature_ptr, concptr name);
+extern errr process_autopick_file(player_type *creature_ptr, concptr name);
+extern errr process_histpref_file(player_type *creature_ptr, concptr name);
index bff109c..c82f2e9 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "angband.h"
 #include "core.h"
+#include "io/read-pref-file.h"
 #include "util.h"
 
 #include "artifact.h"