From a5e877fdd515dec21df4d0bc045f482353c3d92b Mon Sep 17 00:00:00 2001 From: whaffman Date: Wed, 26 Feb 2025 15:27:53 +0100 Subject: [PATCH] norm 1 --- sources.mk | 43 ++++++++++++------------- src/builtin/builtin_exit.c | 19 ++++++----- src/builtin/is_builtin.c | 3 +- src/builtin/simple_builtins.c | 3 +- src/debug/print_commands.c | 1 - src/debug/print_freelist.c | 4 +-- src/environment/environment_get_arr.c | 8 +++-- src/environment/environment_parse.c | 15 ++++----- src/executor/executor_child.c | 4 +-- src/executor/executor_count_fds.c | 4 +-- src/executor/executor_fork.c | 6 ++-- src/executor/executor_open_fds.c | 3 +- src/expander/expander_allocate_memory.c | 8 ++--- src/expander/expander_parse_string.c | 5 ++- src/expander/expander_parse_variables.c | 3 +- src/lexer/lexer_new.c | 6 ++-- src/lexer/lexer_parse_input.c | 6 ++-- src/parser/parser_get_arguments.c | 30 +++++++++-------- 18 files changed, 83 insertions(+), 88 deletions(-) diff --git a/sources.mk b/sources.mk index 3fa9ed9..9930b49 100644 --- a/sources.mk +++ b/sources.mk @@ -1,23 +1,22 @@ -VPATH = src:src/prompt:src/utils:src/lexer:src/token:src/environment:src/executor:src/parser:src/debug:src/expander:src/builtin:src/signal:src/redirect: -SOURCES = history_load.c history_write.c prompt.c error_msg.c \ -ft_lstclear_safe.c ft_lstnew_safe.c ft_strdup_safe.c \ -ft_strjoin_safe.c init_minishell.c malloc_safe.c print_banner.c \ -check_malloc.c free_command_list.c free_freelist.c free_lexer.c \ -free_minishell.c free_minishell_line.c free_safe.c free_token.c \ -free_token_list.c lexer_read_char.c lexer_new.c lexer_parse_input.c \ -lexer_read_word.c lexer_token_next.c token_new.c token_parse.c \ -environment_add.c environment_del.c environment_free.c \ -environment_free_list.c environment_get.c environment_get_arr.c \ -environment_parse.c environment_print.c executor_close_fds.c \ -executor_absolute_path.c executor_child.c executor_count_fds.c \ -executor_create_pipes.c executor_create_redirects.c \ -executor_execute_pipeline.c executor_fork.c executor_open_fds.c \ -parser_get_arguments.c parser_get_commands.c parser_new_command.c \ -print_commands.c print_freelist.c expander_is_character.c \ -expander_expand_dollar.c expander_allocate_memory.c \ +VPATH = src:src/prompt:src/utils:src/lexer:src/token:src/environment:src/executor:src/parser:src/signal:src/debug:src/expander:src/builtin:src/redirect: +SOURCES = history_load.c history_write.c prompt.c ft_lstclear_safe.c \ +ft_lstnew_safe.c ft_strdup_safe.c ft_strjoin_safe.c init_minishell.c \ +malloc_safe.c free_minishell_line.c free_safe.c print_banner.c \ +error_msg.c check_malloc.c free_command_list.c free_freelist.c \ +free_lexer.c free_minishell.c free_token.c free_token_list.c \ +lexer_read_char.c lexer_new.c lexer_parse_input.c lexer_read_word.c \ +lexer_token_next.c token_new.c token_parse.c environment_add.c \ +environment_del.c environment_free.c environment_free_list.c \ +environment_get.c environment_get_arr.c environment_print.c \ +environment_parse.c executor_close_fds.c executor_absolute_path.c \ +executor_child.c executor_count_fds.c executor_create_pipes.c \ +executor_create_redirects.c executor_fork.c executor_open_fds.c \ +executor_execute_pipeline.c parser_get_commands.c \ +parser_new_command.c parser_get_arguments.c signal.c print_freelist.c \ +print_commands.c expander_expand_dollar.c expander_is_character.c \ expander_get_variable.c expander_parse_string.c \ -expander_parse_variables.c builtin_echo.c builtin_router.c \ -simple_builtins.c is_builtin.c builtin_cd.c builtin_env.c \ -builtin_exit.c builtin_export.c builtin_pwd.c builtin_unset.c \ -signal.c redirect_valid_type.c redirect_get_inputs.c \ -redirect_get_outputs.c redirect_new.c main.c \ +expander_parse_variables.c expander_allocate_memory.c builtin_echo.c \ +builtin_router.c simple_builtins.c is_builtin.c builtin_cd.c \ +builtin_env.c builtin_export.c builtin_unset.c builtin_pwd.c \ +builtin_exit.c redirect_valid_type.c redirect_get_outputs.c \ +redirect_new.c redirect_get_inputs.c main.c \ diff --git a/src/builtin/builtin_exit.c b/src/builtin/builtin_exit.c index 5e3252d..4dcb622 100644 --- a/src/builtin/builtin_exit.c +++ b/src/builtin/builtin_exit.c @@ -1,23 +1,23 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* builtin_exit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/20 11:32:59 by whaffman #+# #+# */ -/* Updated: 2025/02/25 20:56:29 by qmennen ### ########.fr */ +/* :::::::: */ +/* builtin_exit.c :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/02/20 11:32:59 by whaffman #+# #+# */ +/* Updated: 2025/02/26 15:19:51 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" - +//TODO EXIT last exit status r:20 int builtin_exit(t_minishell *minishell, t_command *cmd) { int exit_status; - exit_status = 0; //TODO EXIT last exit status + exit_status = 0; if (ft_count_arr(cmd->args) > 2) { ft_putstr_fd("exit\n", STDERR_FILENO); @@ -36,7 +36,6 @@ int builtin_exit(t_minishell *minishell, t_command *cmd) } exit_status = ft_atoi(cmd->args[1]); } - //print_freelist(minishell); free_minishell(&minishell); rl_clear_history(); exit(exit_status); diff --git a/src/builtin/is_builtin.c b/src/builtin/is_builtin.c index 8fe1345..05cb3f9 100644 --- a/src/builtin/is_builtin.c +++ b/src/builtin/is_builtin.c @@ -6,13 +6,12 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/20 11:03:33 by whaffman #+# #+# */ -/* Updated: 2025/02/20 15:36:16 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 14:42:49 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" - int is_builtin(char *cmd) { const char *builtins[] = {"echo", "cd", "pwd", "export", diff --git a/src/builtin/simple_builtins.c b/src/builtin/simple_builtins.c index 992b67d..b83fbbe 100644 --- a/src/builtin/simple_builtins.c +++ b/src/builtin/simple_builtins.c @@ -6,13 +6,12 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/05 16:21:39 by whaffman #+# #+# */ -/* Updated: 2025/02/20 15:06:40 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 14:42:54 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" - void simple_builtins(t_minishell *minishell) { if (minishell->commands == NULL) diff --git a/src/debug/print_commands.c b/src/debug/print_commands.c index c41bfa2..2092b8d 100644 --- a/src/debug/print_commands.c +++ b/src/debug/print_commands.c @@ -53,4 +53,3 @@ void token_print(void *param) token = (t_token *)param; printf("token type %i, value %s\n", token->type, token->value); } - diff --git a/src/debug/print_freelist.c b/src/debug/print_freelist.c index b9b1e6e..7a74220 100644 --- a/src/debug/print_freelist.c +++ b/src/debug/print_freelist.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/25 15:46:03 by whaffman #+# #+# */ -/* Updated: 2025/02/25 18:17:13 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 14:44:46 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ void print_freelist(t_minishell *minishell) { t_list *freelist; - int i; + int i; if (!DEBUG) return ; diff --git a/src/environment/environment_get_arr.c b/src/environment/environment_get_arr.c index c7d9b68..9746792 100644 --- a/src/environment/environment_get_arr.c +++ b/src/environment/environment_get_arr.c @@ -6,7 +6,7 @@ /* By: willem +#+ */ /* +#+ */ /* Created: 2025/02/08 13:59:48 by willem #+# #+# */ -/* Updated: 2025/02/25 14:29:49 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 14:45:35 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -20,12 +20,14 @@ char **environment_get_arr(t_minishell *minishell) t_list *environment; environment = minishell->environment; - arr = malloc_safe(minishell, sizeof(char *) * (ft_lstsize(environment) + 1)); + arr = malloc_safe(minishell, + sizeof(char *) * (ft_lstsize(environment) + 1)); i = 0; while (environment != NULL) { env = (t_environment *)environment->content; - arr[i] = malloc_safe(minishell, ft_strlen(env->name) + ft_strlen(env->value) + 2); + arr[i] = malloc_safe(minishell, + ft_strlen(env->name) + ft_strlen(env->value) + 2); ft_strlcpy(arr[i], env->name, ft_strlen(env->name) + 1); ft_strlcat(arr[i], "=", ft_strlen(env->name) + 2); ft_strlcat(arr[i], env->value, diff --git a/src/environment/environment_parse.c b/src/environment/environment_parse.c index 8ef6f6d..e5a42a1 100644 --- a/src/environment/environment_parse.c +++ b/src/environment/environment_parse.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* environment_parse.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/05 15:52:33 by whaffman #+# #+# */ -/* Updated: 2025/02/25 21:17:06 by qmennen ### ########.fr */ +/* :::::::: */ +/* environment_parse.c :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/02/05 15:52:33 by whaffman #+# #+# */ +/* Updated: 2025/02/26 15:20:09 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -16,7 +16,6 @@ int environment_parse(t_minishell *minishell, char **envp) { char **env; - if (envp == NULL) return (FAILURE); while (*envp != NULL) diff --git a/src/executor/executor_child.c b/src/executor/executor_child.c index 125acbb..549cdcb 100644 --- a/src/executor/executor_child.c +++ b/src/executor/executor_child.c @@ -6,7 +6,7 @@ /* By: willem +#+ */ /* +#+ */ /* Created: 2025/02/12 21:25:10 by willem #+# #+# */ -/* Updated: 2025/02/25 13:52:53 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:20:25 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ void executor_child(t_minishell *minishell, t_command *command) { - char *path; + char *path; if (command->fd_in != 0) dup2(command->fd_in, 0); diff --git a/src/executor/executor_count_fds.c b/src/executor/executor_count_fds.c index f478882..0fcf5f9 100644 --- a/src/executor/executor_count_fds.c +++ b/src/executor/executor_count_fds.c @@ -6,13 +6,13 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/21 12:42:26 by whaffman #+# #+# */ -/* Updated: 2025/02/21 13:05:55 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:20:33 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" -int executor_count_fds(t_minishell *minishell) +int executor_count_fds(t_minishell *minishell) { int count; t_list *current; diff --git a/src/executor/executor_fork.c b/src/executor/executor_fork.c index 5da3295..2c025a3 100644 --- a/src/executor/executor_fork.c +++ b/src/executor/executor_fork.c @@ -6,16 +6,16 @@ /* By: willem +#+ */ /* +#+ */ /* Created: 2025/02/12 21:24:52 by willem #+# #+# */ -/* Updated: 2025/02/25 13:51:48 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:21:42 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" +//TODO should parent close the fds? pid_t executor_fork(t_minishell *minishell, t_command *command) { pid_t pid; - // int status; pid = fork(); if (pid > 0) @@ -24,8 +24,6 @@ pid_t executor_fork(t_minishell *minishell, t_command *command) close(command->fd_in); if (command->fd_out != 1) close(command->fd_out); - // waitpid(pid, &status, 0); - // return (((status) & 0xff00) >> 8); signal_init_parent(); } else if (pid == 0) diff --git a/src/executor/executor_open_fds.c b/src/executor/executor_open_fds.c index 4dc2b5e..ace0aa4 100644 --- a/src/executor/executor_open_fds.c +++ b/src/executor/executor_open_fds.c @@ -6,7 +6,7 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/21 12:50:42 by whaffman #+# #+# */ -/* Updated: 2025/02/21 13:15:04 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:21:56 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -35,5 +35,4 @@ int executor_open_fds(t_list *redirect_list, int og_fd) redirect_list = redirect_list->next; } return (fd); - } diff --git a/src/expander/expander_allocate_memory.c b/src/expander/expander_allocate_memory.c index 08c72b8..a323e4c 100644 --- a/src/expander/expander_allocate_memory.c +++ b/src/expander/expander_allocate_memory.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/02/19 13:57:19 by qmennen #+# #+# */ -/* Updated: 2025/02/25 17:54:08 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:22:11 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -17,10 +17,10 @@ char *expander_allocate_memory( const char *s, t_list *variables) { - int size; - t_list *current; + int size; + t_list *current; t_environment *env; - char *string; + char *string; size = 1; current = variables; diff --git a/src/expander/expander_parse_string.c b/src/expander/expander_parse_string.c index e2fdf4b..6546950 100644 --- a/src/expander/expander_parse_string.c +++ b/src/expander/expander_parse_string.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/02/18 19:00:35 by qmennen #+# #+# */ -/* Updated: 2025/02/25 16:14:16 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:22:54 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -26,6 +26,7 @@ static void free_variables(t_minishell *minishell, t_list *variables) } } +//TODO: Figure out why echo "> echo "\as"" breaks char *expander_parse_string(char *s, t_minishell *minishell) { t_list *variables; @@ -51,8 +52,6 @@ char *expander_parse_string(char *s, t_minishell *minishell) else string[j++] = s[i++]; } - //TODO: Figure out why echo "> echo "\as"" breaks - string[j] = 0; free_variables(minishell, variables); return (string); diff --git a/src/expander/expander_parse_variables.c b/src/expander/expander_parse_variables.c index aab07e9..69c6c5c 100644 --- a/src/expander/expander_parse_variables.c +++ b/src/expander/expander_parse_variables.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/02/19 13:58:13 by qmennen #+# #+# */ -/* Updated: 2025/02/25 16:51:16 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:23:17 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ t_list *expander_parse_variables(const char *s, t_minishell *minishell) { - int i; t_list *var_list; t_environment *env; diff --git a/src/lexer/lexer_new.c b/src/lexer/lexer_new.c index 92d13d1..8bb3a0d 100644 --- a/src/lexer/lexer_new.c +++ b/src/lexer/lexer_new.c @@ -6,7 +6,7 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/02/05 19:03:01 by qmennen #+# #+# */ -/* Updated: 2025/02/25 16:40:16 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:23:52 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -14,9 +14,9 @@ t_lexer *ft_lexer_new(t_minishell *minishell) { - char *input; - + char *input; t_lexer *lexer; + input = minishell->line; lexer = malloc_safe(minishell, sizeof(t_lexer)); lexer->input = ft_strdup_safe(minishell, input); diff --git a/src/lexer/lexer_parse_input.c b/src/lexer/lexer_parse_input.c index e68d723..fb4dc94 100644 --- a/src/lexer/lexer_parse_input.c +++ b/src/lexer/lexer_parse_input.c @@ -6,11 +6,12 @@ /* By: qmennen +#+ */ /* +#+ */ /* Created: 2025/02/05 19:09:20 by qmennen #+# #+# */ -/* Updated: 2025/02/25 16:51:27 by whaffman ######## odam.nl */ +/* Updated: 2025/02/26 15:24:39 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" +//TODO: Check if unicode support is viable /** * @brief Parses the input from the lexer and returns a list of tokens. @@ -33,9 +34,8 @@ t_list *ft_parse_input(t_minishell *minishell) list = NULL; while (TRUE) { - //TODO: Check if unicode support is viable token = ft_token_next(minishell, lexer); - if (token->type == T_EOF || token->type == T_ERROR) //TODO T_ERROR removes the inf loop + if (token->type == T_EOF || token->type == T_ERROR) break ; ft_lstadd_back(&list, ft_lstnew_safe(minishell, token)); } diff --git a/src/parser/parser_get_arguments.c b/src/parser/parser_get_arguments.c index afbb729..1881561 100644 --- a/src/parser/parser_get_arguments.c +++ b/src/parser/parser_get_arguments.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* ::: :::::::: */ -/* parser_get_arguments.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: qmennen +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/11 16:20:09 by qmennen #+# #+# */ -/* Updated: 2025/02/25 20:14:18 by qmennen ### ########.fr */ +/* :::::::: */ +/* parser_get_arguments.c :+: :+: */ +/* +:+ */ +/* By: qmennen +#+ */ +/* +#+ */ +/* Created: 2025/02/11 16:20:09 by qmennen #+# #+# */ +/* Updated: 2025/02/26 15:26:32 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ @@ -38,8 +38,10 @@ static int parser_should_expand(t_list *value) token = (t_token *)value->content; if (!token) return (0); - return (token->type == T_DQWORD || (token->type == T_WORD && - token->value[0] == '$' && token->value[1])); + return (token->type == T_DQWORD + || (token->type == T_WORD + && token->value[0] == '$' + && token->value[1])); } char **parser_get_arguments(t_list *list, t_minishell *minishell) @@ -56,10 +58,12 @@ char **parser_get_arguments(t_list *list, t_minishell *minishell) while ((++i) < cmds && current) { if (parser_should_expand(current)) - args[i] = expander_parse_string(((t_token *)current->content)->value, minishell); - else if (((t_token *)current->content)->type == T_WORD || - ((t_token *)current->content)->type == T_SQWORD) - args[i] = ft_strdup_safe(minishell, ((t_token *)current->content)->value); + args[i] = expander_parse_string( + ((t_token *)current->content)->value, minishell); + else if (((t_token *)current->content)->type == T_WORD + || ((t_token *)current->content)->type == T_SQWORD) + args[i] = ft_strdup_safe(minishell, + ((t_token *)current->content)->value); current = current->next; } args[i] = 0;