OSDN Git Service

[Refactor] #40236 Unified duplicatied functions
authorHourier <hourier@users.sourceforge.jp>
Sat, 25 Apr 2020 02:27:11 +0000 (11:27 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 25 Apr 2020 02:27:11 +0000 (11:27 +0900)
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/cmd/cmd-dump.c
src/io/dump-remover.c [new file with mode: 0644]
src/io/dump-remover.h [new file with mode: 0644]
src/io/read-pref-file.c

index e704c7e..871cf5e 100644 (file)
     <ClCompile Include="..\..\src\artifact.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-entry.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-menu-data-table.c" />\r
+    <ClCompile Include="..\..\src\autopick\autopick-util.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick.c" />\r
     <ClCompile Include="..\..\src\avatar.c" />\r
     <ClCompile Include="..\..\src\birth.c" />\r
     <ClCompile Include="..\..\src\cmd\cmd-knowledge.c" />\r
     <ClCompile Include="..\..\src\cmd\cmd-process-screen.c" />\r
     <ClCompile Include="..\..\src\cmd\dump-util.c" />\r
+    <ClCompile Include="..\..\src\io\dump-remover.c" />\r
     <ClCompile Include="..\..\src\io\mutations-dump.c" />\r
     <ClCompile Include="..\..\src\knowledge\knowledge-autopick.c" />\r
     <ClCompile Include="..\..\src\knowledge\knowledge-features.c" />\r
     <ClInclude Include="..\..\src\cmd\cmd-knowledge.h" />\r
     <ClInclude Include="..\..\src\cmd\cmd-process-screen.h" />\r
     <ClInclude Include="..\..\src\cmd\dump-util.h" />\r
+    <ClInclude Include="..\..\src\io\dump-remover.h" />\r
     <ClInclude Include="..\..\src\io\mutations-dump.h" />\r
     <ClInclude Include="..\..\src\knowledge\knowledge-autopick.h" />\r
     <ClInclude Include="..\..\src\knowledge\knowledge-features.h" />\r
index d4f720c..ea48128 100644 (file)
     <ClCompile Include="..\..\src\autopick\autopick-entry.c">
       <Filter>autopick</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\autopick\autopick-util.c">
+      <Filter>autopick</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\src\io\dump-remover.c">
+      <Filter>io</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\autopick\autopick-entry.h">
       <Filter>autopick</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\io\dump-remover.h">
+      <Filter>io</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index ac49422..c33909f 100644 (file)
@@ -14,7 +14,8 @@ hengband_SOURCES = \
        autopick/autopick-editor-table.h autopick/autopick-flags-table.h \
        autopick/autopick-key-flag-process.h autopick/autopick-key-table.h \
        autopick/autopick-menu-data-table.c autopick/autopick-menu-data-table.h \
-       autopick/autopick-methods-table.h autopick/autopick-util.h \
+       autopick/autopick-methods-table.h \
+       autopick/autopick-util.c autopick/autopick-util.h \
        autopick/autopick-entry.c autopick/autopick-entry.h \
        \
        avatar.h avatar.c birth.c birth.h \
@@ -52,6 +53,7 @@ hengband_SOURCES = \
        player/permanent-resistances.c player/permanent-resistances.h \
        player/temporary-resistances.c player/temporary-resistances.h \
        \
+       io/dump-remover.c io/dump-remover.h \
        io/gf-descriptions.c io/gf-descriptions.h \
        io/tokenizer.c io/tokenizer.h \
        io/interpret-pref-file.c io/interpret-pref-file.h \
index fb812de..5dac742 100644 (file)
@@ -35,6 +35,7 @@
 #include "cmd/dump-util.h"
 #include "gameterm.h"
 #include "core.h" // 暫定。後で消す.
+#include "io/dump-remover.h"
 #include "io/read-pref-file.h"
 #include "io/interpret-pref-file.h"
 
 
 #include "chuukei.h"
 
-/*!
- * @brief prefファイルを選択して処理する /
- * Ask for a "user pref line" and process it
- * @brief prf出力内容を消去する /
- * Remove old lines automatically generated before.
- * @param orig_file 消去を行うファイル名
- */
-static void remove_auto_dump(concptr orig_file, concptr auto_dump_mark)
-{
-       char buf[1024];
-       bool between_mark = FALSE;
-       bool changed = FALSE;
-       int line_num = 0;
-       long header_location = 0;
-       char header_mark_str[80];
-       char footer_mark_str[80];
-
-       sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
-       sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
-       size_t mark_len = strlen(footer_mark_str);
-
-       FILE *orig_fff;
-       orig_fff = my_fopen(orig_file, "r");
-       if (!orig_fff) return;
-
-       FILE *tmp_fff = NULL;
-       char tmp_file[FILE_NAME_SIZE];
-       if (!open_temporary_file(&tmp_fff, tmp_file)) return;
-
-       while (TRUE)
-       {
-               if (my_fgets(orig_fff, buf, sizeof(buf)))
-               {
-                       if (between_mark)
-                       {
-                               fseek(orig_fff, header_location, SEEK_SET);
-                               between_mark = FALSE;
-                               continue;
-                       }
-                       else
-                       {
-                               break;
-                       }
-               }
-
-               if (!between_mark)
-               {
-                       if (!strcmp(buf, header_mark_str))
-                       {
-                               header_location = ftell(orig_fff);
-                               line_num = 0;
-                               between_mark = TRUE;
-                               changed = TRUE;
-                       }
-                       else
-                       {
-                               fprintf(tmp_fff, "%s\n", buf);
-                       }
-
-                       continue;
-               }
-
-               if (!strncmp(buf, footer_mark_str, mark_len))
-               {
-                       int tmp;
-                       if (!sscanf(buf + mark_len, " (%d)", &tmp)
-                               || tmp != line_num)
-                       {
-                               fseek(orig_fff, header_location, SEEK_SET);
-                       }
-
-                       between_mark = FALSE;
-                       continue;
-               }
-
-               line_num++;
-       }
-
-       my_fclose(orig_fff);
-       my_fclose(tmp_fff);
-
-       if (changed)
-       {
-               tmp_fff = my_fopen(tmp_file, "r");
-               orig_fff = my_fopen(orig_file, "w");
-               while (!my_fgets(tmp_fff, buf, sizeof(buf)))
-                       fprintf(orig_fff, "%s\n", buf);
-
-               my_fclose(orig_fff);
-               my_fclose(tmp_fff);
-       }
-
-       fd_kill(tmp_file);
-}
-
-
 #ifdef JP
 #else
 /*!
diff --git a/src/io/dump-remover.c b/src/io/dump-remover.c
new file mode 100644 (file)
index 0000000..298382e
--- /dev/null
@@ -0,0 +1,99 @@
+#include "angband.h"
+#include "cmd/dump-util.h"
+#include "io/dump-remover.h"
+#include "io/read-pref-file.h"
+
+/*!
+ * @brief prefファイルを選択して処理する /
+ * Ask for a "user pref line" and process it
+ * @brief prf出力内容を消去する /
+ * Remove old lines automatically generated before.
+ * @param orig_file 消去を行うファイル名
+ */
+void remove_auto_dump(concptr orig_file, concptr auto_dump_mark)
+{
+       char buf[1024];
+       bool between_mark = FALSE;
+       bool changed = FALSE;
+       int line_num = 0;
+       long header_location = 0;
+       char header_mark_str[80];
+       char footer_mark_str[80];
+
+       sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
+       sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
+       size_t mark_len = strlen(footer_mark_str);
+
+       FILE *orig_fff;
+       orig_fff = my_fopen(orig_file, "r");
+       if (!orig_fff) return;
+
+       FILE *tmp_fff = NULL;
+       char tmp_file[FILE_NAME_SIZE];
+       if (!open_temporary_file(&tmp_fff, tmp_file)) return;
+
+       while (TRUE)
+       {
+               if (my_fgets(orig_fff, buf, sizeof(buf)))
+               {
+                       if (between_mark)
+                       {
+                               fseek(orig_fff, header_location, SEEK_SET);
+                               between_mark = FALSE;
+                               continue;
+                       }
+                       else
+                       {
+                               break;
+                       }
+               }
+
+               if (!between_mark)
+               {
+                       if (!strcmp(buf, header_mark_str))
+                       {
+                               header_location = ftell(orig_fff);
+                               line_num = 0;
+                               between_mark = TRUE;
+                               changed = TRUE;
+                       }
+                       else
+                       {
+                               fprintf(tmp_fff, "%s\n", buf);
+                       }
+
+                       continue;
+               }
+
+               if (!strncmp(buf, footer_mark_str, mark_len))
+               {
+                       int tmp;
+                       if (!sscanf(buf + mark_len, " (%d)", &tmp)
+                               || tmp != line_num)
+                       {
+                               fseek(orig_fff, header_location, SEEK_SET);
+                       }
+
+                       between_mark = FALSE;
+                       continue;
+               }
+
+               line_num++;
+       }
+
+       my_fclose(orig_fff);
+       my_fclose(tmp_fff);
+
+       if (changed)
+       {
+               tmp_fff = my_fopen(tmp_file, "r");
+               orig_fff = my_fopen(orig_file, "w");
+               while (!my_fgets(tmp_fff, buf, sizeof(buf)))
+                       fprintf(orig_fff, "%s\n", buf);
+
+               my_fclose(orig_fff);
+               my_fclose(tmp_fff);
+       }
+
+       fd_kill(tmp_file);
+}
diff --git a/src/io/dump-remover.h b/src/io/dump-remover.h
new file mode 100644 (file)
index 0000000..f720985
--- /dev/null
@@ -0,0 +1,3 @@
+#pragma once
+
+void remove_auto_dump(concptr orig_file, concptr auto_dump_mark);
index 11d4830..9bda358 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include "angband.h"
+#include "io/dump-remover.h"
 #include "io/read-pref-file.h"
 #include "io/interpret-pref-file.h"
 #include "autopick/autopick.h"
@@ -198,104 +199,6 @@ errr process_histpref_file(player_type *creature_ptr, concptr name)
 
 
 /*!
- * @brief prf出力内容を消去する /
- * Remove old lines automatically generated before.
- * @param orig_file 消去を行うファイル名
- */
-static void remove_auto_dump(concptr orig_file, concptr auto_dump_mark)
-{
-       char header_mark_str[80];
-       char footer_mark_str[80];
-       sprintf(header_mark_str, auto_dump_header, auto_dump_mark);
-       sprintf(footer_mark_str, auto_dump_footer, auto_dump_mark);
-       size_t mark_len = strlen(footer_mark_str);
-       FILE *orig_fff;
-       orig_fff = my_fopen(orig_file, "r");
-       if (!orig_fff) return;
-
-       char tmp_file[1024];
-       FILE *tmp_fff;
-       tmp_fff = my_fopen_temp(tmp_file, 1024);
-       if (!tmp_fff)
-       {
-               msg_format(_("一時ファイル %s を作成できませんでした。", "Failed to create temporary file %s."), tmp_file);
-               msg_print(NULL);
-               return;
-       }
-
-       char buf[1024];
-       bool between_mark = FALSE;
-       bool changed = FALSE;
-       int line_num = 0;
-       long header_location = 0;
-       while (TRUE)
-       {
-               if (my_fgets(orig_fff, buf, sizeof(buf)))
-               {
-                       if (between_mark)
-                       {
-                               fseek(orig_fff, header_location, SEEK_SET);
-                               between_mark = FALSE;
-                               continue;
-                       }
-                       else
-                       {
-                               break;
-                       }
-               }
-
-               if (!between_mark)
-               {
-                       if (!strcmp(buf, header_mark_str))
-                       {
-                               header_location = ftell(orig_fff);
-                               line_num = 0;
-                               between_mark = TRUE;
-                               changed = TRUE;
-                       }
-                       else
-                       {
-                               fprintf(tmp_fff, "%s\n", buf);
-                       }
-
-                       continue;
-               }
-
-               if (!strncmp(buf, footer_mark_str, mark_len))
-               {
-                       int tmp;
-                       if (!sscanf(buf + mark_len, " (%d)", &tmp)
-                               || tmp != line_num)
-                       {
-                               fseek(orig_fff, header_location, SEEK_SET);
-                       }
-
-                       between_mark = FALSE;
-                       continue;
-               }
-
-               line_num++;
-       }
-
-       my_fclose(orig_fff);
-       my_fclose(tmp_fff);
-
-       if (changed)
-       {
-               tmp_fff = my_fopen(tmp_file, "r");
-               orig_fff = my_fopen(orig_file, "w");
-               while (!my_fgets(tmp_fff, buf, sizeof(buf)))
-                       fprintf(orig_fff, "%s\n", buf);
-
-               my_fclose(orig_fff);
-               my_fclose(tmp_fff);
-       }
-
-       fd_kill(tmp_file);
-}
-
-
-/*!
  * @brief prfファイルのフォーマットに従った内容を出力する /
  * Dump a formatted line, using "vstrnfmt()".
  * @param fmt 出力内容