OSDN Git Service

[Refactor] #39964 Separated autopick-searcher.c/h from autopick.c
authorHourier <hourier@users.sourceforge.jp>
Sat, 25 Apr 2020 15:58:04 +0000 (00:58 +0900)
committerHourier <hourier@users.sourceforge.jp>
Sat, 25 Apr 2020 16:00:03 +0000 (01:00 +0900)
Hengband_vcs2017/Hengband/Hengband.vcxproj
Hengband_vcs2017/Hengband/Hengband.vcxproj.filters
src/Makefile.am
src/autopick/autopick-searcher.c [new file with mode: 0644]
src/autopick/autopick-searcher.h [new file with mode: 0644]
src/autopick/autopick.c

index 9dfd3b5..e6ba72a 100644 (file)
     <ClCompile Include="..\..\src\autopick\autopick-menu-data-table.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-pref-processor.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-reader-writer.c" />\r
+    <ClCompile Include="..\..\src\autopick\autopick-searcher.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-util.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick.c" />\r
     <ClCompile Include="..\..\src\avatar.c" />\r
     <ClInclude Include="..\..\src\autopick\autopick-methods-table.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-pref-processor.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-reader-writer.h" />\r
+    <ClInclude Include="..\..\src\autopick\autopick-searcher.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-util.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick.h" />\r
     <ClInclude Include="..\..\src\avatar.h" />\r
index 8aa8f5d..6a0cf14 100644 (file)
     <ClCompile Include="..\..\src\autopick\autopick-drawer.c">
       <Filter>autopick</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\autopick\autopick-searcher.c">
+      <Filter>autopick</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\autopick\autopick-drawer.h">
       <Filter>autopick</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\autopick\autopick-searcher.h">
+      <Filter>autopick</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index b4b8c2b..181c50d 100644 (file)
@@ -26,6 +26,7 @@ hengband_SOURCES = \
        autopick/autopick-adder.c autopick/autopick-adder.h \
        autopick/autopick-pref-processor.c autopick/autopick-pref-processor.h \
        autopick/autopick-drawer.c autopick/autopick-drawer.h \
+       autopick/autopick-searcher.c autopick/autopick-searcher.h \
        \
        avatar.h avatar.c birth.c birth.h \
        \
diff --git a/src/autopick/autopick-searcher.c b/src/autopick/autopick-searcher.c
new file mode 100644 (file)
index 0000000..eb1b0e9
--- /dev/null
@@ -0,0 +1,370 @@
+/*!
+ * todo get_string_for_search() は長い、要分割
+ * @brief 自動拾いの検索
+ * @date 2020/04/26
+ * @author Hourier
+ */
+
+#include "angband.h"
+#include "autopick/autopick-util.h"
+#include "autopick/autopick-searcher.h"
+#include "autopick/autopick-dirty-flags.h"
+#include "autopick/autopick-entry.h"
+#include "autopick/autopick-matcher.h"
+#include "object-flavor.h"
+#include "gameterm.h"
+#include "player-inventory.h"
+
+/*
+ * Choose an item for search
+ */
+bool get_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
+{
+       concptr q = _("どのアイテムを検索しますか? ", "Enter which item? ");
+       concptr s = _("アイテムを持っていない。", "You have nothing to enter.");
+       object_type *o_ptr;
+       o_ptr = choose_object(player_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
+       if (!o_ptr) return FALSE;
+
+       *o_handle = o_ptr;
+       string_free(*search_strp);
+       char buf[MAX_NLEN + 20];
+       object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
+       *search_strp = string_make(format("<%s>", buf));
+       return TRUE;
+}
+
+
+/*
+ * Prepare for search by destroyed object
+ */
+bool get_destroyed_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
+{
+       if (!autopick_last_destroyed_object.k_idx) return FALSE;
+
+       *o_handle = &autopick_last_destroyed_object;
+       string_free(*search_strp);
+       char buf[MAX_NLEN + 20];
+       object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
+       *search_strp = string_make(format("<%s>", buf));
+       return TRUE;
+}
+
+
+/*
+ * Choose an item or string for search
+ */
+byte get_string_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
+{
+       /*
+        * Text color
+        * TERM_YELLOW : Overwrite mode
+        * TERM_WHITE : Insert mode
+        */
+       byte color = TERM_YELLOW;
+       char buf[MAX_NLEN + 20];
+       const int len = 80;
+       char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
+       int col = sizeof(prompt) - 1;
+       if (*search_strp) strcpy(buf, *search_strp);
+       else buf[0] = '\0';
+
+       if (*o_handle) color = TERM_L_GREEN;
+
+       prt(prompt, 0, 0);
+       int pos = 0;
+       while (TRUE)
+       {
+               bool back = FALSE;
+               Term_erase(col, 0, 255);
+               Term_putstr(col, 0, -1, color, buf);
+               Term_gotoxy(col + pos, 0);
+
+               int skey = inkey_special(TRUE);
+               switch (skey)
+               {
+               case SKEY_LEFT:
+               case KTRL('b'):
+               {
+                       int i = 0;
+                       color = TERM_WHITE;
+                       if (pos == 0) break;
+
+                       while (TRUE)
+                       {
+                               int next_pos = i + 1;
+
+#ifdef JP
+                               if (iskanji(buf[i])) next_pos++;
+#endif
+                               if (next_pos >= pos) break;
+
+                               i = next_pos;
+                       }
+
+                       pos = i;
+                       break;
+               }
+
+               case SKEY_RIGHT:
+               case KTRL('f'):
+                       color = TERM_WHITE;
+                       if ('\0' == buf[pos]) break;
+
+#ifdef JP
+                       if (iskanji(buf[pos])) pos += 2;
+                       else pos++;
+#else
+                       pos++;
+#endif
+                       break;
+
+               case ESCAPE:
+                       return 0;
+
+               case KTRL('r'):
+                       back = TRUE;
+                       /* Fall through */
+
+               case '\n':
+               case '\r':
+               case KTRL('s'):
+                       if (*o_handle) return (back ? -1 : 1);
+                       string_free(*search_strp);
+                       *search_strp = string_make(buf);
+                       *o_handle = NULL;
+                       return (back ? -1 : 1);
+
+               case KTRL('i'):
+                       return get_object_for_search(player_ptr, o_handle, search_strp);
+
+               case KTRL('l'):
+                       if (get_destroyed_object_for_search(player_ptr, o_handle, search_strp))
+                               return 1;
+                       break;
+
+               case '\010':
+               {
+                       int i = 0;
+                       color = TERM_WHITE;
+                       if (pos == 0) break;
+
+                       while (TRUE)
+                       {
+                               int next_pos = i + 1;
+#ifdef JP
+                               if (iskanji(buf[i])) next_pos++;
+#endif
+                               if (next_pos >= pos) break;
+
+                               i = next_pos;
+                       }
+
+                       pos = i;
+               }
+                       /* Fall through */
+
+               case 0x7F:
+               case KTRL('d'):
+               {
+                       int dst, src;
+                       color = TERM_WHITE;
+                       if (buf[pos] == '\0') break;
+
+                       src = pos + 1;
+#ifdef JP
+                       if (iskanji(buf[pos])) src++;
+#endif
+                       dst = pos;
+                       while ('\0' != (buf[dst++] = buf[src++]));
+
+                       break;
+               }
+
+               default:
+               {
+                       char tmp[100];
+                       char c;
+                       if (skey & SKEY_MASK) break;
+
+                       c = (char)skey;
+                       if (color != TERM_WHITE)
+                       {
+                               if (color == TERM_L_GREEN)
+                               {
+                                       *o_handle = NULL;
+                                       string_free(*search_strp);
+                                       *search_strp = NULL;
+                               }
+
+                               buf[0] = '\0';
+                               color = TERM_WHITE;
+                       }
+
+                       strcpy(tmp, buf + pos);
+#ifdef JP
+                       if (iskanji(c))
+                       {
+                               char next;
+                               inkey_base = TRUE;
+                               next = inkey();
+
+                               if (pos + 1 < len)
+                               {
+                                       buf[pos++] = c;
+                                       buf[pos++] = next;
+                               }
+                               else
+                               {
+                                       bell();
+                               }
+                       }
+                       else
+#endif
+                       {
+#ifdef JP
+                               if (pos < len && (isprint(c) || iskana(c)))
+#else
+                               if (pos < len && isprint(c))
+#endif
+                               {
+                                       buf[pos++] = c;
+                               }
+                               else
+                               {
+                                       bell();
+                               }
+                       }
+
+                       buf[pos] = '\0';
+                       my_strcat(buf, tmp, len + 1);
+
+                       break;
+               }
+               }
+
+               if (*o_handle == NULL || color == TERM_L_GREEN) continue;
+
+               *o_handle = NULL;
+               buf[0] = '\0';
+               string_free(*search_strp);
+               *search_strp = NULL;
+       }
+}
+
+
+/*
+ * Search next line matches for o_ptr
+ */
+void search_for_object(player_type *player_ptr, text_body_type *tb, object_type *o_ptr, bool forward)
+{
+       autopick_type an_entry, *entry = &an_entry;
+       GAME_TEXT o_name[MAX_NLEN];
+       int bypassed_cy = -1;
+       int i = tb->cy;
+       object_desc(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
+       str_tolower(o_name);
+
+       while (TRUE)
+       {
+               bool match;
+               if (forward)
+               {
+                       if (!tb->lines_list[++i]) break;
+               }
+               else
+               {
+                       if (--i < 0) break;
+               }
+
+               if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
+
+               match = is_autopick_match(player_ptr, o_ptr, entry, o_name);
+               autopick_free_entry(entry);
+               if (!match)     continue;
+
+               if (tb->states[i] & LSTAT_BYPASS)
+               {
+                       if (bypassed_cy == -1) bypassed_cy = i;
+                       continue;
+               }
+
+               tb->cx = 0;
+               tb->cy = i;
+               if (bypassed_cy != -1)
+               {
+                       tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
+               }
+
+               return;
+       }
+
+       if (bypassed_cy == -1)
+       {
+               tb->dirty_flags |= DIRTY_NOT_FOUND;
+               return;
+       }
+
+       tb->cx = 0;
+       tb->cy = bypassed_cy;
+       tb->dirty_flags |= DIRTY_INACTIVE;
+}
+
+
+/*
+ * Search next line matches to the string
+ */
+void search_for_string(text_body_type *tb, concptr search_str, bool forward)
+{
+       int bypassed_cy = -1;
+       int bypassed_cx = 0;
+
+       int i = tb->cy;
+       while (TRUE)
+       {
+               concptr pos;
+               if (forward)
+               {
+                       if (!tb->lines_list[++i]) break;
+               }
+               else
+               {
+                       if (--i < 0) break;
+               }
+
+               pos = my_strstr(tb->lines_list[i], search_str);
+               if (!pos) continue;
+
+               if ((tb->states[i] & LSTAT_BYPASS) &&
+                       !(tb->states[i] & LSTAT_EXPRESSION))
+               {
+                       if (bypassed_cy == -1)
+                       {
+                               bypassed_cy = i;
+                               bypassed_cx = (int)(pos - tb->lines_list[i]);
+                       }
+
+                       continue;
+               }
+
+               tb->cx = (int)(pos - tb->lines_list[i]);
+               tb->cy = i;
+
+               if (bypassed_cy != -1)
+               {
+                       tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
+               }
+
+               return;
+       }
+
+       if (bypassed_cy == -1)
+       {
+               tb->dirty_flags |= DIRTY_NOT_FOUND;
+               return;
+       }
+
+       tb->cx = bypassed_cx;
+       tb->cy = bypassed_cy;
+       tb->dirty_flags |= DIRTY_INACTIVE;
+}
diff --git a/src/autopick/autopick-searcher.h b/src/autopick/autopick-searcher.h
new file mode 100644 (file)
index 0000000..77286a9
--- /dev/null
@@ -0,0 +1,7 @@
+#pragma once
+
+bool get_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp);
+bool get_destroyed_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp);
+byte get_string_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp);
+void search_for_object(player_type *player_ptr, text_body_type *tb, object_type *o_ptr, bool forward);
+void search_for_string(text_body_type *tb, concptr search_str, bool forward);
index d719787..ec7f8e0 100644 (file)
@@ -30,6 +30,7 @@
 #include "autopick/autopick-adder.h"
 #include "autopick/autopick-pref-processor.h"
 #include "autopick/autopick-drawer.h"
+#include "autopick/autopick-searcher.h"
 #include "gameterm.h"
 #include "autopick/autopick.h"
 #include "core.h"
@@ -44,7 +45,6 @@
 #include "player-move.h"
 #include "player-class.h"
 #include "player-race.h"
-#include "player-inventory.h"
 #include "view/display-player.h" // 暫定。後で消す.
 #include "object/object-kind.h"
 #include "object-ego.h"
@@ -650,361 +650,6 @@ static bool insert_return_code(text_body_type *tb)
 
 
 /*
- * Choose an item for search
- */
-static bool get_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
-{
-       concptr q = _("どのアイテムを検索しますか? ", "Enter which item? ");
-       concptr s = _("アイテムを持っていない。", "You have nothing to enter.");
-       object_type *o_ptr;
-       o_ptr = choose_object(player_ptr, NULL, q, s, USE_INVEN | USE_FLOOR | USE_EQUIP, 0);
-       if (!o_ptr) return FALSE;
-
-       *o_handle = o_ptr;
-       string_free(*search_strp);
-       char buf[MAX_NLEN + 20];
-       object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
-       *search_strp = string_make(format("<%s>", buf));
-       return TRUE;
-}
-
-
-/*
- * Prepare for search by destroyed object
- */
-static bool get_destroyed_object_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
-{
-       if (!autopick_last_destroyed_object.k_idx) return FALSE;
-
-       *o_handle = &autopick_last_destroyed_object;
-       string_free(*search_strp);
-       char buf[MAX_NLEN + 20];
-       object_desc(player_ptr, buf, *o_handle, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
-       *search_strp = string_make(format("<%s>", buf));
-       return TRUE;
-}
-
-
-/*
- * Choose an item or string for search
- */
-static byte get_string_for_search(player_type *player_ptr, object_type **o_handle, concptr *search_strp)
-{
-       /*
-        * Text color
-        * TERM_YELLOW : Overwrite mode
-        * TERM_WHITE : Insert mode
-        */
-       byte color = TERM_YELLOW;
-       char buf[MAX_NLEN + 20];
-       const int len = 80;
-       char prompt[] = _("検索(^I:持ち物 ^L:破壊された物): ", "Search key(^I:inven ^L:destroyed): ");
-       int col = sizeof(prompt) - 1;
-       if (*search_strp) strcpy(buf, *search_strp);
-       else buf[0] = '\0';
-
-       if (*o_handle) color = TERM_L_GREEN;
-
-       prt(prompt, 0, 0);
-       int pos = 0;
-       while (TRUE)
-       {
-               bool back = FALSE;
-               Term_erase(col, 0, 255);
-               Term_putstr(col, 0, -1, color, buf);
-               Term_gotoxy(col + pos, 0);
-
-               int skey = inkey_special(TRUE);
-               switch (skey)
-               {
-               case SKEY_LEFT:
-               case KTRL('b'):
-               {
-                       int i = 0;
-                       color = TERM_WHITE;
-                       if (pos == 0) break;
-
-                       while (TRUE)
-                       {
-                               int next_pos = i + 1;
-
-#ifdef JP
-                               if (iskanji(buf[i])) next_pos++;
-#endif
-                               if (next_pos >= pos) break;
-
-                               i = next_pos;
-                       }
-
-                       pos = i;
-                       break;
-               }
-
-               case SKEY_RIGHT:
-               case KTRL('f'):
-                       color = TERM_WHITE;
-                       if ('\0' == buf[pos]) break;
-
-#ifdef JP
-                       if (iskanji(buf[pos])) pos += 2;
-                       else pos++;
-#else
-                       pos++;
-#endif
-                       break;
-
-               case ESCAPE:
-                       return 0;
-
-               case KTRL('r'):
-                       back = TRUE;
-                       /* Fall through */
-
-               case '\n':
-               case '\r':
-               case KTRL('s'):
-                       if (*o_handle) return (back ? -1 : 1);
-                       string_free(*search_strp);
-                       *search_strp = string_make(buf);
-                       *o_handle = NULL;
-                       return (back ? -1 : 1);
-
-               case KTRL('i'):
-                       return get_object_for_search(player_ptr, o_handle, search_strp);
-
-               case KTRL('l'):
-                       if (get_destroyed_object_for_search(player_ptr, o_handle, search_strp))
-                               return 1;
-                       break;
-
-               case '\010':
-               {
-                       int i = 0;
-                       color = TERM_WHITE;
-                       if (pos == 0) break;
-
-                       while (TRUE)
-                       {
-                               int next_pos = i + 1;
-#ifdef JP
-                               if (iskanji(buf[i])) next_pos++;
-#endif
-                               if (next_pos >= pos) break;
-
-                               i = next_pos;
-                       }
-
-                       pos = i;
-               }
-                       /* Fall through */
-
-               case 0x7F:
-               case KTRL('d'):
-               {
-                       int dst, src;
-                       color = TERM_WHITE;
-                       if (buf[pos] == '\0') break;
-
-                       src = pos + 1;
-#ifdef JP
-                       if (iskanji(buf[pos])) src++;
-#endif
-                       dst = pos;
-                       while ('\0' != (buf[dst++] = buf[src++]));
-
-                       break;
-               }
-
-               default:
-               {
-                       char tmp[100];
-                       char c;
-                       if (skey & SKEY_MASK) break;
-
-                       c = (char)skey;
-                       if (color != TERM_WHITE)
-                       {
-                               if (color == TERM_L_GREEN)
-                               {
-                                       *o_handle = NULL;
-                                       string_free(*search_strp);
-                                       *search_strp = NULL;
-                               }
-
-                               buf[0] = '\0';
-                               color = TERM_WHITE;
-                       }
-
-                       strcpy(tmp, buf + pos);
-#ifdef JP
-                       if (iskanji(c))
-                       {
-                               char next;
-                               inkey_base = TRUE;
-                               next = inkey();
-
-                               if (pos + 1 < len)
-                               {
-                                       buf[pos++] = c;
-                                       buf[pos++] = next;
-                               }
-                               else
-                               {
-                                       bell();
-                               }
-                       }
-                       else
-#endif
-                       {
-#ifdef JP
-                               if (pos < len && (isprint(c) || iskana(c)))
-#else
-                               if (pos < len && isprint(c))
-#endif
-                               {
-                                       buf[pos++] = c;
-                               }
-                               else
-                               {
-                                       bell();
-                               }
-                       }
-
-                       buf[pos] = '\0';
-                       my_strcat(buf, tmp, len + 1);
-
-                       break;
-               }
-               }
-
-               if (*o_handle == NULL || color == TERM_L_GREEN) continue;
-
-               *o_handle = NULL;
-               buf[0] = '\0';
-               string_free(*search_strp);
-               *search_strp = NULL;
-       }
-}
-
-
-/*
- * Search next line matches for o_ptr
- */
-static void search_for_object(player_type *player_ptr, text_body_type *tb, object_type *o_ptr, bool forward)
-{
-       autopick_type an_entry, *entry = &an_entry;
-       GAME_TEXT o_name[MAX_NLEN];
-       int bypassed_cy = -1;
-       int i = tb->cy;
-       object_desc(player_ptr, o_name, o_ptr, (OD_NO_FLAVOR | OD_OMIT_PREFIX | OD_NO_PLURAL));
-       str_tolower(o_name);
-
-       while (TRUE)
-       {
-               bool match;
-               if (forward)
-               {
-                       if (!tb->lines_list[++i]) break;
-               }
-               else
-               {
-                       if (--i < 0) break;
-               }
-
-               if (!autopick_new_entry(entry, tb->lines_list[i], FALSE)) continue;
-
-               match = is_autopick_match(player_ptr, o_ptr, entry, o_name);
-               autopick_free_entry(entry);
-               if (!match)     continue;
-
-               if (tb->states[i] & LSTAT_BYPASS)
-               {
-                       if (bypassed_cy == -1) bypassed_cy = i;
-                       continue;
-               }
-
-               tb->cx = 0;
-               tb->cy = i;
-               if (bypassed_cy != -1)
-               {
-                       tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
-               }
-
-               return;
-       }
-
-       if (bypassed_cy == -1)
-       {
-               tb->dirty_flags |= DIRTY_NOT_FOUND;
-               return;
-       }
-
-       tb->cx = 0;
-       tb->cy = bypassed_cy;
-       tb->dirty_flags |= DIRTY_INACTIVE;
-}
-
-
-/*
- * Search next line matches to the string
- */
-static void search_for_string(text_body_type *tb, concptr search_str, bool forward)
-{
-       int bypassed_cy = -1;
-       int bypassed_cx = 0;
-
-       int i = tb->cy;
-       while (TRUE)
-       {
-               concptr pos;
-               if (forward)
-               {
-                       if (!tb->lines_list[++i]) break;
-               }
-               else
-               {
-                       if (--i < 0) break;
-               }
-
-               pos = my_strstr(tb->lines_list[i], search_str);
-               if (!pos) continue;
-
-               if ((tb->states[i] & LSTAT_BYPASS) &&
-                       !(tb->states[i] & LSTAT_EXPRESSION))
-               {
-                       if (bypassed_cy == -1)
-                       {
-                               bypassed_cy = i;
-                               bypassed_cx = (int)(pos - tb->lines_list[i]);
-                       }
-
-                       continue;
-               }
-
-               tb->cx = (int)(pos - tb->lines_list[i]);
-               tb->cy = i;
-
-               if (bypassed_cy != -1)
-               {
-                       tb->dirty_flags |= DIRTY_SKIP_INACTIVE;
-               }
-
-               return;
-       }
-
-       if (bypassed_cy == -1)
-       {
-               tb->dirty_flags |= DIRTY_NOT_FOUND;
-               return;
-       }
-
-       tb->cx = bypassed_cx;
-       tb->cy = bypassed_cy;
-       tb->dirty_flags |= DIRTY_INACTIVE;
-}
-
-
-/*
  * Display the menu, and get a command
  */
 static int do_command_menu(int level, int start)