Moved files a bit to reflect their use
This commit is contained in:
parent
7ac90bac55
commit
72b90debcc
18 changed files with 149 additions and 124 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/04/28 17:28:30 by maiboyer #+# #+# #
|
# Created: 2024/04/28 17:28:30 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/07/31 17:18:34 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:58:21 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -100,4 +100,6 @@ build_filelist:
|
||||||
@echo "" >> Filelist.$(ANAME).mk
|
@echo "" >> Filelist.$(ANAME).mk
|
||||||
@echo -e '$(GREY) Populating $(GREEN) Filelist.$(ANAME).mk$(END)'
|
@echo -e '$(GREY) Populating $(GREEN) Filelist.$(ANAME).mk$(END)'
|
||||||
|
|
||||||
|
%.h: ;
|
||||||
|
|
||||||
-include $(DEP)
|
-include $(DEP)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/07/23 21:52:17 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:57:11 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -17,7 +17,6 @@ SRC_DIR = src
|
||||||
INCLUDE_DIR = include output/include ../stdme/include
|
INCLUDE_DIR = include output/include ../stdme/include
|
||||||
LIBS_DIR = .
|
LIBS_DIR = .
|
||||||
|
|
||||||
|
|
||||||
BASE_PATH ?= $(shell pwd)
|
BASE_PATH ?= $(shell pwd)
|
||||||
NAME = lib$(ANAME).a
|
NAME = lib$(ANAME).a
|
||||||
LIB_NAME ?=
|
LIB_NAME ?=
|
||||||
|
|
@ -87,4 +86,6 @@ build_filelist:
|
||||||
@echo "" >> Filelist.$(ANAME).mk
|
@echo "" >> Filelist.$(ANAME).mk
|
||||||
@echo -e '$(COL_GRAY) Populating $(COL_GREEN) Filelist.$(ANAME).mk$(END)'
|
@echo -e '$(COL_GRAY) Populating $(COL_GREEN) Filelist.$(ANAME).mk$(END)'
|
||||||
|
|
||||||
|
%.h: ;
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/07/23 21:52:27 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:58:20 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -87,4 +87,6 @@ build_filelist:
|
||||||
@echo "" >> Filelist.$(ANAME).mk
|
@echo "" >> Filelist.$(ANAME).mk
|
||||||
@echo -e '$(COL_GRAY) Populating $(COL_GREEN) Filelist.$(ANAME).mk$(END)'
|
@echo -e '$(COL_GRAY) Populating $(COL_GREEN) Filelist.$(ANAME).mk$(END)'
|
||||||
|
|
||||||
|
%.h: ;
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
SRC_FILES = \
|
SRC_FILES = \
|
||||||
arith/arith \
|
run_arithmetic/arithmetic \
|
||||||
arith/arith_operation \
|
run_arithmetic/arithmetic_operation \
|
||||||
run_ast \
|
run_ast \
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/07/30 16:02:19 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:58:14 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -85,4 +85,6 @@ build_filelist:
|
||||||
@echo "" >> Filelist.$(ANAME).mk
|
@echo "" >> Filelist.$(ANAME).mk
|
||||||
@echo -e '$(COL_GRAY) Populating $(COL_GREEN) Filelist.$(ANAME).mk$(END)'
|
@echo -e '$(COL_GRAY) Populating $(COL_GREEN) Filelist.$(ANAME).mk$(END)'
|
||||||
|
|
||||||
|
%.h: ;
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,24 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* run_ast.h :+: :+: :+: */
|
/* _run_ast.h :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/08/02 14:41:48 by rparodi #+# #+# */
|
/* Created: 2024/08/02 14:41:48 by rparodi #+# #+# */
|
||||||
/* Updated: 2024/08/02 14:44:22 by rparodi ### ########.fr */
|
/* Updated: 2024/08/02 18:51:16 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef RUN_AST_H
|
#ifndef _RUN_AST_H
|
||||||
# define RUN_AST_H
|
#define _RUN_AST_H
|
||||||
|
|
||||||
#include "app/state.h"
|
#include "app/state.h"
|
||||||
#include "ast/ast.h"
|
#include "ast/ast.h"
|
||||||
#include "exec/run.h"
|
|
||||||
#include "me/convert/numbers_to_str.h"
|
|
||||||
#include "me/fs/fs.h"
|
#include "me/fs/fs.h"
|
||||||
#include "me/hashmap/hashmap_env.h"
|
|
||||||
#include "me/mem/mem.h"
|
|
||||||
#include "me/os/os.h"
|
#include "me/os/os.h"
|
||||||
#include "me/str/str.h"
|
|
||||||
#include "me/string/string.h"
|
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/vec/vec_estr.h"
|
#include "me/vec/vec_estr.h"
|
||||||
#include "me/vec/vec_str.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define NOT_DONE \
|
#define NOT_DONE \
|
||||||
{ \
|
{ \
|
||||||
|
|
@ -35,7 +26,6 @@
|
||||||
return (ERROR); \
|
return (ERROR); \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||||
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
|
||||||
|
|
@ -78,8 +68,8 @@ typedef struct s_cmd_pipe t_cmd_pipe;
|
||||||
|
|
||||||
struct s_cmd_pipe
|
struct s_cmd_pipe
|
||||||
{
|
{
|
||||||
t_fd *output;
|
t_fd *input;
|
||||||
bool create_input;
|
bool create_output;
|
||||||
};
|
};
|
||||||
|
|
||||||
t_error run_arithmetic_expansion(t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out);
|
t_error run_arithmetic_expansion(t_ast_arithmetic_expansion *arithmetic_expansion, t_state *state, t_i64 *out);
|
||||||
|
|
@ -110,5 +100,4 @@ t_error run_until(t_ast_until *until, t_state *state, void *out);
|
||||||
t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, void *out);
|
t_error run_variable_assignment(t_ast_variable_assignment *variable_assignment, t_state *state, void *out);
|
||||||
t_error run_while_(t_ast_while *while_, t_state *state, void *out);
|
t_error run_while_(t_ast_while *while_, t_state *state, void *out);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "exec/arith.h"
|
#include "exec/_run_arith.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
#include "me/convert/str_to_numbers.h"
|
#include "me/convert/str_to_numbers.h"
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "exec/arith.h"
|
#include "exec/_run_arith.h"
|
||||||
|
|
||||||
t_error _binary_op_add(t_ast_node self, t_state *state, t_i64 *out)
|
t_error _binary_op_add(t_ast_node self, t_state *state, t_i64 *out)
|
||||||
{
|
{
|
||||||
|
|
@ -6,11 +6,26 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */
|
/* Created: 2024/07/11 17:22:29 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/08/02 14:45:19 by rparodi ### ########.fr */
|
/* Updated: 2024/08/02 19:04:30 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "./run_ast.h"
|
#include "app/state.h"
|
||||||
|
#include "ast/ast.h"
|
||||||
|
#include "exec/_run_ast.h"
|
||||||
|
#include "exec/run.h"
|
||||||
|
#include "me/convert/numbers_to_str.h"
|
||||||
|
#include "me/fs/fs.h"
|
||||||
|
#include "me/hashmap/hashmap_env.h"
|
||||||
|
#include "me/mem/mem.h"
|
||||||
|
#include "me/os/os.h"
|
||||||
|
#include "me/str/str.h"
|
||||||
|
#include "me/string/string.h"
|
||||||
|
#include "me/types.h"
|
||||||
|
#include "me/vec/vec_estr.h"
|
||||||
|
#include "me/vec/vec_str.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
bool _is_special_var(t_ast_expansion *self)
|
bool _is_special_var(t_ast_expansion *self)
|
||||||
{
|
{
|
||||||
|
|
@ -23,16 +38,12 @@ bool _is_special_var(t_ast_expansion *self)
|
||||||
if (str_len(self->var_name) != 1)
|
if (str_len(self->var_name) != 1)
|
||||||
return (false);
|
return (false);
|
||||||
name = self->var_name[0];
|
name = self->var_name[0];
|
||||||
if (name == '*' || name == '@' || \
|
if (name == '*' || name == '@' || name == '?' || name == '!' || name == '#' || name == '-' || name == '$' || name == '0')
|
||||||
name == '?' || name == '!' || \
|
|
||||||
name == '#' || name == '-' || \
|
|
||||||
name == '$' || name == '0')
|
|
||||||
return (true);
|
return (true);
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
t_error _run_expansion_special_var(\
|
t_error _run_expansion_special_var(t_ast_expansion *self, t_state *state, t_expansion_result *out)
|
||||||
t_ast_expansion *self, t_state *state, t_expansion_result *out)
|
|
||||||
{
|
{
|
||||||
char name;
|
char name;
|
||||||
|
|
||||||
|
|
@ -100,19 +111,19 @@ t_error _handle_no_operator(t_ast_expansion *self, t_state *state, t_expansion_r
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
};
|
};
|
||||||
|
|
||||||
t_error _handle_assign_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_assign_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_assign_colon_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_assign_colon_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_alternate_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_alternate_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_alternate_colon_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_alternate_colon_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_default_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_default_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_default_colon_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_default_colon_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_error_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_error_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_error_colon_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_error_colon_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
|
|
||||||
t_error _handle_suffix_pattern_smallest_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_suffix_pattern_smallest_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_suffix_pattern_longest_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_suffix_pattern_largest_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_prefix_pattern_smallest_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_prefix_pattern_smallest_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
t_error _handle_prefix_pattern_longest_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
t_error _exp_prefix_pattern_largest_operator(t_ast_expansion *self, t_state *state, t_expansion_result *value) NOT_DONE;
|
||||||
|
|
||||||
t_error _get_op_func(t_ast_expansion *self, t_error (**op_func)(t_ast_expansion *self, t_state *state, t_expansion_result *value))
|
t_error _get_op_func(t_ast_expansion *self, t_error (**op_func)(t_ast_expansion *self, t_state *state, t_expansion_result *value))
|
||||||
{
|
{
|
||||||
|
|
@ -121,29 +132,29 @@ t_error _get_op_func(t_ast_expansion *self, t_error (**op_func)(t_ast_expansion
|
||||||
if (self->kind == E_OP_NONE)
|
if (self->kind == E_OP_NONE)
|
||||||
return (*op_func = _handle_no_operator, NO_ERROR);
|
return (*op_func = _handle_no_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_ERROR)
|
if (self->kind == E_OP_ERROR)
|
||||||
return (*op_func = _handle_error_operator, NO_ERROR);
|
return (*op_func = _exp_error_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_ERROR_COLON)
|
if (self->kind == E_OP_ERROR_COLON)
|
||||||
return (*op_func = _handle_error_colon_operator, NO_ERROR);
|
return (*op_func = _exp_error_colon_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_ASSIGN_DEFAULT)
|
if (self->kind == E_OP_ASSIGN_DEFAULT)
|
||||||
return (*op_func = _handle_assign_operator, NO_ERROR);
|
return (*op_func = _exp_assign_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_ASSIGN_DEFAULT_COLON)
|
if (self->kind == E_OP_ASSIGN_DEFAULT_COLON)
|
||||||
return (*op_func = _handle_assign_colon_operator, NO_ERROR);
|
return (*op_func = _exp_assign_colon_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_DEFAULT)
|
if (self->kind == E_OP_DEFAULT)
|
||||||
return (*op_func = _handle_default_operator, NO_ERROR);
|
return (*op_func = _exp_default_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_DEFAULT_COLON)
|
if (self->kind == E_OP_DEFAULT_COLON)
|
||||||
return (*op_func = _handle_default_colon_operator, NO_ERROR);
|
return (*op_func = _exp_default_colon_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_ALTERNATE)
|
if (self->kind == E_OP_ALTERNATE)
|
||||||
return (*op_func = _handle_alternate_operator, NO_ERROR);
|
return (*op_func = _exp_alternate_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_ALTERNATE_COLON)
|
if (self->kind == E_OP_ALTERNATE_COLON)
|
||||||
return (*op_func = _handle_alternate_colon_operator, NO_ERROR);
|
return (*op_func = _exp_alternate_colon_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_LARGEST_PREFIX)
|
if (self->kind == E_OP_LARGEST_PREFIX)
|
||||||
return (*op_func = _handle_prefix_pattern_smallest_operator, NO_ERROR);
|
return (*op_func = _exp_prefix_pattern_largest_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_SMALLEST_PREFIX)
|
if (self->kind == E_OP_SMALLEST_PREFIX)
|
||||||
return (*op_func = _handle_prefix_pattern_smallest_operator, NO_ERROR);
|
return (*op_func = _exp_prefix_pattern_smallest_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_LARGEST_SUFFIX)
|
if (self->kind == E_OP_LARGEST_SUFFIX)
|
||||||
return (*op_func = _handle_suffix_pattern_smallest_operator, NO_ERROR);
|
return (*op_func = _exp_suffix_pattern_largest_operator, NO_ERROR);
|
||||||
if (self->kind == E_OP_SMALLEST_SUFFIX)
|
if (self->kind == E_OP_SMALLEST_SUFFIX)
|
||||||
return (*op_func = _handle_suffix_pattern_longest_operator, NO_ERROR);
|
return (*op_func = _exp_suffix_pattern_smallest_operator, NO_ERROR);
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -511,8 +522,11 @@ t_error _spawn_cmd_and_run(t_vec_str args, t_vec_ast redirection, t_state *state
|
||||||
t_vec_str filename_args;
|
t_vec_str filename_args;
|
||||||
t_fd *red_fd;
|
t_fd *red_fd;
|
||||||
|
|
||||||
if (cmd_pipe.output)
|
info = (t_spawn_info){};
|
||||||
info.stdout = fd(cmd_pipe.output);
|
if (cmd_pipe.input)
|
||||||
|
info.stdin = fd(cmd_pipe.input);
|
||||||
|
if (cmd_pipe.create_output)
|
||||||
|
info.stdout = piped();
|
||||||
i = 0;
|
i = 0;
|
||||||
filename_args = vec_str_new(16, str_free);
|
filename_args = vec_str_new(16, str_free);
|
||||||
while (i < redirection.len)
|
while (i < redirection.len)
|
||||||
|
|
@ -533,7 +547,7 @@ t_error _spawn_cmd_and_run(t_vec_str args, t_vec_ast redirection, t_state *state
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
if (filename_args.len != 1)
|
if (filename_args.len != 1)
|
||||||
return (vec_str_free(filename_args), ERROR);
|
return (vec_str_free(filename_args), ERROR);
|
||||||
red_fd = open_fd(filename_args.buffer[i], FD_READ, 0 | O_CLOEXEC, 0);
|
red_fd = open_fd(filename_args.buffer[i], FD_READ, O_CLOEXEC, 0);
|
||||||
if (red_fd == NULL)
|
if (red_fd == NULL)
|
||||||
return (vec_str_free(filename_args), ERROR);
|
return (vec_str_free(filename_args), ERROR);
|
||||||
info.stdin = fd(red_fd);
|
info.stdin = fd(red_fd);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/07/23 22:07:26 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:58:07 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -83,4 +83,6 @@ build_filelist:
|
||||||
@echo "" >> Filelist.$(ANAME).mk
|
@echo "" >> Filelist.$(ANAME).mk
|
||||||
@echo -e '$(COL_GRAY) Populating $(COL_GREEN) Filelist.$(ANAME).mk$(END)'
|
@echo -e '$(COL_GRAY) Populating $(COL_GREEN) Filelist.$(ANAME).mk$(END)'
|
||||||
|
|
||||||
|
%.h: ;
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/07/30 14:52:58 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:57:50 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -77,4 +77,6 @@ build_filelist:
|
||||||
@echo "" >> Filelist.$(ANAME).mk
|
@echo "" >> Filelist.$(ANAME).mk
|
||||||
@echo -e '$(GREY) Populating $(GREEN) Filelist.$(ANAME).mk$(END)'
|
@echo -e '$(GREY) Populating $(GREEN) Filelist.$(ANAME).mk$(END)'
|
||||||
|
|
||||||
|
%.h: ;
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/07/23 21:53:53 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:57:55 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -91,4 +91,6 @@ build_filelist:
|
||||||
@echo "" >> Filelist.$(ANAME).mk
|
@echo "" >> Filelist.$(ANAME).mk
|
||||||
@echo -e '$(GREY) Populating $(GREEN) Filelist.$(ANAME).mk$(END)'
|
@echo -e '$(GREY) Populating $(GREEN) Filelist.$(ANAME).mk$(END)'
|
||||||
|
|
||||||
|
%.h: ;
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
|
||||||
|
|
@ -68,8 +68,8 @@ os/abort \
|
||||||
os/exit \
|
os/exit \
|
||||||
os/pipe \
|
os/pipe \
|
||||||
os/process \
|
os/process \
|
||||||
os/process_inner \
|
os/process_iterator_function \
|
||||||
os/process_inner2 \
|
os/process_redirection \
|
||||||
printf/callbacks \
|
printf/callbacks \
|
||||||
printf/formatter/char \
|
printf/formatter/char \
|
||||||
printf/formatter/decimal \
|
printf/formatter/decimal \
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
# By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# #
|
||||||
# Updated: 2024/07/23 21:49:24 by maiboyer ### ########.fr #
|
# Updated: 2024/08/02 18:57:39 by maiboyer ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -100,4 +100,6 @@ build_filelist:
|
||||||
@tree $(GEN_DIR) -ifF | rg '$(GEN_DIR)/(.*)\.c$$' --replace '$$1' | sed -re 's/^(.*)_([0-9]+)$$/\1|\2/g' | sort -t'|' --key=1,1 --key=2,2n | sed -e's/|/_/' | xargs printf '%-78s\\\n' >> Filelist.$(ANAME).mk
|
@tree $(GEN_DIR) -ifF | rg '$(GEN_DIR)/(.*)\.c$$' --replace '$$1' | sed -re 's/^(.*)_([0-9]+)$$/\1|\2/g' | sort -t'|' --key=1,1 --key=2,2n | sed -e's/|/_/' | xargs printf '%-78s\\\n' >> Filelist.$(ANAME).mk
|
||||||
@echo "" >> Filelist.$(ANAME).mk
|
@echo "" >> Filelist.$(ANAME).mk
|
||||||
|
|
||||||
|
%.h: ;
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
/* Created: 2024/01/03 16:22:41 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/08/01 07:14:29 by maiboyer ### ########.fr */
|
/* Updated: 2024/08/02 19:11:00 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -21,9 +21,8 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
bool find_path(const t_str *s);
|
bool _find_path(const t_str *s);
|
||||||
bool find_null(const t_str *s);
|
bool _find_null(const t_str *s);
|
||||||
bool str_start_with(t_const_str s, t_const_str prefix);
|
|
||||||
t_error handle_redirections(t_spawn_info *info, t_process *process);
|
t_error handle_redirections(t_spawn_info *info, t_process *process);
|
||||||
|
|
||||||
t_error spawn_process_exec(t_spawn_info info, t_process *process)
|
t_error spawn_process_exec(t_spawn_info info, t_process *process)
|
||||||
|
|
@ -41,10 +40,10 @@ t_error spawn_process_exec(t_spawn_info info, t_process *process)
|
||||||
close_fd(info.stdin.fd.fd);
|
close_fd(info.stdin.fd.fd);
|
||||||
close_fd(info.stdout.fd.fd);
|
close_fd(info.stdout.fd.fd);
|
||||||
close_fd(info.stderr.fd.fd);
|
close_fd(info.stderr.fd.fd);
|
||||||
if (!vec_str_any(&info.arguments, find_null, &res) && res)
|
if (!vec_str_any(&info.arguments, _find_null, &res) && res)
|
||||||
vec_str_push(&info.arguments, NULL);
|
vec_str_push(&info.arguments, NULL);
|
||||||
res = false;
|
res = false;
|
||||||
if (!vec_str_any(&info.environement, find_null, &res) && res)
|
if (!vec_str_any(&info.environement, _find_null, &res) && res)
|
||||||
vec_str_push(&info.environement, NULL);
|
vec_str_push(&info.environement, NULL);
|
||||||
execve(info.binary_path, info.arguments.buffer, info.environement.buffer);
|
execve(info.binary_path, info.arguments.buffer, info.environement.buffer);
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
|
|
@ -79,12 +78,11 @@ t_error find_binary(t_spawn_info *info, t_process *process)
|
||||||
if (info->binary_path == NULL)
|
if (info->binary_path == NULL)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
s = string_new(256);
|
s = string_new(256);
|
||||||
if (str_start_with(info->binary_path, "/")
|
if (str_find_chr(info->binary_path, '/') != NULL)
|
||||||
|| str_find_chr(info->binary_path, '/') != NULL)
|
|
||||||
string_push(&s, info->binary_path);
|
string_push(&s, info->binary_path);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (vec_str_find(&info->environement, find_path, &p_idx))
|
if (vec_str_find(&info->environement, _find_path, &p_idx))
|
||||||
return (string_free(s), ERROR);
|
return (string_free(s), ERROR);
|
||||||
if (in_path(info, process, info->environement.buffer[p_idx], &s))
|
if (in_path(info, process, info->environement.buffer[p_idx], &s))
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
|
|
@ -98,7 +96,8 @@ t_error find_binary(t_spawn_info *info, t_process *process)
|
||||||
return (string_free(s), ERROR);
|
return (string_free(s), ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup(t_spawn_info info, t_process *process, bool cleanup_process)
|
static void _process_cleanup(t_spawn_info info, t_process *process, \
|
||||||
|
bool cleanup_process)
|
||||||
{
|
{
|
||||||
if (cleanup_process && process->stdin)
|
if (cleanup_process && process->stdin)
|
||||||
close_fd(process->stdin);
|
close_fd(process->stdin);
|
||||||
|
|
@ -116,16 +115,18 @@ static void cleanup(t_spawn_info info, t_process *process, bool cleanup_process)
|
||||||
|
|
||||||
t_error spawn_process(t_spawn_info info, t_process *process)
|
t_error spawn_process(t_spawn_info info, t_process *process)
|
||||||
{
|
{
|
||||||
|
if (process == NULL)
|
||||||
|
return (ERROR);
|
||||||
if (handle_redirections(&info, process))
|
if (handle_redirections(&info, process))
|
||||||
return (cleanup(info, process, true), ERROR);
|
return (_process_cleanup(info, process, true), ERROR);
|
||||||
if (find_binary(&info, process))
|
if (find_binary(&info, process))
|
||||||
return (cleanup(info, process, true), ERROR);
|
return (_process_cleanup(info, process, true), ERROR);
|
||||||
process->pid = fork();
|
process->pid = fork();
|
||||||
if (process->pid == 0)
|
if (process->pid == 0)
|
||||||
(spawn_process_exec(info, process), exit(1));
|
(spawn_process_exec(info, process), exit(1));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cleanup(info, process, false);
|
_process_cleanup(info, process, false);
|
||||||
if (process->pid == -1)
|
if (process->pid == -1)
|
||||||
return (ERROR);
|
return (ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* process_inner2.c :+: :+: :+: */
|
/* process_redirection.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/01/04 22:27:00 by maiboyer #+# #+# */
|
/* Created: 2024/01/04 22:27:00 by maiboyer #+# #+# */
|
||||||
/* Updated: 2024/08/01 07:14:10 by maiboyer ### ########.fr */
|
/* Updated: 2024/08/02 19:10:51 by maiboyer ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
#include "me/os/os.h"
|
#include "me/os/os.h"
|
||||||
#include "me/types.h"
|
#include "me/types.h"
|
||||||
|
|
||||||
void handle_redirections_inherited(t_spawn_info *info, t_process *process)
|
t_error _handle_redirections_inherited(t_spawn_info *info, t_process *process)
|
||||||
{
|
{
|
||||||
(void)(process);
|
(void)(process);
|
||||||
if (info->stdin.tag == R_INHERITED)
|
if (info->stdin.tag == R_INHERITED)
|
||||||
|
|
@ -32,9 +32,10 @@ void handle_redirections_inherited(t_spawn_info *info, t_process *process)
|
||||||
info->stderr = fd(dup_fd(get_stderr()));
|
info->stderr = fd(dup_fd(get_stderr()));
|
||||||
process->stderr = dup_fd(get_stderr());
|
process->stderr = dup_fd(get_stderr());
|
||||||
}
|
}
|
||||||
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_redirections_fds(t_spawn_info *info, t_process *process)
|
t_error _handle_redirections_fds(t_spawn_info *info, t_process *process)
|
||||||
{
|
{
|
||||||
if (info->stdin.tag == R_FD)
|
if (info->stdin.tag == R_FD)
|
||||||
{
|
{
|
||||||
|
|
@ -51,22 +52,13 @@ void handle_redirections_fds(t_spawn_info *info, t_process *process)
|
||||||
info->stderr = fd(dup_fd(info->stderr.fd.fd));
|
info->stderr = fd(dup_fd(info->stderr.fd.fd));
|
||||||
process->stderr = dup_fd(info->stderr.fd.fd);
|
process->stderr = dup_fd(info->stderr.fd.fd);
|
||||||
}
|
}
|
||||||
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void redirection_inner(t_spawn_info *info, t_process *process)
|
t_error _handle_redirections_pipe(t_spawn_info *info, t_process *process)
|
||||||
{
|
|
||||||
process->stderr = NULL;
|
|
||||||
process->stdout = NULL;
|
|
||||||
process->stdin = NULL;
|
|
||||||
handle_redirections_fds(info, process);
|
|
||||||
handle_redirections_inherited(info, process);
|
|
||||||
}
|
|
||||||
|
|
||||||
t_error handle_redirections(t_spawn_info *info, t_process *process)
|
|
||||||
{
|
{
|
||||||
t_pipe pipe_fd;
|
t_pipe pipe_fd;
|
||||||
|
|
||||||
redirection_inner(info, process);
|
|
||||||
if (info->stdin.tag == R_PIPED)
|
if (info->stdin.tag == R_PIPED)
|
||||||
{
|
{
|
||||||
if (create_pipe(&pipe_fd))
|
if (create_pipe(&pipe_fd))
|
||||||
|
|
@ -90,3 +82,17 @@ t_error handle_redirections(t_spawn_info *info, t_process *process)
|
||||||
}
|
}
|
||||||
return (NO_ERROR);
|
return (NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t_error handle_redirections(t_spawn_info *info, t_process *process)
|
||||||
|
{
|
||||||
|
process->stderr = NULL;
|
||||||
|
process->stdout = NULL;
|
||||||
|
process->stdin = NULL;
|
||||||
|
if (_handle_redirections_fds(info, process))
|
||||||
|
return (ERROR);
|
||||||
|
if (_handle_redirections_inherited(info, process))
|
||||||
|
return (ERROR);
|
||||||
|
if (_handle_redirections_pipe(info, process))
|
||||||
|
return (ERROR);
|
||||||
|
return (NO_ERROR);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue