aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/spawn.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/spawn.c')
-rw-r--r--src/spawn.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/spawn.c b/src/spawn.c
index d51dbb1..61718fd 100644
--- a/src/spawn.c
+++ b/src/spawn.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012-2025 Robin Haberkorn
+ * Copyright (C) 2012-2026 Robin Haberkorn
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -129,7 +129,7 @@ teco_parse_shell_command_line(const gchar *cmdline, GError **error)
teco_string_t comspec;
if (!reg->vtable->get_string(reg, &comspec.data, &comspec.len, NULL, error))
return NULL;
- if (teco_string_contains(&comspec, '\0')) {
+ if (teco_string_contains(comspec, '\0')) {
teco_string_clear(&comspec);
teco_error_qregcontainsnull_set(error, "$COMSPEC", 8, FALSE);
return NULL;
@@ -150,7 +150,7 @@ teco_parse_shell_command_line(const gchar *cmdline, GError **error)
teco_string_t shell;
if (!reg->vtable->get_string(reg, &shell.data, &shell.len, NULL, error))
return NULL;
- if (teco_string_contains(&shell, '\0')) {
+ if (teco_string_contains(shell, '\0')) {
teco_string_clear(&shell);
teco_error_qregcontainsnull_set(error, "$SHELL", 6, FALSE);
return NULL;
@@ -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)) {
@@ -247,7 +242,7 @@ teco_state_execute_initial(teco_machine_main_t *ctx, GError **error)
}
static teco_state_t *
-teco_state_execute_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
+teco_state_execute_done(teco_machine_main_t *ctx, teco_string_t str, GError **error)
{
/*
* NOTE: With G_SPAWN_LEAVE_DESCRIPTORS_OPEN and without G_SPAWN_SEARCH_PATH_FROM_ENVP,
@@ -290,13 +285,13 @@ teco_state_execute_done(teco_machine_main_t *ctx, const teco_string_t *str, GErr
}
#endif
- if (!str->len || teco_string_contains(str, '\0')) {
+ if (!str.len || teco_string_contains(str, '\0')) {
g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED,
"Command line must not be empty or contain null-bytes");
goto gerror;
}
- argv = teco_parse_shell_command_line(str->data, error);
+ argv = teco_parse_shell_command_line(str.data, error);
if (!argv)
goto gerror;
@@ -420,8 +415,9 @@ teco_state_execute_done(teco_machine_main_t *ctx, const teco_string_t *str, GErr
teco_interface_ssm(SCI_DELETERANGE, teco_spawn_ctx.from,
teco_spawn_ctx.to - teco_spawn_ctx.from);
- teco_undo_gsize(teco_ranges[0].from) = teco_spawn_ctx.from;
- teco_undo_gsize(teco_ranges[0].to) = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0);
+ sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0);
+ teco_undo_int(teco_ranges[0].from) = teco_interface_bytes2glyphs(teco_spawn_ctx.from);
+ teco_undo_int(teco_ranges[0].to) = teco_interface_bytes2glyphs(pos);
teco_undo_guint(teco_ranges_count) = 1;
}
teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0);
@@ -490,7 +486,7 @@ cleanup:
/* in cmdline.c */
gboolean teco_state_execute_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar key, GError **error);
-/*$ EC pipe filter
+/*$ "EC" :EC" pipe filter
* ECcommand$ -- Execute operating system command and filter buffer contents
* linesECcommand$
* -ECcommand$
@@ -609,7 +605,8 @@ gboolean teco_state_execute_process_edit_cmd(teco_machine_main_t *ctx, teco_mach
*/
TECO_DEFINE_STATE_EXPECTSTRING(teco_state_execute,
.initial_cb = (teco_state_initial_cb_t)teco_state_execute_initial,
- .process_edit_cmd_cb = (teco_state_process_edit_cmd_cb_t)teco_state_execute_process_edit_cmd
+ .process_edit_cmd_cb = (teco_state_process_edit_cmd_cb_t)teco_state_execute_process_edit_cmd,
+ .expectstring.done_cb = teco_state_execute_done
);
static teco_state_t *
@@ -623,7 +620,7 @@ teco_state_egcommand_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg,
return &teco_state_execute;
}
-/*$ EG EGq
+/*$ "EG" "EGq" ":EGq"
* EGq command$ -- Set Q-Register to output of operating system command
* linesEGq command$
* -EGq command$
@@ -651,7 +648,8 @@ teco_state_egcommand_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg,
* The register <q> is defined if it does not already exist.
*/
TECO_DEFINE_STATE_EXPECTQREG(teco_state_egcommand,
- .expectqreg.type = TECO_QREG_OPTIONAL_INIT
+ .expectqreg.type = TECO_QREG_OPTIONAL_INIT,
+ .expectqreg.got_register_cb = teco_state_egcommand_got_register
);
/*