From fb62d4ceedd0d64b16331d49ebf82bfbde0fcfb3 Mon Sep 17 00:00:00 2001 From: mdev9 Date: Thu, 18 Apr 2024 21:50:23 +0200 Subject: [PATCH] i think i never speedran the norm like this before --- Makefile | 2 +- srcs/builtins.c | 2 +- srcs/cd.c | 2 +- srcs/commands.c | 12 ++++---- srcs/debug.c | 22 ++++++------- srcs/echo.c | 2 +- srcs/env_utils.c | 2 +- srcs/exec.c | 2 +- srcs/exec_bonus.c | 16 +++++----- srcs/exit.c | 2 +- srcs/export.c | 6 ++-- srcs/here_doc.c | 4 +-- srcs/here_doc_utils.c | 2 +- srcs/input_redirections.c | 19 ++++++------ srcs/is_fd_open.c | 2 +- srcs/lst_cmd.c | 2 +- srcs/lst_env.c | 2 +- srcs/lst_token.c | 2 +- srcs/main.c | 11 ++++--- srcs/output_redirections.c | 28 +++++++++-------- srcs/parsing.c | 12 ++++---- srcs/parsing_bonus.c | 4 +-- srcs/parsing_var.c | 4 +-- srcs/path.c | 2 +- srcs/pipe.c | 32 +++++++++---------- srcs/pwd.c | 2 +- srcs/signal_handler.c | 12 ++++---- srcs/sort_wildcard_list.c | 29 +++++++++--------- srcs/utils.c | 4 +-- srcs/utils_bonus.c | 18 +++++------ srcs/wildcards.c | 63 +++++++++++++++++++------------------- todo_list | 3 ++ 32 files changed, 169 insertions(+), 158 deletions(-) diff --git a/Makefile b/Makefile index 5f049b6..aecf953 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: marde-vr +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# # -# Updated: 2024/04/17 10:13:40 by tomoron ### ########.fr # +# Updated: 2024/04/18 20:36:38 by marde-vr ### ########.fr # # # # **************************************************************************** # diff --git a/srcs/builtins.c b/srcs/builtins.c index aff406b..d9e8d94 100755 --- a/srcs/builtins.c +++ b/srcs/builtins.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */ -/* Updated: 2024/04/07 17:14:57 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:48 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/cd.c b/srcs/cd.c index 80e9711..94ac531 100755 --- a/srcs/cd.c +++ b/srcs/cd.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/16 21:02:54 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 17:56:04 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:50 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/commands.c b/srcs/commands.c index 4b2e082..b353fde 100755 --- a/srcs/commands.c +++ b/srcs/commands.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */ -/* Updated: 2024/04/17 18:29:07 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:51 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,17 +60,17 @@ char **get_cmd_args(t_msh *msh) void remove_command_from_msh(t_msh *msh) { - t_cmd *tmp; + t_cmd *tmp; free_token(msh->tokens); - while(msh->cmds && !is_cmd_type(msh->cmds)) + while (msh->cmds && !is_cmd_type(msh->cmds)) msh->cmds = msh->cmds->next; - while(msh->cmds && is_cmd_type(msh->cmds)) + while (msh->cmds && is_cmd_type(msh->cmds)) msh->cmds = msh->cmds->next; tmp = msh->cmds; - while(tmp && !is_cmd_type(tmp)) + while (tmp && !is_cmd_type(tmp)) tmp = tmp->next; - if(tmp) + if (tmp) msh->tokens = parse_command(tmp->value, msh->env); else msh->tokens = 0; diff --git a/srcs/debug.c b/srcs/debug.c index 6005460..91ee9cd 100755 --- a/srcs/debug.c +++ b/srcs/debug.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */ -/* Updated: 2024/04/07 17:27:45 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:51 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,29 +24,29 @@ void print_parsed_token(t_token *token) void print_cmd_type(t_cmd_type type, char *value) { - if(type == CMD) + if (type == CMD) printf("[CMD : %s] ", value); - if(type == PAREN) + if (type == PAREN) printf("[PAREN : %s] ", value); - if(type == AND) + if (type == AND) printf("[AND] "); - if(type == OR) + if (type == OR) printf("[OR] "); - if(type == PIPE) + if (type == PIPE) printf("[PIPE] "); - if(type == RED_O_APP) + if (type == RED_O_APP) printf("[RED_O_APP : %s] ", value); - if(type == RED_O) + if (type == RED_O) printf("[RED_O : %s] ", value); - if(type == RED_I) + if (type == RED_I) printf("[RED_I : %s] ", value); - if(type == HERE_DOC) + if (type == HERE_DOC) printf("[HERE_DOC : %s] ", value); } void print_parsed_cmd(t_cmd *cmd) { - while(cmd) + while (cmd) { print_cmd_type(cmd->cmd_type, cmd->value); cmd = cmd->next; diff --git a/srcs/echo.c b/srcs/echo.c index 2f1c08f..ad4c7b2 100755 --- a/srcs/echo.c +++ b/srcs/echo.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 15:30:37 by tomoron #+# #+# */ -/* Updated: 2024/04/02 00:44:56 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/env_utils.c b/srcs/env_utils.c index 8301200..98c5ee6 100755 --- a/srcs/env_utils.c +++ b/srcs/env_utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/16 13:30:18 by tomoron #+# #+# */ -/* Updated: 2024/03/26 08:49:12 by marde-vr ### ########.fr */ +/* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/exec.c b/srcs/exec.c index a4ecebc..bfcb4c1 100755 --- a/srcs/exec.c +++ b/srcs/exec.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */ -/* Updated: 2024/04/03 17:21:57 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:52 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 9ff9011..6e48798 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/04/18 18:29:10 by marde-vr ### ########.fr */ +/* Updated: 2024/04/18 21:06:26 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,12 +36,12 @@ void exec_command_bonus(t_msh *msh, char *cmd_str) t_cmd *tmp; cmds = parsing_bonus(cmd_str); - print_parsed_cmd(cmds); // debug + //print_parsed_cmd(cmds); // debug tmp = check_cmds_syntax(cmds); if (tmp) { print_syntax_error_bonus(tmp); - printf("error\n"); // debug + //printf("error\n"); // debug free_cmd(cmds); return ; } @@ -72,13 +72,13 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count) if (i != cmd_count - 1) { - fprintf(stderr, "piping %d", i); + //fprintf(stderr, "piping %d", i); if (pipe(msh->fds[i]) == -1) { perror("minishell: pipe"); ft_exit(msh, 1); } - fprintf(stderr, "pipe: msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][1]); + //fprintf(stderr, "pipe: msh->fds[%d][0]: %d, msh->fds[%d][1]: %d\n", i, msh->fds[i][0], i, msh->fds[i][1]); } pid = fork(); if (pid == -1) @@ -99,7 +99,7 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count) void exec_command(t_msh *msh, int i, int cmd_count) { - g_return_code = 0; + //g_return_code = 0; msh->fds[i] = ft_calloc(2, sizeof(int *)); if (!msh->fds[i]) ft_exit(msh, 1); @@ -153,7 +153,7 @@ void exec_commands(t_msh *msh) if (!msh->tokens) return ; cmd_count = get_cmd_count(msh->cmds); - printf("cmd_count : %d\n", cmd_count); + //printf("cmd_count : %d\n", cmd_count); msh->fds = ft_calloc(cmd_count, sizeof(int **)); msh->pids = ft_calloc(cmd_count, sizeof(int *)); if (!msh->pids || !msh->fds) @@ -162,7 +162,7 @@ void exec_commands(t_msh *msh) while (i < cmd_count) { get_redirections(msh, msh->cmds); - fprintf(stderr, "command: %s, in_type: %d, out_type: %d\n", msh->cmds->value, msh->in_type, msh->out_type); + //fprintf(stderr, "command: %s, in_type: %d, out_type: %d\n", msh->cmds->value, msh->in_type, msh->out_type); exec_command(msh, i, cmd_count); //free(msh->fds[i]); i++; diff --git a/srcs/exit.c b/srcs/exit.c index 9ebc43f..e9f6427 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/04/03 15:44:06 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:53 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/export.c b/srcs/export.c index fa03433..509579d 100755 --- a/srcs/export.c +++ b/srcs/export.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */ -/* Updated: 2024/04/03 15:45:32 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:53 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,8 +61,8 @@ int ft_export(t_msh *msh) value = ft_strdup(arg + len); msh->env = env_add_back(msh->env, name, value); } -//export += -//replacer si ça existe deja sauf si il y a pas de = + //export += + //replacer si ça existe deja sauf si il y a pas de = return (0); } diff --git a/srcs/here_doc.c b/srcs/here_doc.c index 45c54d8..42e6e13 100755 --- a/srcs/here_doc.c +++ b/srcs/here_doc.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/24 17:44:32 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:53 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,7 +50,7 @@ void here_doc_child(t_msh *msh, char *eof, char *here_doc_file) void here_doc_signal(t_msh *msh, int child_pid, char *here_doc_file) { - int status; + int status; //signal(SIGINT, signal_handler_command); signal(SIGQUIT, signal_handler_here_doc); diff --git a/srcs/here_doc_utils.c b/srcs/here_doc_utils.c index bd4ba01..c098368 100755 --- a/srcs/here_doc_utils.c +++ b/srcs/here_doc_utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/26 09:06:51 by marde-vr #+# #+# */ -/* Updated: 2024/03/26 09:07:42 by marde-vr ### ########.fr */ +/* Updated: 2024/04/18 20:48:54 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/input_redirections.c b/srcs/input_redirections.c index 0b8c1a9..bea735d 100755 --- 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/04/18 18:25:20 by marde-vr ### ########.fr */ +/* Updated: 2024/04/18 20:48:54 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,15 +16,15 @@ void redirect_input(t_msh *msh, int i) { if (msh->in_type != PIPE) { - fprintf(stderr, "redirecting input\n"); + //fprintf(stderr, "redirecting input\n"); if (dup2(msh->in_fd, 0) < 0) ft_exit(msh, 1); close(msh->in_fd); } else { - fprintf(stderr, "redirecting pipe input\n"); - fprintf(stderr, "input of cmd %d: %d -> 0\n", i, msh->fds[i - 1][0]); + //fprintf(stderr, "redirecting pipe input\n"); + //fprintf(stderr, "input of cmd %d: %d -> 0\n", i, msh->fds[i - 1][0]); if (dup2(msh->fds[i - 1][0], 0) < 0) { perror("dup2"); //debug @@ -35,7 +35,7 @@ void redirect_input(t_msh *msh, int i) void open_input_file(t_msh *msh, t_cmd **cur_token) { - t_token *filename; + t_token *filename; if ((*cur_token)->cmd_type == HERE_DOC) handle_here_doc(msh, (*cur_token)->value); @@ -44,7 +44,7 @@ void open_input_file(t_msh *msh, t_cmd **cur_token) if (msh->in_fd != 0) close(msh->in_fd); filename = parse_command((*cur_token)->value, msh->env); - if(!filename) + if (!filename) ft_exit(msh, 1); msh->in_fd = open(filename->value, O_RDONLY); free_token(filename); @@ -67,14 +67,15 @@ void get_in_type(t_msh *msh, t_cmd *tokens) msh->in_type = PIPE; return ; } - while (cur_token && (cur_token->cmd_type == CMD || cur_token->cmd_type == PAREN)) + while (cur_token && (cur_token->cmd_type == CMD + || cur_token->cmd_type == PAREN)) cur_token = cur_token->next; if (cur_token && is_input_type(cur_token)) { msh->in_type = cur_token->cmd_type; open_input_file(msh, &cur_token); } - if(cur_token && cur_token->next && !is_operand_type(cur_token->next)) + if (cur_token && cur_token->next && !is_operand_type(cur_token->next)) get_in_type(msh, cur_token->next); } @@ -85,7 +86,7 @@ int first_is_in_type(t_cmd *cmd) cur_token = cmd; while (cur_token && cur_token->cmd_type == CMD && cur_token->next) cur_token = cur_token->next; - if ( is_input_type(cur_token) || cur_token->cmd_type == PIPE) + if (is_input_type(cur_token) || cur_token->cmd_type == PIPE) return (1); return (0); } diff --git a/srcs/is_fd_open.c b/srcs/is_fd_open.c index 86b2070..ab6e75a 100644 --- a/srcs/is_fd_open.c +++ b/srcs/is_fd_open.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 17:31:53 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:54 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/lst_cmd.c b/srcs/lst_cmd.c index ed9309d..d6ce291 100755 --- a/srcs/lst_cmd.c +++ b/srcs/lst_cmd.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ -/* Updated: 2024/03/29 14:30:00 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:55 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/lst_env.c b/srcs/lst_env.c index a1e2ce3..2dd75d0 100755 --- a/srcs/lst_env.c +++ b/srcs/lst_env.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ -/* Updated: 2024/02/17 04:33:17 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:55 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/lst_token.c b/srcs/lst_token.c index d0ded65..ceff6d0 100755 --- a/srcs/lst_token.c +++ b/srcs/lst_token.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/06 20:46:19 by tomoron #+# #+# */ -/* Updated: 2024/04/02 00:44:16 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:56 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/main.c b/srcs/main.c index 6f2d404..0783daf 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/04/17 14:24:31 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:57:00 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,7 +83,7 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp) (*msh)->env = get_env(envp); tcgetattr(1, &t_p); (*msh)->echoctl = t_p.c_lflag & ECHOCTL; -// signal(SIGINT, signal_handler_interactive); //enables ctrl-C + // signal(SIGINT, signal_handler_interactive); //enables ctrl-C signal(SIGQUIT, signal_handler_interactive); if (set_echoctl(0)) ft_exit(*msh, 1); @@ -96,6 +96,9 @@ int main(int argc, char **argv, char **envp) char *commands; char *prompt; t_msh *msh; + char *commands; + char *prompt; + t_msh *msh; commands = (char *)1; init_minishell(&msh, argc, argv, envp); @@ -121,7 +124,7 @@ int main(int argc, char **argv, char **envp) return (g_return_code); }*/ -int main(int argc, char **argv, char **envp) +int main(int argc, char **argv, char **envp) { char *commands; char *prompt; @@ -139,5 +142,5 @@ int main(int argc, char **argv, char **envp) add_history(commands); exec_command_bonus(msh, commands); free(commands); - } + } } diff --git a/srcs/output_redirections.c b/srcs/output_redirections.c index 5baf346..02a2bd3 100755 --- 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/04/18 17:56:05 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,18 +17,18 @@ void redirect_output(t_msh *msh, int i) { if (msh->out_type != PIPE) { - fprintf(stderr, "redirecting output\n"); + //fprintf(stderr, "redirecting output\n"); if (dup2(msh->out_fd, 1) < 0) ft_exit(msh, 1); } else { - fprintf(stderr, "redirecting pipe output\n"); + //fprintf(stderr, "redirecting pipe output\n"); //sleep(1); if (dup2(msh->fds[i][1], 1) < 0) { perror("dup2"); - fprintf(stderr, "exiting\n"); + //fprintf(stderr, "exiting\n"); //ft_exit(msh, 1); } } @@ -59,31 +59,33 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename) void get_out_type(t_msh *msh, t_cmd *cmds) { t_cmd *cur_cmd; - t_token *filename; + t_token *filename; msh->out_type = CMD; msh->out_fd = 0; cur_cmd = cmds; - while(cur_cmd && !is_cmd_type(cur_cmd)) + while (cur_cmd && !is_cmd_type(cur_cmd)) cur_cmd = cur_cmd->next; - while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) + while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd) + && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) { - fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type); + //fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type); cur_cmd = cur_cmd->next; } - if (cur_cmd) - fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type); + //if (cur_cmd) + //fprintf(stderr, "%s: %d\n", cur_cmd->value, cur_cmd->cmd_type); if (cur_cmd->cmd_type == CMD || cur_cmd->cmd_type == PAREN) msh->out_type = 0; - else if(cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) + else if (cur_cmd && is_output_type(cur_cmd) && !is_operand_type(cur_cmd) + && cur_cmd->cmd_type != PIPE) { msh->out_type = cur_cmd->cmd_type; filename = parse_command(cur_cmd->value, msh->env); - if(!filename) + if (!filename) ft_exit(msh, 1); open_out_file(msh, &cur_cmd, filename->value); free_token(filename); } - else if(cur_cmd && cur_cmd->cmd_type == PIPE) + else if (cur_cmd && cur_cmd->cmd_type == PIPE) msh->out_type = PIPE; } diff --git a/srcs/parsing.c b/srcs/parsing.c index 7d17cf1..fce7084 100755 --- a/srcs/parsing.c +++ b/srcs/parsing.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/04/15 15:56:17 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -51,7 +51,7 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) else if (**cmd == '~' && !*in_quote && !*in_dquote) i += add_home_to_str(res + i); else if (((**cmd == '\'' && *in_dquote) || (**cmd == '"' && *in_quote)) - || (**cmd != '\'' && **cmd != '"')) + || (**cmd != '\'' && **cmd != '"')) res[i++] = **cmd; (*cmd)++; } @@ -60,10 +60,10 @@ char *get_token(char **cmd, int *in_quote, int *in_dquote, t_env *env) t_token *parse_command(char *command, t_env *env) { - int in_quote; - int in_dquote; - t_token *res; - char *value; + int in_quote; + int in_dquote; + t_token *res; + char *value; in_quote = 0; in_dquote = 0; diff --git a/srcs/parsing_bonus.c b/srcs/parsing_bonus.c index 81d1455..31f2cad 100755 --- a/srcs/parsing_bonus.c +++ b/srcs/parsing_bonus.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/27 14:40:44 by tomoron #+# #+# */ -/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:57 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -236,7 +236,7 @@ t_cmd *parsing_bonus(char *cmd) if (type == CMD || type == PAREN) value = get_cmd_value(&cmd, type); else if (type == RED_O || type == RED_O_APP || type == RED_I - || type == HERE_DOC) + || type == HERE_DOC) value = get_next_arg(&cmd); else value = 0; diff --git a/srcs/parsing_var.c b/srcs/parsing_var.c index 8546dfb..c333abc 100755 --- a/srcs/parsing_var.c +++ b/srcs/parsing_var.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:24:36 by tomoron #+# #+# */ -/* Updated: 2024/03/28 14:10:02 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:58 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -65,7 +65,7 @@ int get_token_len(char *command, t_env *env) else if (*command != '\'' && *command != '"') res++; else if ((*command == '\'' && in_dquote) || (*command == '"' - && in_quote)) + && in_quote)) res++; command++; } diff --git a/srcs/path.c b/srcs/path.c index 9f9275b..9e17a6f 100755 --- a/srcs/path.c +++ b/srcs/path.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:58 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/pipe.c b/srcs/pipe.c index 1e8cf4b..f251f65 100755 --- a/srcs/pipe.c +++ b/srcs/pipe.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:58 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,23 +18,23 @@ void close_pipe_fds(t_msh *msh, int i) { if (msh->fds[i - 1][0] > 2) { - fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][0]); + //fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][0]); close(msh->fds[i - 1][0]); } if (msh->fds[i - 1][1] > 2) { - fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][1]); + //fprintf(stderr, "closing fd %d in child\n", msh->fds[i-1][1]); close(msh->fds[i - 1][1]); } } if (msh->fds[i][0] > 2) { - fprintf(stderr, "closing fd %d in child\n", msh->fds[i][0]); + //fprintf(stderr, "closing fd %d in child\n", msh->fds[i][0]); close(msh->fds[i][0]); } if (msh->fds[i][1] > 2) { - fprintf(stderr, "closing fd %d in child\n", msh->fds[i][1]); + //fprintf(stderr, "closing fd %d in child\n", msh->fds[i][1]); close(msh->fds[i][1]); } } @@ -53,9 +53,9 @@ void execute_command(t_msh *msh, char **cmd_args) { set_echoctl(msh->echoctl); env = env_to_char_tab(msh->env); - if(env) + if (env) { - fprintf(stderr, "execveing %s\n", msh->tokens->value); + //fprintf(stderr, "execveing %s\n", msh->tokens->value); execve(msh->tokens->value, cmd_args, env); } ft_free_str_arr(env); @@ -65,13 +65,13 @@ void execute_command(t_msh *msh, char **cmd_args) void child(t_msh *msh, char **cmd_args, int i) { if ((msh->in_type != CMD && msh->in_type != PAREN && msh->in_type != AND - && msh->in_type != OR && msh->in_type != PIPE) + && msh->in_type != OR && msh->in_type != PIPE) || (msh->in_type == PIPE && i > 0)) redirect_input(msh, i); if (msh->out_type == PIPE || msh->out_type == RED_O || msh->out_type == RED_O_APP) redirect_output(msh, i); - fprintf(stderr, "closing fds\n"); + //fprintf(stderr, "closing fds\n"); close_pipe_fds(msh, i); execute_command(msh, cmd_args); close(0); @@ -89,12 +89,12 @@ void parent(t_msh *msh, int i, int cmd_count) { if (msh->fds[i - 1][0] > 2) { - fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][0]); + //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][0]); close(msh->fds[i - 1][0]); } if (msh->fds[i - 1][1] > 2) { - fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][1]); + //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i - 1][1]); close(msh->fds[i - 1][1]); } } @@ -102,23 +102,23 @@ void parent(t_msh *msh, int i, int cmd_count) { if (msh->fds[i][0] > 2) { - fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][0]); + //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][0]); close(msh->fds[i][0]); } if (msh->fds[i][1] > 2) { - fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][1]); + //fprintf(stderr, "closing fd %d in parent\n", msh->fds[i][1]); close(msh->fds[i][1]); } } if (msh->in_fd > 2) { - fprintf(stderr, "closing in_fd %d in parent\n", msh->in_fd); + //fprintf(stderr, "closing in_fd %d in parent\n", msh->in_fd); close(msh->in_fd); } if (msh->out_fd > 2) { - fprintf(stderr, "closing in_fd %d in parent\n", msh->out_fd); - close(msh->out_fd); + //fprintf(stderr, "closing in_fd %d in parent\n", msh->out_fd); + close(msh->out_fd); } } diff --git a/srcs/pwd.c b/srcs/pwd.c index 7a5b7f7..07ba076 100755 --- a/srcs/pwd.c +++ b/srcs/pwd.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 18:31:21 by tomoron #+# #+# */ -/* Updated: 2024/02/21 12:47:39 by marde-vr ### ########.fr */ +/* Updated: 2024/04/18 20:48:59 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" diff --git a/srcs/signal_handler.c b/srcs/signal_handler.c index ae4c065..2fc0279 100755 --- 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/04/18 17:56:05 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:57:35 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,21 +60,21 @@ int set_echoctl(int value) //ft_printf("echoctl value : %d\n",value); if (tcgetattr(1, &t_p)) { - fprintf(stderr, "minishell: an error occured while getting the local fl\ -ags\n"); + //fprintf(stderr, "minishell: an error occured while getting the local fl\ +//ags\n"); return (1); } if (((t_p.c_lflag & ECHOCTL) != 0) == value) return (0); - ft_printf("change\n"); + //ft_printf("change\n"); 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)) { - fprintf(stderr, "minishell: an error occured while setting the local fl\ -ags\n"); + //fprintf(stderr, "minishell: an error occured while setting the local fl\ +//ags\n"); return (1); } return (0); diff --git a/srcs/sort_wildcard_list.c b/srcs/sort_wildcard_list.c index ac0ac2d..6d7a784 100644 --- a/srcs/sort_wildcard_list.c +++ b/srcs/sort_wildcard_list.c @@ -6,22 +6,22 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/17 09:12:33 by tomoron #+# #+# */ -/* Updated: 2024/04/17 10:42:39 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:49:00 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int wildcard_cmp(char *s1, char *s2, char *order) +int wildcard_cmp(char *s1, char *s2, char *order) { - while(*s1 && *s2) + while (*s1 && *s2) { - while(*s1 && !ft_isalnum(*s1)) + while (*s1 && !ft_isalnum(*s1)) s1++; - while(*s2 && !ft_isalnum(*s2)) + while (*s2 && !ft_isalnum(*s2)) s2++; - if(*s1 != *s2) - return ((ft_strchr(order, *s2) - order) - (ft_strchr(order, *s1)\ + if (*s1 != *s2) + return ((ft_strchr(order, *s2) - order) - (ft_strchr(order, *s1) - order)); s1++; s2++; @@ -31,18 +31,19 @@ int wildcard_cmp(char *s1, char *s2, char *order) void sort_wildcards_token(t_token *list) { - t_token *tmp; - t_token *start; - char *swap; - + t_token *tmp; + t_token *start; + char *swap; + tmp = list; start = list; - while(tmp) + while (tmp) { list = start; - while(list->next) + while (list->next) { - if(wildcard_cmp(list->value, list->next->value, "zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA9876543210") > 0) + if (wildcard_cmp(list->value, list->next->value, + "zZyYxXwWvVuUtTsSrRqQpPoOnNmMlLkKjJiIhHgGfFeEdDcCbBaA9876543210") > 0) { swap = list->value; list->value = list->next->value; diff --git a/srcs/utils.c b/srcs/utils.c index 0220fc1..4b960bb 100755 --- a/srcs/utils.c +++ b/srcs/utils.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */ -/* Updated: 2024/04/18 17:56:05 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:49:01 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ void free_msh(t_msh *msh) void ft_exit(t_msh *msh, int exit_code) { - ft_printf("exiting"); + //ft_printf("exiting"); free_msh(msh); exit(exit_code); } diff --git a/srcs/utils_bonus.c b/srcs/utils_bonus.c index c4a1981..34a3e5e 100755 --- a/srcs/utils_bonus.c +++ b/srcs/utils_bonus.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/27 17:19:27 by tomoron #+# #+# */ -/* Updated: 2024/04/02 17:16:06 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:49:00 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,22 +19,22 @@ t_token *parsing_syntax_error(t_token *res) return (0); } -int is_input_type(t_cmd *cmd) +int is_input_type(t_cmd *cmd) { - return(cmd->cmd_type == HERE_DOC || cmd->cmd_type == RED_I); + return (cmd->cmd_type == HERE_DOC || cmd->cmd_type == RED_I); } -int is_output_type(t_cmd *cmd) +int is_output_type(t_cmd *cmd) { - return(cmd->cmd_type == RED_O || cmd->cmd_type == RED_O_APP); + return (cmd->cmd_type == RED_O || cmd->cmd_type == RED_O_APP); } -int is_cmd_type(t_cmd *cmd) +int is_cmd_type(t_cmd *cmd) { - return(cmd->cmd_type == CMD || cmd->cmd_type == PAREN); + return (cmd->cmd_type == CMD || cmd->cmd_type == PAREN); } -int is_operand_type(t_cmd *cmd) +int is_operand_type(t_cmd *cmd) { - return(cmd->cmd_type == AND || cmd->cmd_type == OR); + return (cmd->cmd_type == AND || cmd->cmd_type == OR); } diff --git a/srcs/wildcards.c b/srcs/wildcards.c index e50b6af..2d9aff6 100644 --- a/srcs/wildcards.c +++ b/srcs/wildcards.c @@ -6,79 +6,80 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */ -/* Updated: 2024/04/17 10:16:33 by tomoron ### ########.fr */ +/* Updated: 2024/04/18 20:48:39 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int filename_corresponds(char *wildcard, char *value) +int filename_corresponds(char *wildcard, char *value) { - if(*value == '.' && *wildcard != '.') - return(0); - while(*wildcard && (*wildcard == '*' || *wildcard == *value)) + if (*value == '.' && *wildcard != '.') + return (0); + while (*wildcard && (*wildcard == '*' || *wildcard == *value)) { - if(*wildcard == '*') + if (*wildcard == '*') { - while(*wildcard && *value && *value != wildcard[1] && *wildcard != wildcard[1]) + while (*wildcard && *value && *value != wildcard[1] + && *wildcard != wildcard[1]) value++; wildcard++; } - while(*wildcard && *value && *value == *wildcard && *wildcard != '*') + while (*wildcard && *value && *value == *wildcard && *wildcard != '*') { wildcard++; value++; } } - return(!*wildcard && !*value); + return (!*wildcard && !*value); } -t_token *get_all_files(DIR *dir, char *wildcard) +t_token *get_all_files(DIR *dir, char *wildcard) { - struct dirent *content; - t_token *res; + struct dirent *content; + t_token *res; res = 0; content = readdir(dir); - while(content) + while (content) { - if(filename_corresponds(wildcard, content->d_name)) - res = token_add_back(res,ft_strdup(content->d_name)); + if (filename_corresponds(wildcard, content->d_name)) + res = token_add_back(res, ft_strdup(content->d_name)); content = readdir(dir); } - return(res); + return (res); } t_token *wildcards_add_back(t_token *res, t_token *next) { - if(!res) - return(next); - while(res->next) + if (!res) + return (next); + while (res->next) res = res->next; res->next = next; - return(res); + return (res); } t_token *expand_wildcards(t_token *res, char *value) { - DIR *dir; - char *cwd; + DIR *dir; + char *cwd; t_token *new; - if(!ft_strchr(value, '*')) - return(token_add_back(res, value)); + if (!ft_strchr(value, '*')) + return (token_add_back(res, value)); cwd = getcwd(NULL, 100000); - if(!cwd) - return(token_add_back(res, value)); + if (!cwd) + return (token_add_back(res, value)); dir = opendir(cwd); free(cwd); - if(!dir) - return(token_add_back(res, value)); + if (!dir) + return (token_add_back(res, value)); new = get_all_files(dir, value); closedir(dir); - if(!new) - return(token_add_back(res, value)); + if (!new) + return (token_add_back(res, value)); free(value); sort_wildcards_token(new); res = wildcards_add_back(res, new); - return(res); + return (res); } diff --git a/todo_list b/todo_list index 8ab43a7..4e37b57 100644 --- a/todo_list +++ b/todo_list @@ -2,3 +2,6 @@ redirection au millieu d'une commande print message quand segfault et "(core dumped)" si WCOREDUMP export += export sort +fix exit | exit +exec export in fork when piped +here doc in fork