diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-28 01:35:42 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-28 01:35:42 +0300 |
commit | afc50684cdb38815573fdff0f4fff47cc4eb00a8 (patch) | |
tree | 9a7adf6bf02f69218f144de7ddbc9c682fab06e2 | |
parent | dfa4394c1df45755de955260b1d7412c673a7ca0 (diff) | |
download | sciteco-afc50684cdb38815573fdff0f4fff47cc4eb00a8.tar.gz |
=/==/===: fixed detection of execution from the end of the command-line
In particular, fixes the test case `3<255=>` which would print
only one number in interactive mode.
-rw-r--r-- | src/cmdline.h | 8 | ||||
-rw-r--r-- | src/stdio-commands.c | 35 | ||||
-rw-r--r-- | tests/testsuite.at | 2 |
3 files changed, 31 insertions, 14 deletions
diff --git a/src/cmdline.h b/src/cmdline.h index be97c74..ebdf1e1 100644 --- a/src/cmdline.h +++ b/src/cmdline.h @@ -84,14 +84,6 @@ teco_cmdline_keymacro_c(gchar key, GError **error) return TRUE; } -/** Check whether we are executing directly from the end of the command line. */ -static inline gboolean -teco_cmdline_is_executing(teco_machine_main_t *ctx) -{ - return G_UNLIKELY(ctx == &teco_cmdline.machine && - ctx->macro_pc == teco_cmdline.effective_len); -} - extern gboolean teco_quit_requested; /* diff --git a/src/stdio-commands.c b/src/stdio-commands.c index 1a64db9..2d5da62 100644 --- a/src/stdio-commands.c +++ b/src/stdio-commands.c @@ -31,6 +31,19 @@ #include "stdio-commands.h" /** + * Check whether we are executing directly from the end of the command line. + * This works \b only when invoked from the initial_cb. + */ +static inline gboolean +teco_cmdline_is_executing(teco_machine_main_t *ctx) +{ + return ctx == &teco_cmdline.machine && + ctx->macro_pc == teco_cmdline.effective_len; +} + +static gboolean is_executing = FALSE; + +/** * Print number from stack in the given radix. * * It must be popped manually, so we can call it multiple times @@ -110,7 +123,10 @@ TECO_DECLARE_STATE(teco_state_print_octal); static gboolean teco_state_print_decimal_initial(teco_machine_main_t *ctx, GError **error) { - if (ctx->flags.mode > TECO_MODE_NORMAL || !teco_cmdline_is_executing(ctx)) + if (ctx->flags.mode > TECO_MODE_NORMAL) + return TRUE; + is_executing = teco_cmdline_is_executing(ctx); + if (G_LIKELY(!is_executing)) return TRUE; /* * Interactive invocation: @@ -126,7 +142,7 @@ teco_state_print_decimal_input(teco_machine_main_t *ctx, gunichar chr, GError ** return &teco_state_print_octal; if (ctx->flags.mode == TECO_MODE_NORMAL) { - if (!teco_cmdline_is_executing(ctx) && !teco_print(ctx, 10, error)) + if (G_LIKELY(!is_executing) && !teco_print(ctx, 10, error)) return NULL; teco_expressions_pop_num(0); } @@ -140,7 +156,9 @@ teco_state_print_decimal_input(teco_machine_main_t *ctx, gunichar chr, GError ** static gboolean teco_state_print_decimal_end_of_macro(teco_machine_main_t *ctx, GError **error) { - if (teco_cmdline_is_executing(ctx) || ctx->flags.mode > TECO_MODE_NORMAL) + if (ctx->flags.mode > TECO_MODE_NORMAL) + return TRUE; + if (G_UNLIKELY(is_executing)) return TRUE; if (!teco_print(ctx, 10, error)) return FALSE; @@ -157,7 +175,10 @@ TECO_DEFINE_STATE_START(teco_state_print_decimal, static gboolean teco_state_print_octal_initial(teco_machine_main_t *ctx, GError **error) { - if (ctx->flags.mode > TECO_MODE_NORMAL || !teco_cmdline_is_executing(ctx)) + if (ctx->flags.mode > TECO_MODE_NORMAL) + return TRUE; + is_executing = teco_cmdline_is_executing(ctx); + if (G_LIKELY(!is_executing)) return TRUE; /* * Interactive invocation: @@ -179,7 +200,7 @@ teco_state_print_octal_input(teco_machine_main_t *ctx, gunichar chr, GError **er } if (ctx->flags.mode == TECO_MODE_NORMAL) { - if (!teco_cmdline_is_executing(ctx) && !teco_print(ctx, 8, error)) + if (G_LIKELY(!is_executing) && !teco_print(ctx, 8, error)) return NULL; teco_expressions_pop_num(0); } @@ -193,7 +214,9 @@ teco_state_print_octal_input(teco_machine_main_t *ctx, gunichar chr, GError **er static gboolean teco_state_print_octal_end_of_macro(teco_machine_main_t *ctx, GError **error) { - if (teco_cmdline_is_executing(ctx) || ctx->flags.mode > TECO_MODE_NORMAL) + if (ctx->flags.mode > TECO_MODE_NORMAL) + return TRUE; + if (G_UNLIKELY(is_executing)) return TRUE; if (!teco_print(ctx, 8, error)) return FALSE; diff --git a/tests/testsuite.at b/tests/testsuite.at index b8a7404..9f84a23 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -185,6 +185,8 @@ AT_FAIL_IF([test `wc -l <stdout` -ne 1], 0, ignore, ignore) # Will print a decimal, octal and 2 hexadecimal numbers. TE_CHECK_CMDLINE([[2<255===>]], 0, stdout, ignore) AT_FAIL_IF([test `$GREP -v "^Info:" stdout | wc -l` -ne 4], 0, ignore, ignore) +TE_CHECK_CMDLINE([[3<255=>]], 0, stdout, ignore) +AT_FAIL_IF([test `$GREP -v "^Info:" stdout | wc -l` -ne 3], 0, ignore, ignore) AT_CLEANUP AT_SETUP([Printing strings]) |