aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/interface-curses/interface.c
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-08-23 00:28:23 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-08-23 00:28:23 +0200
commit32122651bdb51006edce2be3586dd09179bed52f (patch)
tree6fa0bb17ec74693e25eebe8e05a9e04828c3c446 /src/interface-curses/interface.c
parent2e097cec409182c3cb39b74489387480bf8a278f (diff)
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.
Diffstat (limited to 'src/interface-curses/interface.c')
-rw-r--r--src/interface-curses/interface.c26
1 files changed, 8 insertions, 18 deletions
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;