update: fixed some issues

This commit is contained in:
maix0 2024-10-24 23:02:37 +02:00
parent 1a3253afc8
commit 2b5a62afc8
6 changed files with 40 additions and 24 deletions

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
/* Updated: 2024/10/15 21:30:02 by maiboyer ### ########.fr */
/* Updated: 2024/10/24 22:48:26 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,27 +21,39 @@ t_error _word_handle_star(t_ast_word *word, t_state *state, t_vec_str *out);
t_error list_files_in_current_directory(t_vec_str *out);
t_error _word_into_str_inner(struct s_word_str_args args);
t_error _word_split_loop(\
bool do_split, t_expandable_str val, t_vec_str *append, t_string *tmp)
t_error _word_split_loop_expand(\
t_expandable_str val, t_vec_str *append, t_string *tmp)
{
t_vec_str split;
t_str stmp;
if (val.do_expand)
{
if (val.value == NULL)
val.value = "";
if (str_split(val.value, " \t\n\r\v", &split))
return (ERROR);
if (split.len != 0)
{
vec_str_push(append, tmp->buf);
*tmp = string_new(16);
}
while (!vec_str_pop_front(&split, &stmp))
vec_str_push(append, stmp);
vec_str_free(split);
}
else
string_push(tmp, val.value);
return (NO_ERROR);
}
t_error _word_split_loop(\
bool do_split, t_expandable_str val, t_vec_str *append, t_string *tmp)
{
if (do_split)
{
if (val.do_expand)
{
if (val.value == NULL)
val.value = "";
if (str_split(val.value, " ", &split))
return (ERROR);
while (!vec_str_pop_front(&split, &stmp))
vec_str_push(append, stmp);
vec_str_free(split);
}
else
vec_str_push(append, str_clone(val.value));
}
return (_word_split_loop_expand(val, append, tmp));
else
string_push(tmp, val.value);
return (NO_ERROR);
@ -60,7 +72,7 @@ t_error _word_split(\
if (_word_split_loop(do_split, res->value.buffer[i++], append, &tmp))
return (string_free(tmp), ERROR);
}
if (!do_split)
if (!do_split || tmp.len != 0)
vec_str_push(append, tmp.buf);
else
string_free(tmp);

View file

@ -6,7 +6,7 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
/* Updated: 2024/10/14 15:07:42 by maiboyer ### ########.fr */
/* Updated: 2024/10/24 22:57:49 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
@ -79,6 +79,7 @@ t_error _spawn_cmd_and_run_end(\
bpath = str_clone(info.binary_path);
if (spawn_process(info, &out->process))
return (close_fd(cmd_pipe.input), out->exit = 127, _err_cmd(bpath));
close_fd(cmd_pipe.input);
str_free(bpath);
if (cmd_pipe.create_output || cmd_pipe.input != NULL)
return (out->exit = -1, NO_ERROR);