1 #include "autopick/autopick-editor-util.h"
2 #include "autopick/autopick-flags-table.h"
3 #include "autopick/autopick-methods-table.h"
4 #include "autopick/autopick-dirty-flags.h"
5 #include "autopick/autopick-entry.h"
6 #include "autopick/autopick-key-flag-process.h"
9 * Delete or insert string
11 void toggle_keyword(text_body_type *tb, BIT_FLAGS flg)
18 by1 = MIN(tb->my, tb->cy);
19 by2 = MAX(tb->my, tb->cy);
21 else /* if (!tb->mark) */
26 for (int y = by1; y <= by2; y++)
28 autopick_type an_entry, *entry = &an_entry;
29 if (!autopick_new_entry(entry, tb->lines_list[y], !fixed)) continue;
31 string_free(tb->lines_list[y]);
34 if (!IS_FLG(flg)) add = TRUE;
40 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
43 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
46 else if (FLG_UNAWARE <= flg && flg <= FLG_STAR_IDENTIFIED)
49 for (i = FLG_UNAWARE; i <= FLG_STAR_IDENTIFIED; i++)
52 else if (FLG_ARTIFACT <= flg && flg <= FLG_AVERAGE)
55 for (i = FLG_ARTIFACT; i <= FLG_AVERAGE; i++)
58 else if (FLG_RARE <= flg && flg <= FLG_COMMON)
61 for (i = FLG_RARE; i <= FLG_COMMON; i++)
65 if (add) ADD_FLG(flg);
68 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
69 tb->dirty_flags |= DIRTY_ALL;
76 * Change command letter
78 void toggle_command_letter(text_body_type *tb, byte flg)
80 autopick_type an_entry;
81 autopick_type *entry = &an_entry;
87 by1 = MIN(tb->my, tb->cy);
88 by2 = MAX(tb->my, tb->cy);
90 else /* if (!tb->mark) */
95 for (int y = by1; y <= by2; y++)
99 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
101 string_free(tb->lines_list[y]);
105 if (!(entry->action & flg)) add = TRUE;
111 if (entry->action & DONT_AUTOPICK) wid--;
112 else if (entry->action & DO_AUTODESTROY) wid--;
113 else if (entry->action & DO_QUERY_AUTOPICK) wid--;
114 if (!(entry->action & DO_DISPLAY)) wid--;
116 if (flg != DO_DISPLAY)
118 entry->action &= ~(DO_AUTOPICK | DONT_AUTOPICK | DO_AUTODESTROY | DO_QUERY_AUTOPICK);
119 if (add) entry->action |= flg;
120 else entry->action |= DO_AUTOPICK;
124 entry->action &= ~(DO_DISPLAY);
125 if (add) entry->action |= flg;
130 if (entry->action & DONT_AUTOPICK) wid++;
131 else if (entry->action & DO_AUTODESTROY) wid++;
132 else if (entry->action & DO_QUERY_AUTOPICK) wid++;
133 if (!(entry->action & DO_DISPLAY)) wid++;
135 if (wid > 0) tb->cx++;
136 if (wid < 0 && tb->cx > 0) tb->cx--;
139 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
140 tb->dirty_flags |= DIRTY_ALL;
147 * Delete or insert string
149 void add_keyword(text_body_type *tb, BIT_FLAGS flg)
154 by1 = MIN(tb->my, tb->cy);
155 by2 = MAX(tb->my, tb->cy);
162 for (int y = by1; y <= by2; y++)
164 autopick_type an_entry, *entry = &an_entry;
165 if (!autopick_new_entry(entry, tb->lines_list[y], FALSE)) continue;
169 autopick_free_entry(entry);
173 string_free(tb->lines_list[y]);
174 if (FLG_NOUN_BEGIN <= flg && flg <= FLG_NOUN_END)
177 for (i = FLG_NOUN_BEGIN; i <= FLG_NOUN_END; i++)
182 tb->lines_list[y] = autopick_line_from_entry_kill(entry);
183 tb->dirty_flags |= DIRTY_ALL;
190 * Add an empty line at the last of the file
192 bool add_empty_line(text_body_type *tb)
195 for (num_lines = 0; tb->lines_list[num_lines]; num_lines++);
197 if (num_lines >= MAX_LINES - 2) return FALSE;
198 if (!tb->lines_list[num_lines - 1][0]) return FALSE;
200 tb->lines_list[num_lines] = string_make("");
201 tb->dirty_flags |= DIRTY_EXPRESSION;
207 static chain_str_type *new_chain_str(concptr str)
209 chain_str_type *chain;
210 size_t len = strlen(str);
211 chain = (chain_str_type *)ralloc(sizeof(chain_str_type) + len * sizeof(char));
212 strcpy(chain->s, str);
218 void kill_yank_chain(text_body_type *tb)
220 chain_str_type *chain = tb->yank;
226 chain_str_type *next = chain->next;
227 size_t len = strlen(chain->s);
229 rnfree(chain, sizeof(chain_str_type) + len * sizeof(char));
236 void add_str_to_yank(text_body_type *tb, concptr str)
238 tb->yank_eol = FALSE;
239 if (NULL == tb->yank)
241 tb->yank = new_chain_str(str);
245 chain_str_type *chain;
252 chain->next = new_chain_str(str);
263 * Do work for the copy editor-command
265 void copy_text_to_yank(text_body_type *tb)
267 int len = strlen(tb->lines_list[tb->cy]);
268 if (tb->cx > len) tb->cx = len;
278 if (tb->my != tb->cy)
280 int by1 = MIN(tb->my, tb->cy);
281 int by2 = MAX(tb->my, tb->cy);
283 for (int y = by1; y <= by2; y++)
285 add_str_to_yank(tb, tb->lines_list[y]);
288 add_str_to_yank(tb, "");
290 tb->dirty_flags |= DIRTY_ALL;
294 char buf[MAX_LINELEN];
295 int bx1 = MIN(tb->mx, tb->cx);
296 int bx2 = MAX(tb->mx, tb->cx);
297 if (bx2 > len) bx2 = len;
299 if (bx1 == 0 && bx2 == len)
301 add_str_to_yank(tb, tb->lines_list[tb->cy]);
302 add_str_to_yank(tb, "");
307 for (int i = 0; i < bx2 - bx1; i++)
309 buf[i] = tb->lines_list[tb->cy][bx1 + i];
313 add_str_to_yank(tb, buf);
317 tb->dirty_flags |= DIRTY_ALL;