]> git.dkaiser.de - 42/minishell.git/commitdiff
Make norminette happy
authorDominik Kaiser <dkaiser@3-H-7.42heilbronn.de>
Sat, 25 Jan 2025 14:42:11 +0000 (15:42 +0100)
committerDominik Kaiser <dkaiser@3-H-7.42heilbronn.de>
Sat, 25 Jan 2025 14:42:11 +0000 (15:42 +0100)
include/minishell.h
src/error.c
src/get_cmd_path.c
src/main.c
src/parse_cmd.c
src/repl.c

index 97e22cb6bfdf7bdbee9e21a030bd193b2e8ab8a9..354d5b94b06902dea6f0ee7be096bc12856bb03a 100644 (file)
@@ -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       */
 /*                                                                            */
 /* ************************************************************************** */
 
 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);
index 2ca60b24b1aac61e6c407879bfec6028c6ff7277..eebc21addf7767d0982d402756a47ce2891c0995 100644 (file)
@@ -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);
 }
index 8075a5f788c765c1b2158ef845c9075692dbbdb1..aae80cdde472738d34d7f963daa1135577e574b1 100644 (file)
@@ -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)
index 6fbe58c84dbaaad5b78f89db0dd1f57d9c7315bd..9cd1b393fd0c22d3360a1e082c4e3f3d9cdabd40 100644 (file)
@@ -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       */
 /*                                                                            */
 /* ************************************************************************** */
 
 
 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);
 }
index 5f9e36dfeb8ec063d8cd22bb4c00ea02fe6aa83b..578601c8280818c8f136641c22b4ccba942ada1a 100644 (file)
@@ -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;
+}
index 93874a778a94da8e050a6f1f865623464d7a5cd7..3f4435d8547dd0b5208e859d19fa740d4d4f67cd 100644 (file)
@@ -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 ;
                }