fixed: splitting
This commit is contained in:
parent
ca8e484183
commit
135a6429ee
14 changed files with 117 additions and 66 deletions
4
Makefile
4
Makefile
|
|
@ -6,7 +6,7 @@
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||||
# Updated: 2024/10/14 14:00:30 by maiboyer ### ########.fr #
|
# Updated: 2024/10/14 15:20:12 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -44,7 +44,7 @@ endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS_ADDITIONAL ?=
|
CFLAGS_ADDITIONAL ?=
|
||||||
#CFLAGS_ADDITIONAL += -DNVALGRIND
|
CFLAGS_ADDITIONAL += -DNVALGRIND
|
||||||
|
|
||||||
# TODO: REMOVE THIS WHEN FINISHING THIS:
|
# TODO: REMOVE THIS WHEN FINISHING THIS:
|
||||||
# CFLAGS_ADDITIONAL += -fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins #-fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--allow-multiple
|
# CFLAGS_ADDITIONAL += -fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins #-fuse-ld=lld -ffunction-sections -fdata-sections -Wl,--allow-multiple
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
|
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/12 17:51:13 by rparodi ### ########.fr */
|
/* Updated: 2024/10/14 14:12:42 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ static inline void ast_print_block2(t_ast_node self)
|
||||||
if (self->kind == AST_FUNCTION_DEFINITION)
|
if (self->kind == AST_FUNCTION_DEFINITION)
|
||||||
return (ast_print_node_function_definition(self));
|
return (ast_print_node_function_definition(self));
|
||||||
if (self->kind == AST_HEREDOC_REDIRECTION)
|
if (self->kind == AST_HEREDOC_REDIRECTION)
|
||||||
return (ast_print_notdone(self));
|
return (ast_print_node_heredoc_redirection(self));
|
||||||
if (self->kind == AST_IF)
|
if (self->kind == AST_IF)
|
||||||
return (ast_print_notdone(self));
|
return (ast_print_notdone(self));
|
||||||
if (self->kind == AST_LIST)
|
if (self->kind == AST_LIST)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
|
/* Created: 2024/07/03 20:38:29 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/12 17:51:13 by rparodi ### ########.fr */
|
/* Updated: 2024/10/14 14:15:06 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -61,8 +61,9 @@ void ast_print_node_command(t_ast_node self)
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < self->data.command.prefixes.len)
|
while (i < self->data.command.prefixes.len)
|
||||||
{
|
{
|
||||||
|
printf(" _");
|
||||||
ast_print(self->data.command.prefixes.buffer[i++]);
|
ast_print(self->data.command.prefixes.buffer[i++]);
|
||||||
printf(" ");
|
printf("_ ");
|
||||||
}
|
}
|
||||||
return (ast_print_node_command_helper(self));
|
return (ast_print_node_command_helper(self));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/26 13:34:09 by rparodi #+# #+# */
|
/* Created: 2024/07/26 13:34:09 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/12 17:51:14 by rparodi ### ########.fr */
|
/* Updated: 2024/10/14 14:14:36 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -26,7 +26,7 @@ void ast_print_node_raw_string(t_ast_node self)
|
||||||
return ;
|
return ;
|
||||||
if (self->kind != AST_RAW_STRING)
|
if (self->kind != AST_RAW_STRING)
|
||||||
return ;
|
return ;
|
||||||
printf("%s", self->data.raw_string.str);
|
printf("{%s}", self->data.raw_string.str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_print_node_regex(t_ast_node self)
|
void ast_print_node_regex(t_ast_node self)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/26 13:07:12 by rparodi #+# #+# */
|
/* Created: 2024/07/26 13:07:12 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/12 17:51:15 by rparodi ### ########.fr */
|
/* Updated: 2024/10/14 14:12:49 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -49,3 +49,8 @@ void ast_print_node_file_redirection(t_ast_node self)
|
||||||
ast_print(self->data.file_redirection.output);
|
ast_print(self->data.file_redirection.output);
|
||||||
return ((void) ast_print_node_file_redirection_heredoc(self));
|
return ((void) ast_print_node_file_redirection_heredoc(self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ast_print_node_heredoc_redirection(t_ast_node self)
|
||||||
|
{
|
||||||
|
printf("<<%s", self->data.heredoc_redirection.delimiter);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/26 13:27:30 by rparodi #+# #+# */
|
/* Created: 2024/07/26 13:27:30 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/12 17:51:15 by rparodi ### ########.fr */
|
/* Updated: 2024/10/14 14:22:39 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -100,8 +100,12 @@ void ast_print_node_word(t_ast_node self)
|
||||||
if (self->data.word.kind == AST_WORD_DOUBLE_QUOTE)
|
if (self->data.word.kind == AST_WORD_DOUBLE_QUOTE)
|
||||||
quote_type = "\"";
|
quote_type = "\"";
|
||||||
i = 0;
|
i = 0;
|
||||||
|
printf("<=");
|
||||||
printf("%s", quote_type);
|
printf("%s", quote_type);
|
||||||
while (i < self->data.word.inner.len)
|
while (i < self->data.word.inner.len)
|
||||||
|
{
|
||||||
ast_print(self->data.word.inner.buffer[i++]);
|
ast_print(self->data.word.inner.buffer[i++]);
|
||||||
|
}
|
||||||
printf("%s", quote_type);
|
printf("%s", quote_type);
|
||||||
|
printf("=>");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:26:51 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/14 12:34:25 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 15:02:01 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,32 +21,62 @@ 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 list_files_in_current_directory(t_vec_str *out);
|
||||||
t_error _word_into_str_inner(struct s_word_str_args args);
|
t_error _word_into_str_inner(struct s_word_str_args args);
|
||||||
|
|
||||||
t_error _word_pass_quote(t_state *state, t_word_result *res, t_vec_str *append)
|
t_error _word_split_loop(\
|
||||||
|
bool do_split, t_expandable_str val, t_vec_str *append, t_string *tmp)
|
||||||
|
{
|
||||||
|
t_vec_str split;
|
||||||
|
t_str stmp;
|
||||||
|
|
||||||
|
if (do_split)
|
||||||
|
{
|
||||||
|
if (val.do_expand)
|
||||||
|
{
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
string_push(tmp, val.value);
|
||||||
|
return (NO_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_error _word_split(\
|
||||||
|
bool do_split, t_state *state, t_word_result *res, t_vec_str *append)
|
||||||
{
|
{
|
||||||
t_string tmp;
|
t_string tmp;
|
||||||
t_usize i;
|
t_usize i;
|
||||||
|
|
||||||
(void)(state);
|
|
||||||
tmp = string_new(64);
|
tmp = string_new(64);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < res->value.len)
|
while (i < res->value.len)
|
||||||
string_push(&tmp, res->value.buffer[i++].value);
|
{
|
||||||
|
if (_word_split_loop(do_split, res->value.buffer[i++], append, &tmp))
|
||||||
|
return (string_free(tmp), ERROR);
|
||||||
|
}
|
||||||
|
if (!do_split)
|
||||||
vec_str_push(append, tmp.buf);
|
vec_str_push(append, tmp.buf);
|
||||||
return (NO_ERROR);
|
else
|
||||||
|
string_free(tmp);
|
||||||
|
return ((void)state, NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *append)
|
t_error _word_into_str(t_ast_node self, t_state *state, t_vec_str *ap)
|
||||||
{
|
{
|
||||||
t_word_result res;
|
t_word_result res;
|
||||||
|
|
||||||
if (self == NULL || state == NULL || append == NULL
|
if (self == NULL || state == NULL || ap == NULL
|
||||||
|| self->kind != AST_WORD)
|
|| self->kind != AST_WORD)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (_word_is_star(&self->data.word))
|
if (_word_is_star(&self->data.word))
|
||||||
return (_word_handle_star(&self->data.word, state, append));
|
return (_word_handle_star(&self->data.word, state, ap));
|
||||||
if (run_word(&self->data.word, state, &res))
|
if (run_word(&self->data.word, state, &res))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (_word_pass_quote(state, &res, append))
|
if (_word_split(self->data.word.kind == AST_WORD_NO_QUOTE, state, &res, ap))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
return (vec_estr_free(res.value), NO_ERROR);
|
return (vec_estr_free(res.value), NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,21 +6,21 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/13 17:59:35 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 15:07:42 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "app/env.h"
|
#include "app/env.h"
|
||||||
#include "exec/_run_ast.h"
|
#include "exec/_run_ast.h"
|
||||||
|
#include "line/line.h"
|
||||||
#include "me/fs/fs.h"
|
#include "me/fs/fs.h"
|
||||||
#include "me/os/os.h"
|
#include "me/os/os.h"
|
||||||
|
#include "me/printf/printf.h"
|
||||||
#include "me/str/str.h"
|
#include "me/str/str.h"
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include "line/line.h"
|
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
t_error _redirection_fd(\
|
t_error _redirection_fd(\
|
||||||
t_spawn_info *info, t_state *state, t_ast_node red);
|
t_spawn_info *info, t_state *state, t_ast_node red);
|
||||||
|
|
@ -55,12 +55,20 @@ t_error _setup_redirection(\
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static t_error _err_cmd(t_str bpath)
|
||||||
|
{
|
||||||
|
me_eprintf("failed to execute %s\n", bpath);
|
||||||
|
str_free(bpath);
|
||||||
|
return (ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
t_error _spawn_cmd_and_run_end(\
|
t_error _spawn_cmd_and_run_end(\
|
||||||
t_spawn_info info, t_state *state, \
|
t_spawn_info info, t_state *state, \
|
||||||
t_cmd_pipe cmd_pipe, t_command_result *out)
|
t_cmd_pipe cmd_pipe, t_command_result *out)
|
||||||
{
|
{
|
||||||
struct s_ffree_state ffree;
|
struct s_ffree_state ffree;
|
||||||
int status;
|
int status;
|
||||||
|
t_str bpath;
|
||||||
|
|
||||||
status = 0;
|
status = 0;
|
||||||
ffree = (struct s_ffree_state){.state = state, .cmd_pipe = cmd_pipe};
|
ffree = (struct s_ffree_state){.state = state, .cmd_pipe = cmd_pipe};
|
||||||
|
|
@ -68,8 +76,10 @@ t_error _spawn_cmd_and_run_end(\
|
||||||
info.forked_free = (void (*)(void *))_ffree_func;
|
info.forked_free = (void (*)(void *))_ffree_func;
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
signal(SIGQUIT, SIG_IGN);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
bpath = str_clone(info.binary_path);
|
||||||
if (spawn_process(info, &out->process))
|
if (spawn_process(info, &out->process))
|
||||||
return (close_fd(cmd_pipe.input), out->exit = 127, ERROR);
|
return (close_fd(cmd_pipe.input), out->exit = 127, _err_cmd(bpath));
|
||||||
|
str_free(bpath);
|
||||||
if (cmd_pipe.create_output || cmd_pipe.input != NULL)
|
if (cmd_pipe.create_output || cmd_pipe.input != NULL)
|
||||||
return (out->exit = -1, NO_ERROR);
|
return (out->exit = -1, NO_ERROR);
|
||||||
if (waitpid(out->process.pid, &status, 0) == -1 && errno != ECHILD)
|
if (waitpid(out->process.pid, &status, 0) == -1 && errno != ECHILD)
|
||||||
|
|
@ -88,8 +98,6 @@ t_error _spawn_cmd_and_run(t_vec_str args, t_redirections redirs,
|
||||||
t_spawn_info info;
|
t_spawn_info info;
|
||||||
|
|
||||||
info = (t_spawn_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))
|
if (_setup_redirection(&info, state, redirs.cmd_pipe, &redirs.redirections))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
redirs.redirections.len = 0;
|
redirs.redirections.len = 0;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:30:09 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/13 13:58:11 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 15:10:40 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
#include "exec/_run_ast.h"
|
#include "exec/_run_ast.h"
|
||||||
#include "me/fs/fs.h"
|
#include "me/fs/fs.h"
|
||||||
#include "me/os/os.h"
|
#include "me/os/os.h"
|
||||||
|
#include "me/printf/printf.h"
|
||||||
#include "me/str/str.h"
|
#include "me/str/str.h"
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -21,8 +22,11 @@
|
||||||
#include "line/line.h"
|
#include "line/line.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
|
|
||||||
|
#define ARG "Error: too may args for redirection\n"
|
||||||
|
#define ERR "Error: failed to open %s\n"
|
||||||
|
|
||||||
t_error _redir_input(\
|
t_error _redir_input(\
|
||||||
t_spawn_info *info, t_state *state, t_vec_str *fname, t_ast_node red)
|
t_spawn_info *info, t_state *state, t_vec_str *fn, t_ast_node red)
|
||||||
{
|
{
|
||||||
t_fd *red_fd;
|
t_fd *red_fd;
|
||||||
|
|
||||||
|
|
@ -30,20 +34,20 @@ t_error _redir_input(\
|
||||||
{
|
{
|
||||||
(void)((info->stdin.tag == R_FD) && (close_fd(info->stdin.fd.fd), 1));
|
(void)((info->stdin.tag == R_FD) && (close_fd(info->stdin.fd.fd), 1));
|
||||||
info->stdin.tag = R_INHERITED;
|
info->stdin.tag = R_INHERITED;
|
||||||
if (_ast_into_str(red->data.file_redirection.output, state, fname))
|
if (_ast_into_str(red->data.file_redirection.output, state, fn))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (fname->len != 1)
|
if (fn->len != 1)
|
||||||
return (vec_str_free(*fname), ERROR);
|
return (me_eprintf(ARG), vec_str_free(*fn), ERROR);
|
||||||
red_fd = open_fd(fname->buffer[0], FD_READ, O_CLOEXEC, 0);
|
red_fd = open_fd(fn->buffer[0], FD_READ, O_CLOEXEC, 0);
|
||||||
if (red_fd == NULL)
|
if (red_fd == NULL)
|
||||||
return (vec_str_free(*fname), ERROR);
|
return (me_eprintf(ERR, fn->buffer[0]), vec_str_free(*fn), ERROR);
|
||||||
info->stdin = fd(red_fd);
|
info->stdin = fd(red_fd);
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _redir_output(\
|
t_error _redir_output(\
|
||||||
t_spawn_info *info, t_state *state, t_vec_str *fname, t_ast_node red)
|
t_spawn_info *info, t_state *state, t_vec_str *fn, t_ast_node red)
|
||||||
{
|
{
|
||||||
t_fd *red_fd;
|
t_fd *red_fd;
|
||||||
|
|
||||||
|
|
@ -51,21 +55,21 @@ t_error _redir_output(\
|
||||||
{
|
{
|
||||||
(void)((info->stdout.tag == R_FD) && (close_fd(info->stdout.fd.fd), 1));
|
(void)((info->stdout.tag == R_FD) && (close_fd(info->stdout.fd.fd), 1));
|
||||||
info->stdout.tag = R_INHERITED;
|
info->stdout.tag = R_INHERITED;
|
||||||
if (_ast_into_str(red->data.file_redirection.output, state, fname))
|
if (_ast_into_str(red->data.file_redirection.output, state, fn))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (fname->len != 1)
|
if (fn->len != 1)
|
||||||
return (vec_str_free(*fname), ERROR);
|
return (me_eprintf(ARG), vec_str_free(*fn), ERROR);
|
||||||
red_fd = open_fd(fname->buffer[0], FD_WRITE, \
|
red_fd = open_fd(fn->buffer[0], FD_WRITE, \
|
||||||
O_TRUNC | O_CREAT | O_CLOEXEC, FP_ALL_READ | FP_ALL_WRITE);
|
O_TRUNC | O_CREAT | O_CLOEXEC, FP_ALL_READ | FP_ALL_WRITE);
|
||||||
if (red_fd == NULL)
|
if (red_fd == NULL)
|
||||||
return (vec_str_free(*fname), ERROR);
|
return (me_eprintf(ERR, fn->buffer[0]), vec_str_free(*fn), ERROR);
|
||||||
info->stdout = fd(red_fd);
|
info->stdout = fd(red_fd);
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _redir_output_append(\
|
t_error _redir_output_append(\
|
||||||
t_spawn_info *info, t_state *state, t_vec_str *fname, t_ast_node red)
|
t_spawn_info *info, t_state *state, t_vec_str *fn, t_ast_node red)
|
||||||
{
|
{
|
||||||
t_fd *red_fd;
|
t_fd *red_fd;
|
||||||
|
|
||||||
|
|
@ -73,14 +77,14 @@ t_error _redir_output_append(\
|
||||||
{
|
{
|
||||||
(void)((info->stdout.tag == R_FD) && (close_fd(info->stdout.fd.fd), 1));
|
(void)((info->stdout.tag == R_FD) && (close_fd(info->stdout.fd.fd), 1));
|
||||||
info->stdout.tag = R_INHERITED;
|
info->stdout.tag = R_INHERITED;
|
||||||
if (_ast_into_str(red->data.file_redirection.output, state, fname))
|
if (_ast_into_str(red->data.file_redirection.output, state, fn))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (fname->len != 1)
|
if (fn->len != 1)
|
||||||
return (vec_str_free(*fname), ERROR);
|
return (me_eprintf(ARG), vec_str_free(*fn), ERROR);
|
||||||
red_fd = open_fd(fname->buffer[0], FD_WRITE, \
|
red_fd = open_fd(fn->buffer[0], FD_WRITE, \
|
||||||
O_APPEND | O_CREAT | O_CLOEXEC, FP_ALL_READ | FP_ALL_WRITE);
|
O_APPEND | O_CREAT | O_CLOEXEC, FP_ALL_READ | FP_ALL_WRITE);
|
||||||
if (red_fd == NULL)
|
if (red_fd == NULL)
|
||||||
return (vec_str_free(*fname), ERROR);
|
return (me_eprintf(ERR, fn->buffer[0]), vec_str_free(*fn), ERROR);
|
||||||
info->stdout = fd(red_fd);
|
info->stdout = fd(red_fd);
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/14 12:32:37 by maiboyer #+# #+# */
|
/* Created: 2024/09/14 12:32:37 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/13 18:01:06 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 15:02:28 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -51,6 +51,7 @@ void _wait_pipeline(t_vec_pid pids, t_state *state, t_pipeline_result *out)
|
||||||
waitpid_status = 0;
|
waitpid_status = 0;
|
||||||
while (waitpid(pids.buffer[pids.len - 1], &waitpid_status, 0) < 0 \
|
while (waitpid(pids.buffer[pids.len - 1], &waitpid_status, 0) < 0 \
|
||||||
&& errno != ECHILD)
|
&& errno != ECHILD)
|
||||||
|
;
|
||||||
if (errno == ECHILD)
|
if (errno == ECHILD)
|
||||||
waitpid_status = 0;
|
waitpid_status = 0;
|
||||||
while (waitpid(-1, NULL, 0) != -1)
|
while (waitpid(-1, NULL, 0) != -1)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/09/06 16:31:41 by rparodi #+# #+# */
|
/* Created: 2024/09/06 16:31:41 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/12 17:52:01 by rparodi ### ########.fr */
|
/* Updated: 2024/10/14 15:03:01 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -67,7 +67,7 @@ void exec_shcat(t_state *state)
|
||||||
if (state->ast != NULL && run_program(&state->ast->data.program, state,
|
if (state->ast != NULL && run_program(&state->ast->data.program, state,
|
||||||
&prog_res))
|
&prog_res))
|
||||||
{
|
{
|
||||||
printf("Error when execting the Command \n");
|
printf("Error when executing the cmd\n");
|
||||||
state->last_exit = 127;
|
state->last_exit = 127;
|
||||||
}
|
}
|
||||||
ast_free(state->ast);
|
ast_free(state->ast);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
/* Created: 2024/03/28 14:40:38 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/10/14 14:01:19 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 15:13:06 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -76,7 +76,6 @@ void append_default_env(t_hashmap_env *env)
|
||||||
shlvl = 0;
|
shlvl = 0;
|
||||||
tmp = hmap_env_get(env, &key);
|
tmp = hmap_env_get(env, &key);
|
||||||
(void)(tmp != NULL && str_to_u64(*tmp, 10, &shlvl));
|
(void)(tmp != NULL && str_to_u64(*tmp, 10, &shlvl));
|
||||||
(void)((tmp != NULL) && (str_free(*tmp), 1));
|
|
||||||
if (u64_to_str(shlvl + 1, &tmp2))
|
if (u64_to_str(shlvl + 1, &tmp2))
|
||||||
me_abort("Failed to set SHLVL");
|
me_abort("Failed to set SHLVL");
|
||||||
hmap_env_insert(env, str_clone(key), tmp2);
|
hmap_env_insert(env, str_clone(key), tmp2);
|
||||||
|
|
@ -84,7 +83,6 @@ void append_default_env(t_hashmap_env *env)
|
||||||
tmp = hmap_env_get(env, &key);
|
tmp = hmap_env_get(env, &key);
|
||||||
if (tmp == NULL)
|
if (tmp == NULL)
|
||||||
hmap_env_insert(env, str_clone(key), str_clone(DFT_PATH));
|
hmap_env_insert(env, str_clone(key), str_clone(DFT_PATH));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error populate_env(t_hashmap_env *env, t_str envp[])
|
t_error populate_env(t_hashmap_env *env, t_str envp[])
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/02 13:22:14 by maiboyer #+# #+# */
|
/* Created: 2024/05/02 13:22:14 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/13 17:56:04 by maiboyer ### ########.fr */
|
/* Updated: 2024/10/14 15:03:10 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
t_error install_signal(void)
|
t_error install_signal(void)
|
||||||
{
|
{
|
||||||
//if (signal(SIGINT, SIG_IGN))
|
if (signal(SIGINT, SIG_IGN))
|
||||||
// return (ERROR);
|
return (ERROR);
|
||||||
//if (signal(SIGQUIT, SIG_IGN))
|
if (signal(SIGQUIT, SIG_IGN))
|
||||||
// return (ERROR);
|
return (ERROR);
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */
|
/* Created: 2024/05/14 18:26:27 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/10/12 17:52:32 by rparodi ### ########.fr */
|
/* Updated: 2024/10/14 14:48:10 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ t_allocator *global_allocator(void)
|
||||||
if (!init)
|
if (!init)
|
||||||
{
|
{
|
||||||
init = true;
|
init = true;
|
||||||
global_alloc = m_init();
|
global_alloc = lc_init();
|
||||||
}
|
}
|
||||||
return (&global_alloc);
|
return (&global_alloc);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue