diff --git a/includes/minishell.h b/includes/minishell.h index 1765ad2..734f033 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -56,7 +56,7 @@ typedef struct s_msh t_msh *init_msh(char **envp); void free_msh(t_msh *msh); void free_child(t_msh *msh); -void init_sig(); +void init_sig(void); void handle_sigint(int sig); void handle_sigquit(int sig); char *powerline(t_msh *msh); diff --git a/includes/parser/ast.h b/includes/parser/ast.h index 411fcb8..c19c9c5 100644 --- a/includes/parser/ast.h +++ b/includes/parser/ast.h @@ -13,6 +13,8 @@ #ifndef AST_H # define AST_H +# include + typedef struct s_node t_node; typedef struct s_msh t_msh; @@ -50,7 +52,7 @@ typedef struct s_ast_n int _stdin; int save_stdo; int save_stdi; - t_redir *redir; + t_redir *redir; char *input; char **files; bool sh; @@ -58,16 +60,16 @@ typedef struct s_ast_n typedef struct s_nodell { - t_node *node; + t_node *node; struct s_nodell *next; } t_nodell; t_ast_n *get_ast(t_msh *msh, t_node *lst); t_nodell *cutll(t_node *lst, t_node *expected, size_t limiter); -t_node *get_top_token(t_node *lst, t_state *state); +t_node *get_top_token(t_node *lst, t_state *state); // recurce -t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh); +t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh, bool subsh); // redir t_redir get_redir(t_node *node); void create_redir(t_node *cpy, t_ast_n *self); @@ -75,14 +77,15 @@ void create_redir_subsh(t_node *head, t_ast_n *self); // cmd void create_cmd(t_ast_n *self, t_node *lst); // subsh -void create_subsh(t_ast_n *parent, t_node *lst, t_msh *msh); +void create_subsh(t_ast_n *parent, t_node *lst, t_msh *msh); // pipeline void create_pline(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh); // and_or -void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token, t_msh *msh); +void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token, + t_msh *msh); // free void free_ast(t_ast_n *node); -void free_lltab(t_nodell *nodell); +void free_lltab(t_nodell *nodell); #endif diff --git a/includes/parser/drawio.h b/includes/parser/drawio.h index 8274286..205a2ca 100644 --- a/includes/parser/drawio.h +++ b/includes/parser/drawio.h @@ -33,12 +33,13 @@ typedef struct s_elems } t_elems; // internal -char *replace_ampercent(char *src); -char *replace_left_red(char *src); +char *replace_ampercent(char *src); +char *replace_left_red(char *src); t_dio_node get_cmd_txt(t_ast_n *node); -int print_ast(t_ast_n *node, t_elems *e, int fd); +int print_ast(t_ast_n *node, t_elems *e, int fd); // external -void gen_dio_linked_list(t_node *head, int fd); -void gen_dio_ast(t_ast_n *head, int fd); +void gen_dio_linked_list(t_node *head, int fd); +void gen_dio_ast(t_ast_n *head, int fd); + #endif diff --git a/includes/parser/heredoc.h b/includes/parser/heredoc.h index 76d26f6..105f1b1 100644 --- a/includes/parser/heredoc.h +++ b/includes/parser/heredoc.h @@ -13,7 +13,6 @@ #ifndef HEREDOC_H # define HEREDOC_H - typedef struct s_node t_node; typedef struct s_msh t_msh; diff --git a/includes/parser/parsing.h b/includes/parser/parsing.h index 2e6f008..8bd7a21 100644 --- a/includes/parser/parsing.h +++ b/includes/parser/parsing.h @@ -17,10 +17,12 @@ typedef struct s_node t_node; typedef struct s_ast_n t_ast_n; typedef struct s_msh t_msh; -t_ast_n *parser(char *input, t_msh *msh); +t_ast_n *parser(char *input, t_msh *msh); int unexpected_token(t_node *node); int is_aop_operator(t_node *node); void interpret_cmd(char **input, t_msh *msh); +void end_heredoc(char *buf, t_msh *msh, t_node *lst); +void exit_heredoc(char *limiter, t_msh *msh, t_node *lst); #endif diff --git a/includes/parser/tokenizer.h b/includes/parser/tokenizer.h index 345f8d5..ad4d9a1 100644 --- a/includes/parser/tokenizer.h +++ b/includes/parser/tokenizer.h @@ -46,23 +46,25 @@ typedef struct s_node enum e_pres pressision; } t_node; -t_node *tokenize(char *str); -t_node *create_node(char *val, t_token token); -int add_node_back(t_node **head, char *val, t_token token, t_pres pres); -int merge_with_next_node(t_node *node); -void free_linked_list(t_node *stack); -t_token get_token(char *str); -t_pres get_pressision(char *s, t_token token, t_token last_token, t_pres last_pres); -int create_node_after(t_node *elem, char *val); -int is_meta(char c); -int is_sticked(char *val); -int trim_nodes(t_node *head); -void debug_linked_list(t_node *head, char *msg); -int find_quote_node(t_node *head, char q); -int syntax_error(t_node *head); -char *copy_meta(char *val, int *copied); -char *copy_unmeta(char *val, int *copied); -void debug_token_list(t_node* lst, char *msg); -void set_token(t_node *head); +t_node *tokenize(char *str); +t_node *create_node(char *val, t_token token); +int add_node_back(t_node **head, char *val, + t_token token, t_pres pres); +int merge_with_next_node(t_node *node); +void free_linked_list(t_node *stack); +t_token get_token(char *str); +t_pres get_pressision(char *s, t_token token, + t_token last_token, t_pres last_pres); +int create_node_after(t_node *elem, char *val); +int is_meta(char c); +int is_sticked(char *val); +int trim_nodes(t_node *head); +void debug_linked_list(t_node *head, char *msg); +int find_quote_node(t_node *head, char q); +int syntax_error(t_node *head); +char *copy_meta(char *val, int *copied); +char *copy_unmeta(char *val, int *copied); +void debug_token_list(t_node *lst, char *msg); +void set_token(t_node *head); #endif diff --git a/srcs/execution/exec.c b/srcs/execution/exec.c index 340551a..ea7666c 100644 --- a/srcs/execution/exec.c +++ b/srcs/execution/exec.c @@ -14,7 +14,7 @@ int execute_command(t_ast_n *node) { - if (!node || (node->state == _CMD && node->cmd == NULL)) + if (!node || (node->state == _CMD && node->cmd == NULL)) return (0); if (node->state == _CMD) handle_redir(node); diff --git a/srcs/main.c b/srcs/main.c index b4aabe5..c598624 100644 --- a/srcs/main.c +++ b/srcs/main.c @@ -13,6 +13,7 @@ #include "../includes/minishell.h" #include #include +#include static void add_prevhistory(t_msh *msh) { @@ -49,13 +50,13 @@ int interactive_mode(t_msh *msh) int main(int ac, char **av, char **envp) { - t_msh *msh; - struct termios term; + t_msh *msh; + struct termios term; (void)av; - tcgetattr(STDIN_FILENO, &term); - term.c_cc[VQUIT] = _POSIX_VDISABLE; - tcsetattr(STDIN_FILENO, TCSANOW, &term); + tcgetattr(STDIN_FILENO, &term); + term.c_cc[VQUIT] = _POSIX_VDISABLE; + tcsetattr(STDIN_FILENO, TCSANOW, &term); msh = init_msh(envp); init_sig(); add_prevhistory(msh); diff --git a/srcs/parsing/heredoc.c b/srcs/parsing/heredoc.c index 0ca5a5c..e47d723 100644 --- a/srcs/parsing/heredoc.c +++ b/srcs/parsing/heredoc.c @@ -72,13 +72,7 @@ void read_hereinput(char *limiter, t_node *lst, t_msh *msh) ft_fprintf(2, "heredoc> "); r = read(0, &c, 1); if (r == 0) - { - ft_fprintf(2, "\n"); - ft_fprintf(1, "%s\n", limiter); - free_linked_list(lst); - free_msh(msh); - exit(EXIT_SUCCESS); - } + exit_heredoc(limiter, msh, lst); while (r && c != '\n' && c != '\0') { if (c != '\n' && c != '\0') @@ -87,12 +81,7 @@ void read_hereinput(char *limiter, t_node *lst, t_msh *msh) } buf[i] = '\0'; if (ft_strncmp(buf, limiter, ft_strlen(limiter)) == 0) - { - ft_fprintf(1, "%s\n", buf); - free_msh(msh); - free_linked_list(lst); - exit(EXIT_SUCCESS); - } + end_heredoc(buf, msh, lst); buf[i++] = '\n'; buf[i] = '\0'; ft_fprintf(1, "%s", buf); @@ -128,7 +117,7 @@ void parse_heredoc(char *limiter, t_node *lst, t_msh *msh) void create_heredoc(t_node *lst, t_msh *msh) { - t_node *tmp; + t_node *tmp; tmp = lst; while (lst) diff --git a/srcs/parsing/heredoc_utils.c b/srcs/parsing/heredoc_utils.c new file mode 100644 index 0000000..17644e7 --- /dev/null +++ b/srcs/parsing/heredoc_utils.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* heredoc_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: lderidde +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/12 13:41:03 by lderidde #+# #+# */ +/* Updated: 2025/02/12 13:41:03 by lderidde ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/minishell.h" + +void exit_heredoc(char *limiter, t_msh *msh, t_node *lst) +{ + ft_fprintf(2, "\n"); + ft_fprintf(1, "%s\n", limiter); + free_linked_list(lst); + free_msh(msh); + exit(EXIT_SUCCESS); +} + +void end_heredoc(char *buf, t_msh *msh, t_node *lst) +{ + ft_fprintf(1, "%s\n", buf); + free_msh(msh); + free_linked_list(lst); + exit(EXIT_SUCCESS); +} diff --git a/srcs/powerline.c b/srcs/powerline.c index 34b855d..da02a53 100644 --- a/srcs/powerline.c +++ b/srcs/powerline.c @@ -11,6 +11,7 @@ /* ************************************************************************** */ #include "../includes/minishell.h" +#include static void handle_input(char *in, t_msh *msh) { @@ -50,16 +51,17 @@ char *get_pwd(void) char *powerline(t_msh *msh) { - char *pwd; - char *input; - char *prompt; - char *separator; - struct winsize w; + char *pwd; + char *input; + char *prompt; + char *separator; + struct winsize w; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); pwd = get_pwd(); separator = rep_c('-', w.ws_col); - prompt = ft_sprintf("%s%s%s\n%s  MMOAT %s%s %s%s %s%s%s ", SEP, separator, RESET, POW1, POW2, POW3, + prompt = ft_sprintf("%s%s%s\n%s  MMOAT %s%s %s%s %s%s%s ", + SEP, separator, RESET, POW1, POW2, POW3, POW4, pwd, RESET, POW5, RESET); input = readline(prompt); handle_input(input, msh); diff --git a/srcs/sig.c b/srcs/sig.c index 8877c04..68444ea 100644 --- a/srcs/sig.c +++ b/srcs/sig.c @@ -43,5 +43,4 @@ void handle_sigint(int sig) void handle_sigquit(int sig) { (void)sig; - // ft_printf("\b\b"); }