From: Dominik Kaiser Date: Sat, 25 Jan 2025 14:42:11 +0000 (+0100) Subject: Make norminette happy X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=21874e1446ccd08f4433870a69dbe1c08f8331a9;p=42%2Fminishell.git Make norminette happy --- diff --git a/include/minishell.h b/include/minishell.h index 97e22cb..354d5b9 100644 --- a/include/minishell.h +++ b/include/minishell.h @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/22 17:14:49 by dkaiser #+# #+# */ -/* Updated: 2025/01/23 23:17:00 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 15:41:33 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,11 +30,12 @@ int init(void); int init_signal_handling(void); -void repl(const char *prompt, t_env **env, int *promptflag); +void repl(const char *prompt, t_env **env); t_node *parse(t_token *tokens, t_env **env); t_node *parse_cmd(t_token *tokens, t_env **env); -t_redirection *collect_redirs(t_token **tokens, t_env *env, t_list **create_files); +t_redirection *collect_redirs(t_token **tokens, t_env *env, + t_list **create_files); void print_ast(t_node *ast); @@ -46,7 +47,8 @@ void set_return_code(int return_code, t_env **env); int handle_redirections(t_redirection *redirs); void *error(int err_code, char *err_text, int exit_code, int *ret_code); -void command_not_found_error(char *cmd); +void *command_not_found_error(char *cmd, int *return_code, + char *cmd_path, char **split_path); char *read_heredoc(char *delimiter); int handle_input_redirection(t_redirection *redir); int handle_output_redirection(t_redirection *redir); diff --git a/src/error.c b/src/error.c index 2ca60b2..eebc21a 100644 --- a/src/error.c +++ b/src/error.c @@ -6,7 +6,7 @@ /* By: dkaiser +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/17 19:19:59 by chuhlig #+# #+# */ -/* Updated: 2025/01/25 11:36:28 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 14:58:45 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -86,11 +86,7 @@ static char *find_in_path(char *cmd, t_env *env, int *return_code) return (ft_free_split(path_start), cmd_path); path++; } - *return_code = 127; - free(cmd_path); - ft_free_split(path_start); - command_not_found_error(cmd); - return (NULL); + return (command_not_found_error(cmd, return_code, cmd_path, path_start)); } static char *get_simple_cmd_path(char *cmd, int *return_code) diff --git a/src/main.c b/src/main.c index 6fbe58c..9cd1b39 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/22 17:14:03 by dkaiser #+# #+# */ -/* Updated: 2025/01/25 10:25:42 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 15:41:04 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,18 +14,16 @@ int main(int argc, char *argv[], char *envp[]) { - t_env *env; - static int promptflag; + t_env *env; env = NULL; - promptflag = 0; if (!argc && !argv) return (1); if (init()) return (1); getenvlst(&env, envp); set_return_code(0, &env); - repl("Minishell $ ", &env, &promptflag); + repl("Minishell $ ", &env); free_envlst(&env); return (0); } diff --git a/src/parse_cmd.c b/src/parse_cmd.c index 5f9e36d..578601c 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,13 +6,14 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */ -/* Updated: 2025/01/25 11:36:09 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 15:00:55 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" static char **collect_args(t_token **tokens, t_env **env); +static void setup_vars(t_token **tokens, t_token **cur, int *i); t_node *parse_cmd(t_token *tokens, t_env **env) { @@ -40,22 +41,19 @@ static char **collect_args(t_token **tokens, t_env **env) int i; t_token *next; - cur = *tokens; - i = 0; + setup_vars(tokens, &cur, &i); while (cur != NULL && ++i) cur = cur->next; result = malloc(sizeof(char *) * (i + 1)); if (result == NULL) return (free_tokens(*tokens), NULL); - cur = *tokens; - i = 0; + setup_vars(tokens, &cur, &i); while (cur != NULL && cur->type == STRING_TOKEN) { next = cur->next; if (cur->previous) free_token2(cur->previous); - result[i] = format_string(cur->content.string, *env, ft_atoi("0")); - i++; + result[i++] = format_string(cur->content.string, *env, ft_atoi("0")); if (cur->next == NULL) free_token2(cur); cur = next; @@ -63,3 +61,9 @@ static char **collect_args(t_token **tokens, t_env **env) result[i] = NULL; return (result); } + +static void setup_vars(t_token **tokens, t_token **cur, int *i) +{ + *cur = *tokens; + *i = 0; +} diff --git a/src/repl.c b/src/repl.c index 93874a7..3f4435d 100644 --- a/src/repl.c +++ b/src/repl.c @@ -6,34 +6,31 @@ /* By: chuhlig +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/24 16:07:04 by dkaiser #+# #+# */ -/* Updated: 2025/01/25 12:41:48 by chuhlig ### ########.fr */ +/* Updated: 2025/01/25 15:39:36 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ #include "../include/minishell.h" #include "token.h" -void free_repl(char *input, t_node *ast) +static void free_repl(char *input, t_node *ast) { free(input); if (ast) free_node(ast); } -void repl(const char *prompt, t_env **env, int *promptflag) +void repl(const char *prompt, t_env **env) { char *input; t_token *token_list; t_node *ast; - (*promptflag)++; while (1) { input = readline(prompt); if (input == NULL) { - if (*promptflag > 1) - (*promptflag)--; printf("exit\n"); break ; }