1 #include "system/angband.h"
2 #include "autopick/autopick-util.h"
3 #include "autopick/autopick-inserter-killer.h"
4 #include "autopick/autopick-dirty-flags.h"
5 #include "game-option/input-options.h"
8 * Check if this line is expression or not.
9 * And update it if it is.
11 void check_expression_line(text_body_type *tb, int y)
13 concptr s = tb->lines_list[y];
15 if ((s[0] == '?' && s[1] == ':') ||
16 (tb->states[y] & LSTAT_BYPASS))
18 tb->dirty_flags |= DIRTY_EXPRESSION;
23 * Insert return code and split the line
25 bool insert_return_code(text_body_type *tb)
27 char buf[MAX_LINELEN];
30 for (num_lines = 0; tb->lines_list[num_lines]; num_lines++);
32 if (num_lines >= MAX_LINES - 2) return FALSE;
35 for (; tb->cy < num_lines; num_lines--)
37 tb->lines_list[num_lines + 1] = tb->lines_list[num_lines];
38 tb->states[num_lines + 1] = tb->states[num_lines];
41 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
44 if (iskanji(tb->lines_list[tb->cy][i]))
45 buf[j++] = tb->lines_list[tb->cy][i++];
47 buf[j++] = tb->lines_list[tb->cy][i];
51 tb->lines_list[tb->cy + 1] = string_make(&tb->lines_list[tb->cy][i]);
52 string_free(tb->lines_list[tb->cy]);
53 tb->lines_list[tb->cy] = string_make(buf);
54 tb->dirty_flags |= DIRTY_EXPRESSION;
61 * Get a trigger key and insert ASCII string for the trigger
63 bool insert_macro_line(text_body_type *tb)
82 ascii_to_text(tmp, buf);
83 if (!tmp[0]) return FALSE;
86 insert_return_code(tb);
87 string_free(tb->lines_list[tb->cy]);
88 tb->lines_list[tb->cy] = string_make(format("P:%s", tmp));
90 i = macro_find_exact(buf);
97 ascii_to_text(tmp, macro__act[i]);
100 insert_return_code(tb);
101 string_free(tb->lines_list[tb->cy]);
102 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
109 * Get a command key and insert ASCII string for the key
111 bool insert_keymap_line(text_body_type *tb)
114 if (rogue_like_commands)
116 mode = KEYMAP_MODE_ROGUE;
120 mode = KEYMAP_MODE_ORIG;
130 ascii_to_text(tmp, buf);
131 if (!tmp[0]) return FALSE;
134 insert_return_code(tb);
135 string_free(tb->lines_list[tb->cy]);
136 tb->lines_list[tb->cy] = string_make(format("C:%d:%s", mode, tmp));
138 concptr act = keymap_act[mode][(byte)(buf[0])];
141 ascii_to_text(tmp, act);
144 insert_return_code(tb);
145 string_free(tb->lines_list[tb->cy]);
146 tb->lines_list[tb->cy] = string_make(format("A:%s", tmp));
153 * Insert single letter at cursor position.
155 void insert_single_letter(text_body_type *tb, int key)
158 char buf[MAX_LINELEN];
160 for (i = j = 0; tb->lines_list[tb->cy][i] && i < tb->cx; i++)
162 buf[j++] = tb->lines_list[tb->cy][i];
172 if (j + 2 < MAX_LINELEN)
174 buf[j++] = (char)key;
175 buf[j++] = (char)next;
184 if (j + 1 < MAX_LINELEN)
185 buf[j++] = (char)key;
189 for (; tb->lines_list[tb->cy][i] && j + 1 < MAX_LINELEN; i++)
190 buf[j++] = tb->lines_list[tb->cy][i];
193 string_free(tb->lines_list[tb->cy]);
194 tb->lines_list[tb->cy] = string_make(buf);
195 len = strlen(tb->lines_list[tb->cy]);
196 if (len < tb->cx) tb->cx = len;
198 tb->dirty_line = tb->cy;
199 check_expression_line(tb, tb->cy);
205 * Kill segment of a line
207 void kill_line_segment(text_body_type *tb, int y, int x0, int x1, bool whole)
209 concptr s = tb->lines_list[y];
210 if (whole && x0 == 0 && s[x1] == '\0' && tb->lines_list[y + 1])
212 string_free(tb->lines_list[y]);
215 for (i = y; tb->lines_list[i + 1]; i++)
216 tb->lines_list[i] = tb->lines_list[i + 1];
217 tb->lines_list[i] = NULL;
219 tb->dirty_flags |= DIRTY_EXPRESSION;
224 if (x0 == x1) return;
226 char buf[MAX_LINELEN];
228 for (int x = 0; x < x0; x++)
231 for (int x = x1; s[x]; x++)
235 string_free(tb->lines_list[y]);
236 tb->lines_list[y] = string_make(buf);
237 check_expression_line(tb, y);