diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-26 16:30:17 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2025-07-26 16:48:56 +0300 |
commit | 0ea082b74414696a7800455a437656fca2886f6d (patch) | |
tree | 63d4809b97c9cbdeb2a2063025fd349af4cd5043 /src/spawn.c | |
parent | eb6f7a82045ad78553fca98c54a51366c55bd7a4 (diff) | |
download | sciteco-0ea082b74414696a7800455a437656fca2886f6d.tar.gz |
properly document some functions in expressions.c and simplified code
* Practically all calls to teco_expressions_args() must be preceded by teco_expressions_eval().
* In code paths where we know that teco_expressions_args() > 0, it is safe
to call teco_expressions_pop_num(0) instead of teco_expressions_pop_num_calc().
This is both easier and faster.
* teco_expressions_pop_num_calc() is for simple applications where you just want to get
a command argument with default (implied) values.
Since it includes teco_expressions_eval(), we can avoid superfluous calls.
* -EC...$ turned out to be broken and is fixed now.
A test case has been added.
Diffstat (limited to 'src/spawn.c')
-rw-r--r-- | src/spawn.c | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/spawn.c b/src/spawn.c index abcce75..73f389e 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -204,7 +204,7 @@ teco_state_execute_initial(teco_machine_main_t *ctx, GError **error) teco_int_t line; teco_spawn_ctx.from = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); - if (!teco_expressions_pop_num_calc(&line, 0, error)) + if (!teco_expressions_pop_num_calc(&line, teco_num_sign, error)) return FALSE; line += teco_interface_ssm(SCI_LINEFROMPOSITION, teco_spawn_ctx.from, 0); teco_spawn_ctx.to = teco_interface_ssm(SCI_POSITIONFROMLINE, line, 0); @@ -219,18 +219,13 @@ teco_state_execute_initial(teco_machine_main_t *ctx, GError **error) break; } - default: { + default: /* pipe and replace character range */ - teco_int_t from, to; - if (!teco_expressions_pop_num_calc(&to, 0, error) || - !teco_expressions_pop_num_calc(&from, 0, error)) - return FALSE; - teco_spawn_ctx.from = teco_interface_glyphs2bytes(from); - teco_spawn_ctx.to = teco_interface_glyphs2bytes(to); + teco_spawn_ctx.to = teco_interface_glyphs2bytes(teco_expressions_pop_num(0)); + teco_spawn_ctx.from = teco_interface_glyphs2bytes(teco_expressions_pop_num(0)); rc = teco_bool(teco_spawn_ctx.from <= teco_spawn_ctx.to && teco_spawn_ctx.from >= 0 && teco_spawn_ctx.to >= 0); } - } if (teco_is_failure(rc)) { if (!teco_machine_main_eval_colon(ctx)) { |