From: Dominik Kaiser Date: Mon, 20 Jan 2025 18:04:57 +0000 (+0100) Subject: Merge branch 'main' into miau X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=b73e9e4fda360885035b9b04e9e9aca4724cb285;p=42%2Fminishell.git Merge branch 'main' into miau --- b73e9e4fda360885035b9b04e9e9aca4724cb285 diff --cc include/env.h index 56b50b5,a35bec3..bfb28c7 --- a/include/env.h +++ b/include/env.h @@@ -22,22 -19,7 +22,22 @@@ typedef struct s_en struct s_env *next; } t_env; -void getenvlst(t_env **env, char **en); -void free_envlst(t_env **env); -char *env_get(t_env *env, char *name); -char **env_to_strlst(t_env *env); +void free_env_node(t_env *node); +void getenvlst(t_env **env, char **en); +void free_envlst(t_env **env); +char *env_get(t_env *env, char *name); +char **env_to_strlst(t_env *env); +void update_oldpwd(t_env **env); +void update_pwd(t_env **env); +int unset(char **av, t_env **env); +int export(char **av, t_env **env, int f); +int echo(char **av); +int pwd(t_env *env); +int cd(t_env **env, char **args); +int ft_env(t_env *env); +int builtin_exit(char **args, t_env **env); +t_env *env_new(char *name); +t_env *check_existing(t_env *env, char *av); +int check_flag(int f); + - #endif ++#endif diff --cc include/minishell.h index 1139dbb,b2a3845..e9810bd --- a/include/minishell.h +++ b/include/minishell.h @@@ -30,39 -29,15 +30,40 @@@ int init(void); int init_signal_handling(void); -void repl(const char *prompt, t_env **env); +void repl(const char *prompt, t_env **env, int *promptflag); -t_list *parse(t_token *tokens); -t_node *parse_cmd(t_token *tokens); -t_redirection *collect_redirs(t_token **tokens); +t_list *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 **cf); void print_ast(t_node *ast); + int eval(t_node *node, t_env **env); -char *get_cmd_path(char *cmd, t_env *env); -int execute_cmd(t_cmd *cmd, t_env *env); +char *get_cmd_path(char *cmd, t_env *env, int *return_code); +int execute_cmd(t_cmd *cmd, t_env **env); +char *format_string(char *str, t_env *env, int is_literal); +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); +char *read_heredoc(char *delimiter); +int handle_input_redirection(t_redirection *redir); +int handle_output_redirection(t_redirection *redir); +int handle_redirections(t_redirection *redirs); +int handle_pipe_parent(int p[2], t_node *node, t_env **env); +int handle_pipe_child(int p[2], t_node *node, t_env **env, + int in_fd); +int open_file(char *path, int flags, int mode); +int eval_rec(t_node *node, t_env **env, int in_fd); +int create_files(t_list *files); +void q4fc(t_list **queue, t_redirection *redir); +void i_love_the_norme(t_token **cur, t_token **tokens); + +typedef struct s_minidata +{ + t_env *env; + t_list **create_files; +} t_minidata; + #endif diff --cc include/token.h index 993a408,7e2038a..bb7ea94 --- a/include/token.h +++ b/include/token.h @@@ -45,10 -45,8 +45,9 @@@ t_token *new_redir_token(int type t_token *next); void free_token(t_token *token); - void free_token_and_connect(t_token *token); - void free_tokens(t_token *tokens); + void tokenizer(char *s, t_token **token_list, char quote_check); +void print_token(t_token *token); #endif diff --cc src/builtins_part_two.c index 9fabc81,94ef258..d3c0929 --- a/src/builtins_part_two.c +++ b/src/builtins_part_two.c @@@ -59,11 -55,13 +59,11 @@@ void update_pwd(t_env **env int cd(t_env **env, char **av) { t_env *current; - t_env *prev; - t_env *pwd; -- - current = env; ++ + current = *env; if (av[1] == NULL) { - update_oldpwd(&env); + update_oldpwd(env); while (current) { if (ft_strncmp(current->name, "HOME", 4) == 0) diff --cc src/env.c index cc9cfae,3110965..63a0f8a --- a/src/env.c +++ b/src/env.c @@@ -61,21 -62,3 +61,21 @@@ char *env_get(t_env *env, char *name } return (NULL); } + +t_env *env_new(char *name) +{ + t_env *result; + + result = malloc(sizeof(t_env)); + if (!result) + return (NULL); + result->name = name; + return (result); +} + +void free_env_node(t_env *node) +{ + free(node->name); + free(node->value); + free(node); - } ++} diff --cc src/interpreter.c index f31e965,c6a4a00..6d71022 --- a/src/interpreter.c +++ b/src/interpreter.c @@@ -49,7 -88,3 +49,8 @@@ int eval_rec(t_node *node, t_env **env return (result); } +int eval(t_node *node, t_env **env) +{ + return (eval_rec(node, env, STDIN_FILENO)); +} ++