From 32122651bdb51006edce2be3586dd09179bed52f Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 23 Aug 2026 00:28:23 +0200 Subject: introduced helper functions teco_qreg_table_get_string() and teco_qreg_table_get_integer() * Simplifies the common task of querying an integer or string from a Q-Register table. * Undefined Q-Regs are reported as TECO_ERROR_QREGUNDEF, so you can theoretically handle this case. In practice however, it requires less boilerplating to just call teco_qreg_table_find() manually. * It also doesn't make sense to use these functions when getting and setting a register at the same time as you will want to avoid repeated lookups. --- src/interface-curses/interface.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/interface-curses/interface.c') diff --git a/src/interface-curses/interface.c b/src/interface-curses/interface.c index db996f5..fbac2cb 100644 --- a/src/interface-curses/interface.c +++ b/src/interface-curses/interface.c @@ -1527,17 +1527,12 @@ teco_interface_set_clipboard(const gchar *name, const gchar *str, gsize str_len, static const gchar reg_name[] = "$SCITECO_CLIPBOARD_SET"; - teco_qreg_t *reg = teco_qreg_table_find(&teco_qreg_table_globals, reg_name, strlen(reg_name)); - if (!reg) { - /* Q-Register could have been removed in the meantime */ - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Cannot set clipboard. %s is undefined.", reg_name); - return FALSE; - } - g_auto(teco_string_t) command = {NULL, 0}; - if (!reg->vtable->get_string(reg, &command.data, &command.len, NULL, error)) + if (!teco_qreg_table_get_string(&teco_qreg_table_globals, reg_name, + &command.data, &command.len, error)) { + g_prefix_error(error, "Cannot set clipboard: "); return FALSE; + } if (teco_string_contains(command, '\0')) { teco_error_qregcontainsnull_set(error, reg_name, strlen(reg_name), FALSE); return FALSE; @@ -1588,17 +1583,12 @@ teco_interface_get_clipboard(const gchar *name, gchar **str, gsize *len, GError static const gchar reg_name[] = "$SCITECO_CLIPBOARD_GET"; - teco_qreg_t *reg = teco_qreg_table_find(&teco_qreg_table_globals, reg_name, strlen(reg_name)); - if (!reg) { - /* Q-Register could have been removed in the meantime */ - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Cannot get clipboard. %s is undefined.", reg_name); - return FALSE; - } - g_auto(teco_string_t) command = {NULL, 0}; - if (!reg->vtable->get_string(reg, &command.data, &command.len, NULL, error)) + if (!teco_qreg_table_get_string(&teco_qreg_table_globals, reg_name, + &command.data, &command.len, error)) { + g_prefix_error(error, "Cannot get clipboard: "); return FALSE; + } if (teco_string_contains(command, '\0')) { teco_error_qregcontainsnull_set(error, reg_name, strlen(reg_name), FALSE); return FALSE; -- cgit v1.2.3