aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/qreg-commands.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-07-18 01:41:28 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-07-18 01:41:28 +0300
commit5d4368584ecd447b953e8853dbeaee4282700970 (patch)
tree290d9034f542e615155fb514cb23f15620474f2d /src/qreg-commands.c
parent45b9dea901cec7045be1a98f61d48d41dc965a9f (diff)
downloadsciteco-5d4368584ecd447b953e8853dbeaee4282700970.tar.gz
support <:]q> (pop Q-Register) for getting a success/failure boolean
* Could be used to check whether the stack is currently empty, although peeking would be cumbersome: `:]q"S [q !...! | !...! '` * This is from DEC TECO-11.
Diffstat (limited to 'src/qreg-commands.c')
-rw-r--r--src/qreg-commands.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/qreg-commands.c b/src/qreg-commands.c
index 9407e6c..1d2766f 100644
--- a/src/qreg-commands.c
+++ b/src/qreg-commands.c
@@ -99,18 +99,29 @@ teco_state_popqreg_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg,
{
teco_state_expectqreg_reset(ctx);
- return ctx->flags.mode == TECO_MODE_NORMAL &&
- !teco_qreg_stack_pop(qreg, error) ? NULL : &teco_state_start;
+ if (ctx->flags.mode > TECO_MODE_NORMAL)
+ return &teco_state_start;
+
+ if (!teco_machine_main_eval_colon(ctx))
+ return !teco_qreg_stack_pop(qreg, error) ? NULL : &teco_state_start;
+ teco_expressions_push(teco_bool(teco_qreg_stack_pop(qreg, NULL)));
+ return &teco_state_start;
}
-/*$ "]" "]q" pop
+/*$ "]" "]q" ":]q" pop
* ]q -- Restore Q-Register
+ * :]q -> Success|Failure
*
* Restore Q-Register <q> by replacing its contents
* with the contents of the register saved on top of
* the Q-Register push-down stack.
* The stack entry is popped.
*
+ * When colon-modified, \fB]\fP returns a success boolean
+ * (-1) if there was a register to pop.
+ * If the stack was empty, a failure boolean (0) is returned
+ * instead of throwing an error.
+ *
* In interactive mode, the original contents of <q>
* are not immediately reclaimed but are kept in memory
* to support rubbing out the command.