OSDN Git Service

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

index e6ba72a..4162bf4 100644 (file)
     <ClCompile Include="..\..\src\autopick\autopick-entry.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-finder.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-initializer.c" />\r
+    <ClCompile Include="..\..\src\autopick\autopick-inserter.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-matcher.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-menu-data-table.c" />\r
     <ClCompile Include="..\..\src\autopick\autopick-pref-processor.c" />\r
     <ClInclude Include="..\..\src\autopick\autopick-finder.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-flags-table.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-initializer.h" />\r
+    <ClInclude Include="..\..\src\autopick\autopick-inserter.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-key-flag-process.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-keys-table.h" />\r
     <ClInclude Include="..\..\src\autopick\autopick-matcher.h" />\r
index 6a0cf14..dbede43 100644 (file)
     <ClCompile Include="..\..\src\autopick\autopick-searcher.c">
       <Filter>autopick</Filter>
     </ClCompile>
+    <ClCompile Include="..\..\src\autopick\autopick-inserter.c">
+      <Filter>autopick</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\src\gamevalue.h" />
     <ClInclude Include="..\..\src\autopick\autopick-searcher.h">
       <Filter>autopick</Filter>
     </ClInclude>
+    <ClInclude Include="..\..\src\autopick\autopick-inserter.h">
+      <Filter>autopick</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\wall.bmp" />
index 181c50d..a21274b 100644 (file)
@@ -27,6 +27,7 @@ hengband_SOURCES = \
        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 \
+       autopick/autopick-inserter.c autopick/autopick-inserter.h \
        \
        avatar.h avatar.c birth.c birth.h \
        \
diff --git a/src/autopick/autopick-inserter.c b/src/autopick/autopick-inserter.c
new file mode 100644 (file)
index 0000000..3d7b061
--- /dev/null
@@ -0,0 +1,200 @@
+#include "angband.h"
+#include "autopick/autopick-util.h"
+#include "autopick/autopick-inserter.h"
+#include "autopick/autopick-dirty-flags.h"
+
+/*
+ * Check if this line is expression or not.
+ * And update it if it is.
+ */
+void check_expression_line(text_body_type *tb, int y)
+{
+       concptr s = tb->lines_list[y];
+
+       if ((s[0] == '?' && s[1] == ':') ||
+               (tb->states[y] & LSTAT_BYPASS))
+       {
+               tb->dirty_flags |= DIRTY_EXPRESSION;
+       }
+}
+
+/*
+ * Insert return code and split the line
+ */
+bool insert_return_code(text_body_type *tb)
+{
+       char buf[MAX_LINELEN];
+       int i, j, num_lines;
+
+       for (num_lines = 0; tb->lines_list[num_lines]; num_lines++);
+
+       if (num_lines >= MAX_LINES - 2) return FALSE;
+       num_lines--;
+
+       for (; tb->cy < num_lines; num_lines--)
+       {
+               tb->lines_list[num_lines + 1] = tb->lines_list[num_lines];
+               tb->states[num_lines + 1] = tb->states[num_lines];
+       }
+
+       for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
+       {
+#ifdef JP
+               if (iskanji(tb->lines_list[tb->cy][i]))
+                       buf[j++] = tb->lines_list[tb->cy][i++];
+#endif
+               buf[j++] = tb->lines_list[tb->cy][i];
+       }
+
+       buf[j] = '\0';
+       tb->lines_list[tb->cy + 1] = string_make(&tb->lines_list[tb->cy][i]);
+       string_free(tb->lines_list[tb->cy]);
+       tb->lines_list[tb->cy] = string_make(buf);
+       tb->dirty_flags |= DIRTY_EXPRESSION;
+       tb->changed = TRUE;
+       return TRUE;
+}
+
+
+/*
+ * Get a trigger key and insert ASCII string for the trigger
+ */
+bool insert_macro_line(text_body_type *tb)
+{
+       int i, n = 0;
+       flush();
+       inkey_base = TRUE;
+       i = inkey();
+       char buf[1024];
+       while (i)
+       {
+               buf[n++] = (char)i;
+               inkey_base = TRUE;
+               inkey_scan = TRUE;
+               i = inkey();
+       }
+
+       buf[n] = '\0';
+       flush();
+
+       char tmp[1024];
+       ascii_to_text(tmp, buf);
+       if (!tmp[0]) return FALSE;
+
+       tb->cx = 0;
+       insert_return_code(tb);
+       string_free(tb->lines_list[tb->cy]);
+       tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
+
+       i = macro_find_exact(buf);
+       if (i == -1)
+       {
+               tmp[0] = '\0';
+       }
+       else
+       {
+               ascii_to_text(tmp, macro__act[i]);
+       }
+
+       insert_return_code(tb);
+       string_free(tb->lines_list[tb->cy]);
+       tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
+
+       return TRUE;
+}
+
+
+/*
+ * Get a command key and insert ASCII string for the key
+ */
+bool insert_keymap_line(text_body_type *tb)
+{
+       BIT_FLAGS mode;
+       if (rogue_like_commands)
+       {
+               mode = KEYMAP_MODE_ROGUE;
+       }
+       else
+       {
+               mode = KEYMAP_MODE_ORIG;
+       }
+
+       flush();
+       char buf[2];
+       buf[0] = inkey();
+       buf[1] = '\0';
+
+       flush();
+       char tmp[1024];
+       ascii_to_text(tmp, buf);
+       if (!tmp[0]) return FALSE;
+
+       tb->cx = 0;
+       insert_return_code(tb);
+       string_free(tb->lines_list[tb->cy]);
+       tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
+
+       concptr act = keymap_act[mode][(byte)(buf[0])];
+       if (act)
+       {
+               ascii_to_text(tmp, act);
+       }
+
+       insert_return_code(tb);
+       string_free(tb->lines_list[tb->cy]);
+       tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
+
+       return TRUE;
+}
+
+
+/*
+ * Insert single letter at cursor position.
+ */
+void insert_single_letter(text_body_type *tb, int key)
+{
+       int i, j, len;
+       char buf[MAX_LINELEN];
+
+       for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
+       {
+               buf[j++] = tb->lines_list[tb->cy][i];
+       }
+
+#ifdef JP
+       if (iskanji(key))
+       {
+               int next;
+
+               inkey_base = TRUE;
+               next = inkey();
+               if (j + 2 < MAX_LINELEN)
+               {
+                       buf[j++] = (char)key;
+                       buf[j++] = (char)next;
+                       tb->cx += 2;
+               }
+               else
+                       bell();
+       }
+       else
+#endif
+       {
+               if (j + 1 < MAX_LINELEN)
+                       buf[j++] = (char)key;
+               tb->cx++;
+       }
+
+       for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
+               buf[j++] = tb->lines_list[tb->cy][i];
+       buf[j] = '\0';
+
+       string_free(tb->lines_list[tb->cy]);
+       tb->lines_list[tb->cy] = string_make(buf);
+       len = strlen(tb->lines_list[tb->cy]);
+       if (len < tb->cx) tb->cx = len;
+
+       tb->dirty_line = tb->cy;
+       check_expression_line(tb, tb->cy);
+       tb->changed = TRUE;
+}
diff --git a/src/autopick/autopick-inserter.h b/src/autopick/autopick-inserter.h
new file mode 100644 (file)
index 0000000..005464c
--- /dev/null
@@ -0,0 +1,7 @@
+#pragma once
+
+void check_expression_line(text_body_type *tb, int y);
+bool insert_return_code(text_body_type *tb);
+bool insert_macro_line(text_body_type *tb);
+bool insert_keymap_line(text_body_type *tb);
+void insert_single_letter(text_body_type *tb, int key);
index ec7f8e0..0c74793 100644 (file)
@@ -31,6 +31,7 @@
 #include "autopick/autopick-pref-processor.h"
 #include "autopick/autopick-drawer.h"
 #include "autopick/autopick-searcher.h"
+#include "autopick/autopick-inserter.h"
 #include "gameterm.h"
 #include "autopick/autopick.h"
 #include "core.h"
@@ -578,22 +579,6 @@ static void add_keyword(text_body_type *tb, BIT_FLAGS flg)
 
 
 /*
- * Check if this line is expression or not.
- * And update it if it is.
- */
-static void check_expression_line(text_body_type *tb, int y)
-{
-       concptr s = tb->lines_list[y];
-
-       if ((s[0] == '?' && s[1] == ':') ||
-               (tb->states[y] & LSTAT_BYPASS))
-       {
-               tb->dirty_flags |= DIRTY_EXPRESSION;
-       }
-}
-
-
-/*
  * Add an empty line at the last of the file
  */
 static bool add_empty_line(text_body_type *tb)
@@ -612,44 +597,6 @@ static bool add_empty_line(text_body_type *tb)
 
 
 /*
- * Insert return code and split the line
- */
-static bool insert_return_code(text_body_type *tb)
-{
-       char buf[MAX_LINELEN];
-       int i, j, num_lines;
-
-       for (num_lines = 0; tb->lines_list[num_lines]; num_lines++);
-
-       if (num_lines >= MAX_LINES - 2) return FALSE;
-       num_lines--;
-
-       for (; tb->cy < num_lines; num_lines--)
-       {
-               tb->lines_list[num_lines + 1] = tb->lines_list[num_lines];
-               tb->states[num_lines + 1] = tb->states[num_lines];
-       }
-
-       for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
-       {
-#ifdef JP
-               if (iskanji(tb->lines_list[tb->cy][i]))
-                       buf[j++] = tb->lines_list[tb->cy][i++];
-#endif
-               buf[j++] = tb->lines_list[tb->cy][i];
-       }
-
-       buf[j] = '\0';
-       tb->lines_list[tb->cy + 1] = string_make(&tb->lines_list[tb->cy][i]);
-       string_free(tb->lines_list[tb->cy]);
-       tb->lines_list[tb->cy] = string_make(buf);
-       tb->dirty_flags |= DIRTY_EXPRESSION;
-       tb->changed = TRUE;
-       return TRUE;
-}
-
-
-/*
  * Display the menu, and get a command
  */
 static int do_command_menu(int level, int start)
@@ -924,98 +871,6 @@ static void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool wh
 
 
 /*
- * Get a trigger key and insert ASCII string for the trigger
- */
-static bool insert_macro_line(text_body_type *tb)
-{
-       int i, n = 0;
-       flush();
-       inkey_base = TRUE;
-       i = inkey();
-       char buf[1024];
-       while (i)
-       {
-               buf[n++] = (char)i;
-               inkey_base = TRUE;
-               inkey_scan = TRUE;
-               i = inkey();
-       }
-
-       buf[n] = '\0';
-       flush();
-
-       char tmp[1024];
-       ascii_to_text(tmp, buf);
-       if (!tmp[0]) return FALSE;
-
-       tb->cx = 0;
-       insert_return_code(tb);
-       string_free(tb->lines_list[tb->cy]);
-       tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
-
-       i = macro_find_exact(buf);
-       if (i == -1)
-       {
-               tmp[0] = '\0';
-       }
-       else
-       {
-               ascii_to_text(tmp, macro__act[i]);
-       }
-
-       insert_return_code(tb);
-       string_free(tb->lines_list[tb->cy]);
-       tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
-
-       return TRUE;
-}
-
-
-/*
- * Get a command key and insert ASCII string for the key
- */
-static bool insert_keymap_line(text_body_type *tb)
-{
-       BIT_FLAGS mode;
-       if (rogue_like_commands)
-       {
-               mode = KEYMAP_MODE_ROGUE;
-       }
-       else
-       {
-               mode = KEYMAP_MODE_ORIG;
-       }
-
-       flush();
-       char buf[2];
-       buf[0] = inkey();
-       buf[1] = '\0';
-
-       flush();
-       char tmp[1024];
-       ascii_to_text(tmp, buf);
-       if (!tmp[0]) return FALSE;
-
-       tb->cx = 0;
-       insert_return_code(tb);
-       string_free(tb->lines_list[tb->cy]);
-       tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
-
-       concptr act = keymap_act[mode][(byte)(buf[0])];
-       if (act)
-       {
-               ascii_to_text(tmp, act);
-       }
-
-       insert_return_code(tb);
-       string_free(tb->lines_list[tb->cy]);
-       tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
-
-       return TRUE;
-}
-
-
-/*
  * Execute a single editor command
  */
 static bool do_editor_command(player_type *player_ptr, text_body_type *tb, int com_id)
@@ -1679,58 +1534,6 @@ static bool do_editor_command(player_type *player_ptr, text_body_type *tb, int c
 
 
 /*
- * Insert single letter at cursor position.
- */
-static void insert_single_letter(text_body_type *tb, int key)
-{
-       int i, j, len;
-       char buf[MAX_LINELEN];
-
-       for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
-       {
-               buf[j++] = tb->lines_list[tb->cy][i];
-       }
-
-#ifdef JP
-       if (iskanji(key))
-       {
-               int next;
-
-               inkey_base = TRUE;
-               next = inkey();
-               if (j + 2 < MAX_LINELEN)
-               {
-                       buf[j++] = (char)key;
-                       buf[j++] = (char)next;
-                       tb->cx += 2;
-               }
-               else
-                       bell();
-       }
-       else
-#endif
-       {
-               if (j + 1 < MAX_LINELEN)
-                       buf[j++] = (char)key;
-               tb->cx++;
-       }
-
-       for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
-               buf[j++] = tb->lines_list[tb->cy][i];
-       buf[j] = '\0';
-
-       string_free(tb->lines_list[tb->cy]);
-       tb->lines_list[tb->cy] = string_make(buf);
-       len = strlen(tb->lines_list[tb->cy]);
-       if (len < tb->cx) tb->cx = len;
-
-       tb->dirty_line = tb->cy;
-       check_expression_line(tb, tb->cy);
-       tb->changed = TRUE;
-}
-
-
-/*
  * Check special key code and get a movement command id
  */
 static int analyze_move_key(text_body_type *tb, int skey)