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/core-commands.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/core-commands.c') diff --git a/src/core-commands.c b/src/core-commands.c index 8f84224..d01cbb9 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -461,10 +461,8 @@ teco_state_start_break(teco_machine_main_t *ctx, GError **error) return; } - teco_qreg_t *reg = teco_qreg_table_find(&teco_qreg_table_globals, "_", 1); - g_assert(reg != NULL); teco_int_t v; - if (!reg->vtable->get_integer(reg, &v, error)) + if (!teco_qreg_table_get_integer(&teco_qreg_table_globals, "_", &v, error)) return; teco_bool_t rc; @@ -1134,10 +1132,9 @@ teco_state_changedir_done(teco_machine_main_t *ctx, teco_string_t str, GError ** g_autofree gchar *dir = teco_file_expand_path(str.data); if (!*dir) { - teco_qreg_t *qreg = teco_qreg_table_find(&teco_qreg_table_globals, "$HOME", 5); - g_assert(qreg != NULL); teco_string_t home; - if (!qreg->vtable->get_string(qreg, &home.data, &home.len, NULL, error)) + if (!teco_qreg_table_get_string(&teco_qreg_table_globals, "$HOME", + &home.data, &home.len, error)) return NULL; /* -- cgit v1.2.3