From a9fde3bad1969d50c97ae9a0c08947ec1e9c1e95 Mon Sep 17 00:00:00 2001 From: tomoron Date: Wed, 27 Mar 2024 16:23:09 +0100 Subject: [PATCH] t_cmd => t_token (parce que c'est plus logique aussi) --- srcs/cd.c | 4 ++-- srcs/commands.c | 16 ++++++++-------- srcs/debug.c | 4 ++-- srcs/echo.c | 6 +++--- srcs/exit.c | 6 +++--- srcs/input_redirections.c | 10 +++++----- srcs/lst_cmd.c | 8 ++++---- srcs/main.c | 2 +- srcs/minishell.h | 28 ++++++++++++++-------------- srcs/output_redirections.c | 8 ++++---- srcs/signal_handler.c | 17 +++++++++-------- 11 files changed, 55 insertions(+), 54 deletions(-) diff --git a/srcs/cd.c b/srcs/cd.c index 5fe80b9..85df981 100644 --- a/srcs/cd.c +++ b/srcs/cd.c @@ -6,13 +6,13 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */ -/* Updated: 2024/03/27 14:49:28 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 16:21:48 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int cd(t_cmd *args) +int cd(t_token *args) { char *new_wd; diff --git a/srcs/commands.c b/srcs/commands.c index 7b82f0a..b1ccc9b 100644 --- a/srcs/commands.c +++ b/srcs/commands.c @@ -6,16 +6,16 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */ -/* Updated: 2024/03/27 14:59:43 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 16:20:06 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int get_cmd_count(t_cmd *cmds) +int get_cmd_count(t_token *cmds) { int count; - t_cmd *cur_cmd; + t_token *cur_cmd; count = 0; cur_cmd = cmds; @@ -31,10 +31,10 @@ int get_cmd_count(t_cmd *cmds) return (count); } -int get_args_count(t_cmd *cmds) +int get_args_count(t_token *cmds) { int count; - t_cmd *cur_cmd; + t_token *cur_cmd; count = 0; cur_cmd = cmds; @@ -56,7 +56,7 @@ int get_args_count(t_cmd *cmds) char **get_cmd_args(t_msh *msh) { char **cmd_args; - t_cmd *cur_cmd; + t_token *cur_cmd; int args_count; int i; @@ -85,8 +85,8 @@ char **get_cmd_args(t_msh *msh) void remove_command_from_msh(t_msh *msh) { - t_cmd *cur_cmd; - t_cmd *cmd_tmp; + t_token *cur_cmd; + t_token *cmd_tmp; cur_cmd = msh->cmds; while (cur_cmd && cur_cmd->next) diff --git a/srcs/debug.c b/srcs/debug.c index 4d81fef..8c91d85 100644 --- a/srcs/debug.c +++ b/srcs/debug.c @@ -6,13 +6,13 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */ -/* Updated: 2024/03/27 14:56:35 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 16:21:24 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void print_parsed_cmd(t_cmd *cmd) +void print_parsed_cmd(t_token *cmd) { while (cmd) { diff --git a/srcs/echo.c b/srcs/echo.c index a612bb3..d7b7357 100755 --- a/srcs/echo.c +++ b/srcs/echo.c @@ -6,14 +6,14 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */ -/* Updated: 2024/03/27 14:55:08 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 16:21:14 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" #include -void put_args(t_cmd *args) +void put_args(t_token *args) { int first; @@ -33,7 +33,7 @@ void put_args(t_cmd *args) } } -int echo(t_cmd *args) +int echo(t_token *args) { int put_nl; int i; diff --git a/srcs/exit.c b/srcs/exit.c index 4b0e20f..2ec9513 100755 --- a/srcs/exit.c +++ b/srcs/exit.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 16:04:11 by tomoron #+# #+# */ -/* Updated: 2024/03/27 14:51:02 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 15:35:57 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ void numeric_arg_err(char *arg, int *exit_code) void get_exit_bt_return_code(t_msh *msh, int *exit_code) { - t_cmd *cur_cmd; + t_token *cur_cmd; cur_cmd = msh->cmds->next; if (cur_cmd && cur_cmd->type == ARG && !ft_strisnbr(cur_cmd->value)) @@ -35,7 +35,7 @@ void get_exit_bt_return_code(t_msh *msh, int *exit_code) void exit_bt(t_msh *msh) { - t_cmd *cur_cmd; + t_token *cur_cmd; int exit_code; int cmd_count; diff --git a/srcs/input_redirections.c b/srcs/input_redirections.c index 35de174..9636109 100644 --- a/srcs/input_redirections.c +++ b/srcs/input_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */ -/* Updated: 2024/03/27 14:58:15 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 16:20:41 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,7 +27,7 @@ void redirect_input(t_msh *msh, int i) } } -void open_input_file(t_msh *msh, t_cmd **cur_cmd) +void open_input_file(t_msh *msh, t_token **cur_cmd) { if ((*cur_cmd)->type == HERE_DOC) handle_here_doc(msh, (*cur_cmd)->next->value); @@ -45,9 +45,9 @@ void open_input_file(t_msh *msh, t_cmd **cur_cmd) } } -void get_in_type(t_msh *msh, t_cmd *cmds) +void get_in_type(t_msh *msh, t_token *cmds) { - t_cmd *cur_cmd; + t_token *cur_cmd; cur_cmd = cmds; while (cur_cmd && cur_cmd->next && cur_cmd->type == ARG) @@ -67,7 +67,7 @@ void get_in_type(t_msh *msh, t_cmd *cmds) int first_is_in_type(t_msh *msh) { - t_cmd *cur_cmd; + t_token *cur_cmd; cur_cmd = msh->cmds; while (cur_cmd && cur_cmd->type == ARG && cur_cmd->next) diff --git a/srcs/lst_cmd.c b/srcs/lst_cmd.c index a49f34d..ff04eec 100755 --- a/srcs/lst_cmd.c +++ b/srcs/lst_cmd.c @@ -6,18 +6,18 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ -/* Updated: 2024/03/27 14:48:50 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 15:56:11 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -t_cmd *cmd_add_back(t_cmd *cmd, char *value, t_token_type type) +t_cmd *cmd_add_back(t_token *cmd, char *value, t_token_type type) { t_cmd *res; t_cmd *current; - res = ft_calloc(1, sizeof(t_cmd)); + res = ft_calloc(1, sizeof(t_token)); if (!res) return (cmd); res->value = value; @@ -31,7 +31,7 @@ t_cmd *cmd_add_back(t_cmd *cmd, char *value, t_token_type type) return (cmd); } -void free_cmd(t_cmd *cmd) +void free_cmd(t_token *cmd) { if (cmd) { diff --git a/srcs/main.c b/srcs/main.c index 3ed0347..3af54e7 100755 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ -/* Updated: 2024/03/26 17:25:20 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 15:05:42 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/minishell.h b/srcs/minishell.h index 6db58b9..64b1411 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/03/27 14:46:04 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 15:24:41 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,12 +35,12 @@ typedef enum e_token_type HERE_DOC, } t_token_type; -typedef struct s_cmd +typedef struct s_token { t_token_type type; char *value; - struct s_cmd *next; -} t_cmd; + struct s_token *next; +} t_token; typedef struct s_env { @@ -65,26 +65,26 @@ typedef struct s_msh extern int g_return_code; -t_cmd *cmd_add_back(t_cmd *res, char *token, t_token_type type); -void free_cmd(t_cmd *cmd); +t_token *cmd_add_back(t_token *res, char *token, t_token_type type); +void free_cmd(t_token *cmd); void exec_commands(t_msh *msh); -int echo(t_cmd *args); +int echo(t_token *args); void exit_bt(t_msh *msh); t_env *env_add_back(t_env *env, char *name, char *value); void free_env(t_env *env); int print_env(t_env *env); -t_cmd *parse_command(char *command, t_env *env); +t_token *parse_command(char *command, t_env *env); int get_token_len(char *cmd, t_env *env); int add_var_to_str(char *res, char **command, t_env *env); int get_var_name_len(char *command); char *ft_get_env(t_env *env, char *var_name); int pwd(void); int is_cmd_char(char c); -void print_parsed_cmd(t_cmd *cmd);//debug +void print_parsed_cmd(t_token *cmd);//debug void ft_exit(t_msh *msh, int error_code); char **env_to_char_tab(t_env *env); void handle_minishellrc(t_msh *msh); -int cd(t_cmd *args); +int cd(t_token *args); int ft_export(t_msh *msh); void free_msh(t_msh *msh); char **split_paths_from_env(t_env *env); @@ -92,8 +92,8 @@ void find_cmd_path(t_msh *msh, char **paths, int *found); void get_cmd_path(t_msh *msh); void handle_here_doc(t_msh *msh, char *eof); int ft_unset(t_msh *msh); -void get_in_type(t_msh *msh, t_cmd *cmds); -void get_out_type(t_msh *msh, t_cmd *cmds); +void get_in_type(t_msh *msh, t_token *cmds); +void get_out_type(t_msh *msh, t_token *cmds); int first_is_in_type(t_msh *msh); void redirect_input(t_msh *msh, int i); void redirect_output(t_msh *msh, int i); @@ -103,8 +103,8 @@ void free_msh(t_msh *msh); void ft_exit(t_msh *msh, int exit_code); int cmd_is_builtin(t_msh *msh, char *cmd_token); int exec_builtin(t_msh *msh); -int get_cmd_count(t_cmd *cmds); -int get_args_count(t_cmd *cmds); +int get_cmd_count(t_token *cmds); +int get_args_count(t_token *cmds); char **get_cmd_args(t_msh *msh); void remove_command_from_msh(t_msh *msh); int file_access(t_msh *msh, int *found); diff --git a/srcs/output_redirections.c b/srcs/output_redirections.c index 1430b31..590cdab 100644 --- a/srcs/output_redirections.c +++ b/srcs/output_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */ -/* Updated: 2024/03/27 14:58:29 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 16:21:56 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ void redirect_output(t_msh *msh, int i) } } -void open_out_file(t_msh *msh, t_cmd **cur_cmd) +void open_out_file(t_msh *msh, t_token **cur_cmd) { msh->out_type = (*cur_cmd)->type; if (msh->out_type == RED_O) @@ -51,9 +51,9 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd) } } -void get_out_type(t_msh *msh, t_cmd *cmds) +void get_out_type(t_msh *msh, t_token *cmds) { - t_cmd *cur_cmd; + t_token *cur_cmd; msh->out_type = ARG; msh->out_fd = 0; diff --git a/srcs/signal_handler.c b/srcs/signal_handler.c index 4a72cea..738990b 100644 --- a/srcs/signal_handler.c +++ b/srcs/signal_handler.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ -/* Updated: 2024/03/26 17:59:37 by tomoron ### ########.fr */ +/* Updated: 2024/03/27 16:22:39 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,27 +53,28 @@ void signal_handler_here_doc(int signum) ft_exit(msh, 1); } } + int set_echoctl(int value) { struct termios t_p; - if(tcgetattr(1, &t_p)) + if (tcgetattr(1, &t_p)) { ft_printf_fd(2, "minishell: an error occured while setting the local fl\ ags"); - return(1); + return (1); } - if(value) + if (value) t_p.c_lflag = t_p.c_lflag | ECHOCTL; else t_p.c_lflag = t_p.c_lflag & (~ECHOCTL); - if(tcsetattr(1, TCSANOW, &t_p)) + if (tcsetattr(1, TCSANOW, &t_p)) { ft_printf_fd(2, "minishell: an error occured while setting the local fl\ - ags"); - return(1); +ags"); + return (1); } - return(0); + return (0); } void signal_handler_command(int signum) {