update: fixed small errors
This commit is contained in:
parent
f5a8c2be04
commit
d97efa87a7
16 changed files with 59 additions and 140 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/12 17:51:23 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/13 17:30:06 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,7 +41,7 @@ t_error _word_no_quote(t_state *state, t_word_result *res, t_vec_str *append)
|
|||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error _word_do_quote(t_state *state, t_word_result *res, t_vec_str *append)
|
||||
t_error _word_pass_quote(t_state *state, t_word_result *res, t_vec_str *append)
|
||||
{
|
||||
t_string tmp;
|
||||
t_usize i;
|
||||
|
|
@ -66,12 +66,7 @@ t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append)
|
|||
return (_word_handle_star(&self->data.word, state, append));
|
||||
if (run_word(&self->data.word, state, &res))
|
||||
return (ERROR);
|
||||
if (res.kind == AST_WORD_NO_QUOTE)
|
||||
{
|
||||
if (_word_no_quote(state, &res, append))
|
||||
return (ERROR);
|
||||
}
|
||||
else if (_word_do_quote(state, &res, append))
|
||||
if (_word_pass_quote(state, &res, append))
|
||||
return (ERROR);
|
||||
return (vec_estr_free(res.value), NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,87 +0,0 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* _ast_into_str6.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/12 17:51:22 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "exec/_run_ast.h"
|
||||
#include "me/string/string.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/convert/numbers_to_str.h"
|
||||
#include "me/vec/vec_str.h"
|
||||
|
||||
bool _word_is_star(t_ast_word *word);
|
||||
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_inner3(struct s_word_str_args args)
|
||||
{
|
||||
t_usize j;
|
||||
t_usize len;
|
||||
|
||||
j = 0;
|
||||
while (j + 1 < args.splitted->len)
|
||||
{
|
||||
if (vec_str_pop_front(args.splitted, args.tmp_str))
|
||||
return (vec_estr_free(args.res->value), ERROR);
|
||||
vec_str_push(args.append, *args.tmp_str);
|
||||
j++;
|
||||
}
|
||||
len = str_len(args.res->value.buffer[args.i].value);
|
||||
if (len != 0 && str_find_chr(args.ifs,
|
||||
args.res->value.buffer[args.i].value[len - 1]) == NULL)
|
||||
(string_push(args.tmp, *args.tmp_str), str_free(*args.tmp_str));
|
||||
else
|
||||
vec_str_push(args.append, *args.tmp_str);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error _word_into_str_inner2(struct s_word_str_args args)
|
||||
{
|
||||
t_str ifs;
|
||||
t_str tmp_str;
|
||||
t_vec_str splitted;
|
||||
|
||||
ifs = _get_ifs_value(args.state);
|
||||
if (str_split(args.res->value.buffer[args.i].value, ifs, &splitted))
|
||||
return (vec_estr_free(args.res->value), ERROR);
|
||||
if (!vec_str_pop_front(&splitted, &tmp_str))
|
||||
{
|
||||
if (str_find_chr(ifs,
|
||||
args.res->value.buffer[args.i].value[0]) == NULL)
|
||||
(string_push(args.tmp, tmp_str), str_free(tmp_str));
|
||||
else
|
||||
{
|
||||
vec_str_push(args.append, args.tmp->buf);
|
||||
*args.tmp = string_new(64);
|
||||
string_push(args.tmp, tmp_str);
|
||||
str_free(tmp_str);
|
||||
}
|
||||
if (_word_into_str_inner3((struct s_word_str_args){args.i, args.state, \
|
||||
args.tmp, args.res, args.append, &tmp_str, &splitted, ifs}))
|
||||
return (ERROR);
|
||||
}
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
||||
t_error _word_into_str_inner(struct s_word_str_args args)
|
||||
{
|
||||
t_str ifs;
|
||||
|
||||
ifs = _get_ifs_value(args.state);
|
||||
while (ifs != NULL && *ifs != '\0'
|
||||
&& str_find_chr(args.res->value.buffer[args.i].value, *ifs) == NULL)
|
||||
ifs++;
|
||||
if (ifs == NULL || *ifs == '\0')
|
||||
string_push(args.tmp, args.res->value.buffer[args.i].value);
|
||||
else if (_word_into_str_inner2((struct s_word_str_args){args.i, \
|
||||
args.state, args.tmp, args.res, args.append, NULL, NULL, NULL}))
|
||||
return (ERROR);
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/12 17:51:27 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/13 17:32:14 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,6 +20,7 @@
|
|||
#include <errno.h>
|
||||
#include "line/line.h"
|
||||
#include "me/types.h"
|
||||
#include <errno.h>
|
||||
|
||||
t_error _redirection_fd(\
|
||||
t_spawn_info *info, t_state *state, t_ast_node red);
|
||||
|
|
@ -70,12 +71,12 @@ t_error _spawn_cmd_and_run_end(\
|
|||
return (close_fd(cmd_pipe.input), out->exit = 127, ERROR);
|
||||
if (cmd_pipe.create_output || cmd_pipe.input != NULL)
|
||||
return (out->exit = -1, NO_ERROR);
|
||||
if (waitpid(out->process.pid, &status, 0) == -1)
|
||||
if (waitpid(out->process.pid, &status, 0) == -1 && errno != ESRCH)
|
||||
return (ERROR);
|
||||
if (WIFEXITED(status))
|
||||
out->exit = WEXITSTATUS(status);
|
||||
if (WIFSIGNALED(status))
|
||||
out->exit = WTERMSIG(status);
|
||||
out->exit = WTERMSIG(status) + 128;
|
||||
state->last_exit = out->exit;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
@ -86,6 +87,8 @@ t_error _spawn_cmd_and_run(t_vec_str args, t_redirections redirs,
|
|||
t_spawn_info info;
|
||||
|
||||
info = (t_spawn_info){};
|
||||
for (t_usize i = 0; i < args.len; i++)
|
||||
printf("args[%zu] = %s\n", i, args.buffer[i]);
|
||||
if (_setup_redirection(&info, state, redirs.cmd_pipe, &redirs.redirections))
|
||||
return (ERROR);
|
||||
redirs.redirections.len = 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/14 12:35:02 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/10/12 17:51:27 by rparodi ### ########.fr */
|
||||
/* Updated: 2024/10/13 17:24:55 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
#include "me/mem/mem.h"
|
||||
#include "me/os/os.h"
|
||||
#include <sys/wait.h>
|
||||
#include <errno.h>
|
||||
|
||||
t_error _spawn_info_to_subshell(\
|
||||
t_spawn_info *info, struct s_subshell_info *sinfo)
|
||||
|
|
@ -75,13 +76,12 @@ t_error _wait_subshell(\
|
|||
(dup2(sinfo.stderr->fd, 2), close_fd(sinfo.stderr));
|
||||
if (cmd_pipe.create_output || cmd_pipe.input != NULL)
|
||||
return (out->stdout = sinfo.ret_stdout, NO_ERROR);
|
||||
if (waitpid(forked, &status, 0) == -1)
|
||||
if (waitpid(forked, &status, 0) == -1 && errno != ESRCH)
|
||||
return (ERROR);
|
||||
if (WIFEXITED(status))
|
||||
out->exit = WEXITSTATUS(status);
|
||||
if (WIFSIGNALED(status))
|
||||
out->exit = WTERMSIG(status);
|
||||
printf("out->exit for subshell is %i\n", out->exit);
|
||||
out->exit = WTERMSIG(status) + 130;
|
||||
sinfo.state->last_exit = out->exit;
|
||||
return (NO_ERROR);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue