aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core-commands.c7
-rw-r--r--src/qreg.c29
2 files changed, 28 insertions, 8 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index ba7aaa8..fa2f8b5 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -1741,7 +1741,7 @@ teco_state_control_decimal(teco_machine_main_t *ctx, GError **error)
* radix^R -- Set and get radix
* ^R -> radix
*
- * Set current radix to arbitrary value <radix>.
+ * Set current radix to any value <radix> larger than or equal to 2.
* If <radix> is omitted, the command instead
* returns the current radix.
*
@@ -1764,11 +1764,6 @@ teco_state_control_radix(teco_machine_main_t *ctx, GError **error)
return;
teco_expressions_push(radix);
} else {
- /*
- * FIXME: We should restrict the allowed values.
- * 0^R 23\ crashes for instance.
- * The ^R register should consequently also be "special".
- */
if (!teco_expressions_pop_num_calc(&radix, 0, error) ||
!qreg->vtable->undo_set_integer(qreg, error) ||
!qreg->vtable->set_integer(qreg, radix, error))
diff --git a/src/qreg.c b/src/qreg.c
index 2c5d4a5..1ce727f 100644
--- a/src/qreg.c
+++ b/src/qreg.c
@@ -399,6 +399,32 @@ teco_qreg_plain_new(const gchar *name, gsize len)
}
static gboolean
+teco_qreg_radix_set_integer(teco_qreg_t *qreg, teco_int_t value, GError **error)
+{
+ if (value < 2) {
+ g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
+ "Invalid radix");
+ return FALSE;
+ }
+
+ qreg->integer = value;
+ return TRUE;
+}
+
+/** @static @memberof teco_qreg_t */
+static teco_qreg_t *
+teco_qreg_radix_new(void)
+{
+ static teco_qreg_vtable_t vtable = TECO_INIT_QREG(
+ .set_integer = teco_qreg_radix_set_integer
+ );
+
+ teco_qreg_t *qreg = teco_qreg_new(&vtable, "\x12", 1); /* ^R */
+ qreg->integer = 10;
+ return qreg;
+}
+
+static gboolean
teco_qreg_external_edit(teco_qreg_t *qreg, GError **error)
{
g_auto(teco_string_t) str = {NULL, 0};
@@ -913,8 +939,7 @@ teco_qreg_table_init_locals(teco_qreg_table_t *table, gboolean must_undo)
/* search mode ("^X") */
teco_qreg_table_insert(table, teco_qreg_plain_new("\x18", 1));
/* numeric radix ("^R") */
- table->radix = teco_qreg_plain_new("\x12", 1);
- table->radix->vtable->set_integer(table->radix, 10, NULL);
+ table->radix = teco_qreg_radix_new();
teco_qreg_table_insert(table, table->radix);
}