aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/expressions.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-11-22 16:59:07 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-11-23 02:33:49 +0300
commit1cfe37610253c20a4fcb0d937c29e70894ecc4f5 (patch)
treeac05844c25fc0918e8fd451d8912fd7f1964acb7 /src/expressions.c
parent07b52f78680858683acb4e40b158f8926285cae4 (diff)
downloadsciteco-1cfe37610253c20a4fcb0d937c29e70894ecc4f5.tar.gz
the search mode and current radix are mapped to __local__ Q-Registers ^X and ^R now (refs #17)
* This way the search mode and radix are local to the current macro frame, unless the macro was invoked with :Mq. If colon-modified, you can reproduce the same effect by calling [.^X 0^X ... ].^X * The radix register is cached in the Q-Reg table as an optimization. This could be done with the other "special" registers as well, but at the cost of larger stack frames. * In order to allow constructs like [.^X typed with upcarets, the Q-Register specification syntax has been extended: ^c is the corresponding control code instead of the register "^".
Diffstat (limited to 'src/expressions.c')
-rw-r--r--src/expressions.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/expressions.c b/src/expressions.c
index ee6b4dc..25213e9 100644
--- a/src/expressions.c
+++ b/src/expressions.c
@@ -23,6 +23,7 @@
#include "sciteco.h"
#include "error.h"
#include "undo.h"
+#include "qreg.h"
#include "expressions.h"
/*
@@ -57,7 +58,6 @@ teco_expressions_precedence(teco_operator_t op)
}
gint teco_num_sign = 1;
-gint teco_radix = 10;
void
teco_expressions_push_int(teco_int_t number)
@@ -114,12 +114,20 @@ teco_expressions_pop_num_calc(teco_int_t *ret, teco_int_t imply, GError **error)
}
void
-teco_expressions_add_digit(gunichar digit)
+teco_expressions_add_digit(gunichar digit, teco_qreg_t *qreg)
{
+ /*
+ * FIXME: We could just access qreg->integer here since
+ * we can assume that "^R" is a plain register.
+ */
+ assert(qreg != NULL);
+ teco_int_t radix = 10;
+ qreg->vtable->get_integer(qreg, &radix, NULL);
+
teco_int_t n = teco_expressions_args() > 0 ? teco_expressions_pop_num(0) : 0;
/* use g_unichar_digit_value()? */
- teco_expressions_push(n*teco_radix + (n < 0 ? -1 : 1)*((gint)digit - '0'));
+ teco_expressions_push(n*radix + (n < 0 ? -1 : 1)*((gint)digit - '0'));
}
void
@@ -378,21 +386,26 @@ teco_expressions_clear(void)
* @param buffer The output buffer of at least TECO_EXPRESSIONS_FORMAT_LEN characters.
* The output string will be null-terminated.
* @param number The number to format.
+ * @param table The local Q-Register table that contains the appropriate radix register (^R).
* @return A pointer into buffer to the beginning of the formatted number.
*/
gchar *
-teco_expressions_format(gchar *buffer, teco_int_t number)
+teco_expressions_format(gchar *buffer, teco_int_t number, teco_qreg_t *qreg)
{
+ assert(qreg != NULL);
+ teco_int_t radix = 10;
+ qreg->vtable->get_integer(qreg, &radix, NULL);
+
gchar *p = buffer + TECO_EXPRESSIONS_FORMAT_LEN;
teco_int_t v = ABS(number);
*--p = '\0';
do {
- *--p = '0' + (v % teco_radix);
+ *--p = '0' + (v % radix);
if (*p > '9')
*p += 'A' - '9' - 1;
- } while ((v /= teco_radix));
+ } while ((v /= radix));
if (number < 0)
*--p = '-';