diff options
| author | Dominik Kaiser | 2025-01-25 15:42:11 +0100 |
|---|---|---|
| committer | Dominik Kaiser | 2025-01-25 15:42:11 +0100 |
| commit | 21874e1446ccd08f4433870a69dbe1c08f8331a9 (patch) | |
| tree | e0d92a277fbb353167ff7909a2007f669058b5bc | |
| parent | b427100b6c0c655f74dc689533a3f36edfeebffc (diff) | |
| download | minishell-21874e1446ccd08f4433870a69dbe1c08f8331a9.tar.gz minishell-21874e1446ccd08f4433870a69dbe1c08f8331a9.zip | |
Make norminette happy
| -rw-r--r-- | include/minishell.h | 10 | ||||
| -rw-r--r-- | src/error.c | 9 | ||||
| -rw-r--r-- | src/get_cmd_path.c | 8 | ||||
| -rw-r--r-- | src/main.c | 8 | ||||
| -rw-r--r-- | src/parse_cmd.c | 18 | ||||
| -rw-r--r-- | src/repl.c | 9 |
6 files changed, 32 insertions, 30 deletions
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 <chuhlig@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/15 16:35:53 by dkaiser #+# #+# */ -/* Updated: 2025/01/20 18:12:40 by dkaiser ### ########.fr */ +/* Updated: 2025/01/25 14:58:52 by dkaiser ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,9 +22,14 @@ void *error(int err_code, char *err_text, int exit_code, int *ret_code) return (NULL); } -void command_not_found_error(char *cmd) +void *command_not_found_error(char *cmd, int *return_code, char *cmd_path, + char **split_path) { ft_printf("%s:", cmd); ft_putstr_fd(" command not found", 2); ft_printf("\n"); + *return_code = 127; + free(cmd_path); + ft_free_split(split_path); + return (NULL); } diff --git a/src/get_cmd_path.c b/src/get_cmd_path.c index 8075a5f..aae80cd 100644 --- a/src/get_cmd_path.c +++ b/src/get_cmd_path.c @@ -6,7 +6,7 @@ /* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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) @@ -6,7 +6,7 @@ /* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 <chuhlig@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; +} @@ -6,34 +6,31 @@ /* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 ; } |
