tb->dirty_flags |= DIRTY_ALL;
}
- insert_return_code(tb);
+ if (!insert_return_code(tb))
+ break;
tb->cy++;
tb->cx = 0;
tb->dirty_flags |= DIRTY_ALL;
buf[i] = '\0';
chain = chain->next;
if (chain || tb->yank_eol) {
- insert_return_code(tb);
+ if (!insert_return_code(tb))
+ break;
string_free(tb->lines_list[tb->cy]);
tb->lines_list[tb->cy] = string_make(buf);
tb->cx = 0;
}
tb->cx = 0;
- insert_return_code(tb);
+ if (!insert_return_code(tb))
+ break;
string_free(tb->lines_list[tb->cy]);
tb->lines_list[tb->cy] = autopick_line_from_entry_kill(entry);
tb->dirty_flags |= DIRTY_SCREEN;
break;
tb->cx = 0;
- insert_return_code(tb);
+ if (!insert_return_code(tb))
+ break;
string_free(tb->lines_list[tb->cy]);
tb->lines_list[tb->cy] = string_make(tb->last_destroyed);
tb->dirty_flags |= DIRTY_ALL;
break;
}
case EC_INSERT_BLOCK: {
+ if (!can_insert_line(tb, 2))
+ break;
char expression[80];
sprintf(expression, "?:[AND [EQU $RACE %s] [EQU $CLASS %s] [GEQ $LEVEL %02d]]",
#ifdef JP
*/
bool add_empty_line(text_body_type *tb)
{
- int num_lines;
- for (num_lines = 0; tb->lines_list[num_lines]; num_lines++)
- ;
+ int num_lines = count_line(tb);
- if (num_lines >= MAX_LINES - 2)
- return FALSE;
if (!tb->lines_list[num_lines - 1][0])
return FALSE;
}
}
+/*!
+ * @brief 行を追加可能かチェックする
+ * @param tb text_body_type
+ * @param add_num 追加する行数
+ * @retval true 追加可能
+ * @retval false 最大行数を超えるため追加不可
+ */
+bool can_insert_line(text_body_type *tb, int add_num)
+{
+ const int count = count_line(tb);
+ return !is_greater_autopick_max_line(count + add_num);
+}
+
/*
* Insert return code and split the line
*/
char buf[MAX_LINELEN];
int i, j, num_lines;
- for (num_lines = 0; tb->lines_list[num_lines]; num_lines++)
- ;
+ num_lines = count_line(tb);
+ if (is_greater_autopick_max_line(num_lines))
+ return false;
- if (num_lines >= MAX_LINES - 2)
- return FALSE;
num_lines--;
for (; tb->cy < num_lines; num_lines--) {
*/
bool insert_macro_line(text_body_type *tb)
{
+ if (!can_insert_line(tb, 2))
+ return false;
int i, n = 0;
flush();
inkey_base = TRUE;
*/
bool insert_keymap_line(text_body_type *tb)
{
+ if (!can_insert_line(tb, 2))
+ return false;
BIT_FLAGS mode;
if (rogue_like_commands) {
mode = KEYMAP_MODE_ROGUE;
typedef struct text_body_type text_body_type;
void check_expression_line(text_body_type *tb, int y);
+bool can_insert_line(text_body_type *tb, int add_num = 1);
bool insert_return_code(text_body_type *tb);
bool insert_macro_line(text_body_type *tb);
bool insert_keymap_line(text_body_type *tb);
C_MAKE(lines_list, MAX_LINES, concptr);
while (angband_fgets(fff, buf, sizeof(buf)) == 0) {
lines_list[lines++] = string_make(buf);
- if (lines >= MAX_LINES - 1)
+ if (is_greater_autopick_max_line(lines))
break;
}
autopick_list[max_autopick] = *entry;
max_autopick++;
}
+
+/*!
+ * @brief 行数をカウントする
+ * @param tb text_body_type
+ * @return 行数
+ */
+int count_line(text_body_type *tb)
+{
+ int num_lines;
+ for (num_lines = 0; tb->lines_list[num_lines]; num_lines++)
+ ;
+
+ return num_lines;
+}
int get_com_id(char key);
void auto_inscribe_item(player_type *player_ptr, object_type *o_ptr, int idx);
void add_autopick_list(autopick_type *entry);
+int count_line(text_body_type *tb);
+
+/*!
+ * @brief 最大行数を超えるかチェックする
+ * @param count 行数
+ * @retval true 最大行数を超える
+ * @retval false 最大行数を超えない
+ */
+inline bool is_greater_autopick_max_line(int count)
+{
+ return (count > MAX_LINES - 3);
+}