OSDN Git Service

[Refactor] #39964 Separated autopick-editor-util.c/h from autopick.c
authorHourier <hourier@users.sourceforge.jp>
Sun, 26 Apr 2020 02:17:25 +0000 (11:17 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sun, 26 Apr 2020 04:28:31 +0000 (13:28 +0900)
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/autopick/autopick-editor-util.c [new file with mode: 0644]
src/autopick/autopick-editor-util.h [new file with mode: 0644]
src/autopick/autopick.c

index 9b5ae3a..f81c2c3 100644 (file)
     <ClCompile Include="..\..\src\autopick\autopick-describer.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-destroyer.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-drawer.c" />\r
+    <ClCompile Include="..\..\src\autopick\autopick-editor-util.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-entry.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-finder.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-initializer.c" />\r
     <ClInclude Include="..\..\src\autopick\autopick-dirty-flags.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-drawer.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-editor-table.h" />\r
+    <ClInclude Include="..\..\src\autopick\autopick-editor-util.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-entry.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-finder.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-flags-table.h" />\r
index 94d346c..14bb71e 100644 (file)
     <ClCompile Include="..\..\src\autopick\autopick-command-menu.c">
       <Filter>autopick</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\autopick\autopick-editor-util.c">
+      <Filter>autopick</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\autopick\autopick-command-menu.h">
       <Filter>autopick</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\autopick\autopick-editor-util.h">
+      <Filter>autopick</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 8e2c994..d964e0a 100644 (file)
@@ -30,6 +30,7 @@ hengband_SOURCES = \
        autopick/autopick-inserter-killer.c autopick/autopick-inserter-killer.h \
        autopick/autopick-registry.c autopick/autopick-registry.h \
        autopick/autopick-command-menu.c autopick/autopick-command-menu.h \
+       autopick-editor-util.c autopick-editor-util.h \
        \
        avatar.h avatar.c birth.c birth.h \
        \
diff --git a/src/autopick/autopick-editor-util.c b/src/autopick/autopick-editor-util.c
new file mode 100644 (file)
index 0000000..0b7f6db
--- /dev/null
@@ -0,0 +1,320 @@
+#include "angband.h"
+#include "autopick/autopick-util.h"
+#include "autopick/autopick-editor-util.h"
+#include "autopick/autopick-flags-table.h"
+#include "autopick/autopick-methods-table.h"
+#include "autopick/autopick-dirty-flags.h"
+#include "autopick/autopick-entry.h"
+#include "autopick/autopick-key-flag-process.h"
+
+/*
+ * Delete or insert string
+ */
+void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
+{
+       int by1, by2;
+       bool add = TRUE;
+       bool fixed = FALSE;
+       if (tb->mark)
+       {
+               by1 = MIN(tb->my, tb->cy);
+               by2 = MAX(tb->my, tb->cy);
+       }
+       else /* if (!tb->mark) */
+       {
+               by1 = by2 = tb->cy;
+       }
+
+       for (int y = by1; y <= by2; y++)
+       {
+               autopick_type an_entry, *entry = &an_entry;
+               if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
+
+               string_free(tb->lines_list[y]);
+               if (!fixed)
+               {
+                       if (!IS_FLG(flg)) add = TRUE;
+                       else add = FALSE;
+
+                       fixed = TRUE;
+               }
+
+               if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
+               {
+                       int i;
+                       for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
+                               REM_FLG(i);
+               }
+               else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
+               {
+                       int i;
+                       for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
+                               REM_FLG(i);
+               }
+               else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
+               {
+                       int i;
+                       for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
+                               REM_FLG(i);
+               }
+               else if (FLG_RARE <= flg && flg <= FLG_COMMON)
+               {
+                       int i;
+                       for (i = FLG_RARE; i <= FLG_COMMON; i++)
+                               REM_FLG(i);
+               }
+
+               if (add) ADD_FLG(flg);
+               else REM_FLG(flg);
+
+               tb->lines_list[y] = autopick_line_from_entry_kill(entry);
+               tb->dirty_flags |= DIRTY_ALL;
+               tb->changed = TRUE;
+       }
+}
+
+
+/*
+ * Change command letter
+ */
+void toggle_command_letter(text_body_type *tb, byte flg)
+{
+       autopick_type an_entry;
+       autopick_type *entry = &an_entry;
+       int by1, by2;
+       bool add = TRUE;
+       bool fixed = FALSE;
+       if (tb->mark)
+       {
+               by1 = MIN(tb->my, tb->cy);
+               by2 = MAX(tb->my, tb->cy);
+       }
+       else /* if (!tb->mark) */
+       {
+               by1 = by2 = tb->cy;
+       }
+
+       for (int y = by1; y <= by2; y++)
+       {
+               int wid = 0;
+
+               if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
+
+               string_free(tb->lines_list[y]);
+
+               if (!fixed)
+               {
+                       if (!(entry->action & flg)) add = TRUE;
+                       else add = FALSE;
+
+                       fixed = TRUE;
+               }
+
+               if (entry->action & DONT_AUTOPICK) wid--;
+               else if (entry->action & DO_AUTODESTROY) wid--;
+               else if (entry->action & DO_QUERY_AUTOPICK) wid--;
+               if (!(entry->action & DO_DISPLAY)) wid--;
+
+               if (flg != DO_DISPLAY)
+               {
+                       entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
+                       if (add) entry->action |= flg;
+                       else entry->action |= DO_AUTOPICK;
+               }
+               else
+               {
+                       entry->action &= ~(DO_DISPLAY);
+                       if (add) entry->action |= flg;
+               }
+
+               if (tb->cy == y)
+               {
+                       if (entry->action & DONT_AUTOPICK) wid++;
+                       else if (entry->action & DO_AUTODESTROY) wid++;
+                       else if (entry->action & DO_QUERY_AUTOPICK) wid++;
+                       if (!(entry->action & DO_DISPLAY)) wid++;
+
+                       if (wid > 0) tb->cx++;
+                       if (wid < 0 && tb->cx > 0) tb->cx--;
+               }
+
+               tb->lines_list[y] = autopick_line_from_entry_kill(entry);
+               tb->dirty_flags |= DIRTY_ALL;
+               tb->changed = TRUE;
+       }
+}
+
+
+/*
+ * Delete or insert string
+ */
+void add_keyword(text_body_type *tb, BIT_FLAGS flg)
+{
+       int by1, by2;
+       if (tb->mark)
+       {
+               by1 = MIN(tb->my, tb->cy);
+               by2 = MAX(tb->my, tb->cy);
+       }
+       else
+       {
+               by1 = by2 = tb->cy;
+       }
+
+       for (int y = by1; y <= by2; y++)
+       {
+               autopick_type an_entry, *entry = &an_entry;
+               if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
+
+               if (IS_FLG(flg))
+               {
+                       autopick_free_entry(entry);
+                       continue;
+               }
+
+               string_free(tb->lines_list[y]);
+               if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
+               {
+                       int i;
+                       for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
+                               REM_FLG(i);
+               }
+
+               ADD_FLG(flg);
+               tb->lines_list[y] = autopick_line_from_entry_kill(entry);
+               tb->dirty_flags |= DIRTY_ALL;
+               tb->changed = TRUE;
+       }
+}
+
+
+/*
+ * Add an empty line at the last of the file
+ */
+bool add_empty_line(text_body_type *tb)
+{
+       int num_lines;
+       for (num_lines = 0; tb->lines_list[num_lines]; num_lines++);
+
+       if (num_lines >= MAX_LINES - 2) return FALSE;
+       if (!tb->lines_list[num_lines - 1][0]) return FALSE;
+
+       tb->lines_list[num_lines] = string_make("");
+       tb->dirty_flags |= DIRTY_EXPRESSION;
+       tb->changed = TRUE;
+       return TRUE;
+}
+
+
+static chain_str_type *new_chain_str(concptr str)
+{
+       chain_str_type *chain;
+       size_t len = strlen(str);
+       chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
+       strcpy(chain->s, str);
+       chain->next = NULL;
+       return chain;
+}
+
+
+void kill_yank_chain(text_body_type *tb)
+{
+       chain_str_type *chain = tb->yank;
+       tb->yank = NULL;
+       tb->yank_eol = TRUE;
+
+       while (chain)
+       {
+               chain_str_type *next = chain->next;
+               size_t len = strlen(chain->s);
+
+               rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
+
+               chain = next;
+       }
+}
+
+
+void add_str_to_yank(text_body_type *tb, concptr str)
+{
+       tb->yank_eol = FALSE;
+       if (NULL == tb->yank)
+       {
+               tb->yank = new_chain_str(str);
+               return;
+       }
+
+       chain_str_type *chain;
+       chain = tb->yank;
+
+       while (TRUE)
+       {
+               if (!chain->next)
+               {
+                       chain->next = new_chain_str(str);
+                       return;
+               }
+
+               /* Go to next */
+               chain = chain->next;
+       }
+}
+
+
+/*
+ * Do work for the copy editor-command
+ */
+void copy_text_to_yank(text_body_type *tb)
+{
+       int len = strlen(tb->lines_list[tb->cy]);
+       if (tb->cx > len) tb->cx = len;
+
+       if (!tb->mark)
+       {
+               tb->cx = 0;
+               tb->my = tb->cy;
+               tb->mx = len;
+       }
+
+       kill_yank_chain(tb);
+       if (tb->my != tb->cy)
+       {
+               int by1 = MIN(tb->my, tb->cy);
+               int by2 = MAX(tb->my, tb->cy);
+
+               for (int y = by1; y <= by2; y++)
+               {
+                       add_str_to_yank(tb, tb->lines_list[y]);
+               }
+
+               add_str_to_yank(tb, "");
+               tb->mark = 0;
+               tb->dirty_flags |= DIRTY_ALL;
+               return;
+       }
+
+       char buf[MAX_LINELEN];
+       int bx1 = MIN(tb->mx, tb->cx);
+       int bx2 = MAX(tb->mx, tb->cx);
+       if (bx2 > len) bx2 = len;
+
+       if (bx1 == 0 && bx2 == len)
+       {
+               add_str_to_yank(tb, tb->lines_list[tb->cy]);
+               add_str_to_yank(tb, "");
+       }
+       else
+       {
+               int end = bx2 - bx1;
+               for (int i = 0; i < bx2 - bx1; i++)
+               {
+                       buf[i] = tb->lines_list[tb->cy][bx1 + i];
+               }
+
+               buf[end] = '\0';
+               add_str_to_yank(tb, buf);
+       }
+
+       tb->mark = 0;
+       tb->dirty_flags |= DIRTY_ALL;
+}
diff --git a/src/autopick/autopick-editor-util.h b/src/autopick/autopick-editor-util.h
new file mode 100644 (file)
index 0000000..48b7eef
--- /dev/null
@@ -0,0 +1,9 @@
+#pragma once
+
+void toggle_keyword(text_body_type *tb, BIT_FLAGS flg);
+void toggle_command_letter(text_body_type *tb, byte flg);
+void add_keyword(text_body_type *tb, BIT_FLAGS flg);
+bool add_empty_line(text_body_type *tb);
+void kill_yank_chain(text_body_type *tb);
+void add_str_to_yank(text_body_type *tb, concptr str);
+void copy_text_to_yank(text_body_type *tb);
index f45ef3b..38962ba 100644 (file)
@@ -29,6 +29,7 @@
 #include "autopick/autopick-inserter-killer.h"
 #include "autopick/autopick-registry.h"
 #include "autopick/autopick-command-menu.h"
+#include "autopick/autopick-editor-util.h"
 #include "gameterm.h"
 #include "autopick/autopick.h"
 #include "core/show-file.h"
@@ -171,319 +172,6 @@ void autopick_pickup_items(player_type* player_ptr, grid_type *g_ptr)
 
 
 /*
- * Delete or insert string
- */
-static void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
-{
-       int by1, by2;
-       bool add = TRUE;
-       bool fixed = FALSE;
-       if (tb->mark)
-       {
-               by1 = MIN(tb->my, tb->cy);
-               by2 = MAX(tb->my, tb->cy);
-       }
-       else /* if (!tb->mark) */
-       {
-               by1 = by2 = tb->cy;
-       }
-
-       for (int y = by1; y <= by2; y++)
-       {
-               autopick_type an_entry, *entry = &an_entry;
-               if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
-
-               string_free(tb->lines_list[y]);
-               if (!fixed)
-               {
-                       if (!IS_FLG(flg)) add = TRUE;
-                       else add = FALSE;
-
-                       fixed = TRUE;
-               }
-
-               if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
-               {
-                       int i;
-                       for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
-                               REM_FLG(i);
-               }
-               else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
-               {
-                       int i;
-                       for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
-                               REM_FLG(i);
-               }
-               else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
-               {
-                       int i;
-                       for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
-                               REM_FLG(i);
-               }
-               else if (FLG_RARE <= flg && flg <= FLG_COMMON)
-               {
-                       int i;
-                       for (i = FLG_RARE; i <= FLG_COMMON; i++)
-                               REM_FLG(i);
-               }
-
-               if (add) ADD_FLG(flg);
-               else REM_FLG(flg);
-
-               tb->lines_list[y] = autopick_line_from_entry_kill(entry);
-               tb->dirty_flags |= DIRTY_ALL;
-               tb->changed = TRUE;
-       }
-}
-
-
-/*
- * Change command letter
- */
-static void toggle_command_letter(text_body_type *tb, byte flg)
-{
-       autopick_type an_entry;
-       autopick_type *entry = &an_entry;
-       int by1, by2;
-       bool add = TRUE;
-       bool fixed = FALSE;
-       if (tb->mark)
-       {
-               by1 = MIN(tb->my, tb->cy);
-               by2 = MAX(tb->my, tb->cy);
-       }
-       else /* if (!tb->mark) */
-       {
-               by1 = by2 = tb->cy;
-       }
-
-       for (int y = by1; y <= by2; y++)
-       {
-               int wid = 0;
-
-               if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
-
-               string_free(tb->lines_list[y]);
-
-               if (!fixed)
-               {
-                       if (!(entry->action & flg)) add = TRUE;
-                       else add = FALSE;
-
-                       fixed = TRUE;
-               }
-
-               if (entry->action & DONT_AUTOPICK) wid--;
-               else if (entry->action & DO_AUTODESTROY) wid--;
-               else if (entry->action & DO_QUERY_AUTOPICK) wid--;
-               if (!(entry->action & DO_DISPLAY)) wid--;
-
-               if (flg != DO_DISPLAY)
-               {
-                       entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
-                       if (add) entry->action |= flg;
-                       else entry->action |= DO_AUTOPICK;
-               }
-               else
-               {
-                       entry->action &= ~(DO_DISPLAY);
-                       if (add) entry->action |= flg;
-               }
-
-               if (tb->cy == y)
-               {
-                       if (entry->action & DONT_AUTOPICK) wid++;
-                       else if (entry->action & DO_AUTODESTROY) wid++;
-                       else if (entry->action & DO_QUERY_AUTOPICK) wid++;
-                       if (!(entry->action & DO_DISPLAY)) wid++;
-
-                       if (wid > 0) tb->cx++;
-                       if (wid < 0 && tb->cx > 0) tb->cx--;
-               }
-
-               tb->lines_list[y] = autopick_line_from_entry_kill(entry);
-               tb->dirty_flags |= DIRTY_ALL;
-               tb->changed = TRUE;
-       }
-}
-
-
-/*
- * Delete or insert string
- */
-static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
-{
-       int by1, by2;
-       if (tb->mark)
-       {
-               by1 = MIN(tb->my, tb->cy);
-               by2 = MAX(tb->my, tb->cy);
-       }
-       else
-       {
-               by1 = by2 = tb->cy;
-       }
-
-       for (int y = by1; y <= by2; y++)
-       {
-               autopick_type an_entry, *entry = &an_entry;
-               if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
-
-               if (IS_FLG(flg))
-               {
-                       autopick_free_entry(entry);
-                       continue;
-               }
-
-               string_free(tb->lines_list[y]);
-               if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
-               {
-                       int i;
-                       for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
-                               REM_FLG(i);
-               }
-
-               ADD_FLG(flg);
-               tb->lines_list[y] = autopick_line_from_entry_kill(entry);
-               tb->dirty_flags |= DIRTY_ALL;
-               tb->changed = TRUE;
-       }
-}
-
-
-/*
- * Add an empty line at the last of the file
- */
-static bool add_empty_line(text_body_type *tb)
-{
-       int num_lines;
-       for (num_lines = 0; tb->lines_list[num_lines]; num_lines++);
-
-       if (num_lines >= MAX_LINES - 2) return FALSE;
-       if (!tb->lines_list[num_lines - 1][0]) return FALSE;
-
-       tb->lines_list[num_lines] = string_make("");
-       tb->dirty_flags |= DIRTY_EXPRESSION;
-       tb->changed = TRUE;
-       return TRUE;
-}
-
-
-static chain_str_type *new_chain_str(concptr str)
-{
-       chain_str_type *chain;
-       size_t len = strlen(str);
-       chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
-       strcpy(chain->s, str);
-       chain->next = NULL;
-       return chain;
-}
-
-
-static void kill_yank_chain(text_body_type *tb)
-{
-       chain_str_type *chain = tb->yank;
-       tb->yank = NULL;
-       tb->yank_eol = TRUE;
-
-       while (chain)
-       {
-               chain_str_type *next = chain->next;
-               size_t len = strlen(chain->s);
-
-               rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
-
-               chain = next;
-       }
-}
-
-
-static void add_str_to_yank(text_body_type *tb, concptr str)
-{
-       tb->yank_eol = FALSE;
-       if (NULL == tb->yank)
-       {
-               tb->yank = new_chain_str(str);
-               return;
-       }
-
-       chain_str_type *chain;
-       chain = tb->yank;
-
-       while (TRUE)
-       {
-               if (!chain->next)
-               {
-                       chain->next = new_chain_str(str);
-                       return;
-               }
-
-               /* Go to next */
-               chain = chain->next;
-       }
-}
-
-
-/*
- * Do work for the copy editor-command
- */
-static void copy_text_to_yank(text_body_type *tb)
-{
-       int len = strlen(tb->lines_list[tb->cy]);
-       if (tb->cx > len) tb->cx = len;
-
-       if (!tb->mark)
-       {
-               tb->cx = 0;
-               tb->my = tb->cy;
-               tb->mx = len;
-       }
-
-       kill_yank_chain(tb);
-       if (tb->my != tb->cy)
-       {
-               int by1 = MIN(tb->my, tb->cy);
-               int by2 = MAX(tb->my, tb->cy);
-
-               for (int y = by1; y <= by2; y++)
-               {
-                       add_str_to_yank(tb, tb->lines_list[y]);
-               }
-
-               add_str_to_yank(tb, "");
-               tb->mark = 0;
-               tb->dirty_flags |= DIRTY_ALL;
-               return;
-       }
-
-       char buf[MAX_LINELEN];
-       int bx1 = MIN(tb->mx, tb->cx);
-       int bx2 = MAX(tb->mx, tb->cx);
-       if (bx2 > len) bx2 = len;
-
-       if (bx1 == 0 && bx2 == len)
-       {
-               add_str_to_yank(tb, tb->lines_list[tb->cy]);
-               add_str_to_yank(tb, "");
-       }
-       else
-       {
-               int end = bx2 - bx1;
-               for (int i = 0; i < bx2 - bx1; i++)
-               {
-                       buf[i] = tb->lines_list[tb->cy][bx1 + i];
-               }
-
-               buf[end] = '\0';
-               add_str_to_yank(tb, buf);
-       }
-
-       tb->mark = 0;
-       tb->dirty_flags |= DIRTY_ALL;
-}
-
-
-/*
  * Execute a single editor command
  */
 static bool do_editor_command(player_type *player_ptr, text_body_type *tb, int com_id)