From 12863ff7c05e4abe601890157b222eaee9737ad5 Mon Sep 17 00:00:00 2001 From: Lars Henriksen Date: Fri, 10 Jan 2020 20:39:19 +0100 Subject: Refactor cut and paste registers Register REG_BLACK_HOLE can neither be copied into nor pasted from and has been removed from the input routine. Register 36 was not used. Signed-off-by: Lars Henriksen Signed-off-by: Lukas Fleischer --- src/calcurse.h | 8 ++++++-- src/keys.c | 2 -- src/ui-day.c | 29 ++++++++++++++++++----------- src/utils.c | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/calcurse.h b/src/calcurse.h index e41bc32..7826f3a 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -161,8 +161,11 @@ #define KEYS_LABELEN 8 /* length of command description */ #define KEYS_CMDS_PER_LINE 6 /* max number of commands per line */ -/* Register definitions. */ -#define REG_BLACK_HOLE 37 +/* + * Register definitions, see ui_day.c. + * Index 0-35 is used for '0'-'9' and 'a'-'z', see keys_get(). + */ +#define REG_BLACK_HOLE 36 /* Size of the hash table the note garbage collector uses. */ #define NOTE_GC_HSIZE 1024 @@ -1115,6 +1118,7 @@ void ui_day_item_delete(unsigned); void ui_day_item_edit(void); void ui_day_item_pipe(void); void ui_day_item_repeat(void); +void ui_day_item_cut(unsigned); void ui_day_item_cut_free(unsigned); void ui_day_item_copy(unsigned); void ui_day_item_paste(unsigned); diff --git a/src/keys.c b/src/keys.c index b48aade..4f346ab 100644 --- a/src/keys.c +++ b/src/keys.c @@ -297,8 +297,6 @@ enum key keys_get(WINDOW *win, int *count, int *reg) *reg = ch - '1' + 1; } else if (ch >= 'a' && ch <= 'z') { *reg = ch - 'a' + 10; - } else if (ch == '_') { - *reg = REG_BLACK_HOLE; } ch = keys_wgetch(win); } diff --git a/src/ui-day.c b/src/ui-day.c index e0e306b..912f700 100644 --- a/src/ui-day.c +++ b/src/ui-day.c @@ -36,7 +36,8 @@ #include "calcurse.h" -struct day_item day_cut[38] = { {0, 0, 0, {NULL}} }; +/* Cut & paste registers. */ +static struct day_item day_cut[REG_BLACK_HOLE + 1]; /* * Set the selected day in the calendar from the selected item in the APP panel. @@ -834,11 +835,7 @@ void ui_day_item_delete(unsigned reg) return; } } - - ui_day_item_cut_free(reg); - p = day_cut_item(listbox_get_sel(&lb_apt)); - day_cut[reg].type = p->type; - day_cut[reg].item = p->item; + ui_day_item_cut(reg); /* Keep the selection on the same day. */ day_set_sel_data(day_get_item(listbox_get_sel(&lb_apt) - 1)); io_set_modified(); @@ -995,11 +992,7 @@ void ui_day_item_repeat(void) /* NOTREACHED */ } day_set_sel_data(&d); - - ui_day_item_cut_free(REG_BLACK_HOLE); - p = day_cut_item(item_nb); - day_cut[REG_BLACK_HOLE].type = p->type; - day_cut[REG_BLACK_HOLE].item = p->item; + ui_day_item_cut(REG_BLACK_HOLE); io_set_modified(); ui_calendar_monthly_view_cache_set_invalid(); @@ -1008,9 +1001,23 @@ cleanup: mem_free(msg_asktype); } +/* Delete an item and save it in a register. */ +void ui_day_item_cut(unsigned reg) +{ + struct day_item *p; + + ui_day_item_cut_free(reg); + + p = day_cut_item(listbox_get_sel(&lb_apt)); + day_cut[reg].type = p->type; + day_cut[reg].item = p->item; +} + /* Free the current cut item, if any. */ void ui_day_item_cut_free(unsigned reg) { + EXIT_IF(reg > REG_BLACK_HOLE, "illegal register"); + if (!day_cut[reg].type) { /* No previously cut item, don't free anything. */ return; diff --git a/src/utils.c b/src/utils.c index a9a9e68..f467efd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -112,7 +112,7 @@ void free_user_data(void) apoint_llist_free(); recur_apoint_llist_free(); recur_event_llist_free(); - for (i = 0; i <= 37; i++) + for (i = 0; i <= REG_BLACK_HOLE; i++) ui_day_item_cut_free(i); todo_free_list(); notify_free_app(); -- cgit v1.2.3-70-g09d2