This commit is contained in:
gazhonsepaskwa
2025-02-12 11:39:05 +01:00
parent 2350222238
commit 99a74ea9ac
7 changed files with 25 additions and 14 deletions

View File

@@ -13,7 +13,7 @@
#ifndef MINISHELL_H #ifndef MINISHELL_H
# define MINISHELL_H # define MINISHELL_H
# define DEBUG 0 # define DEBUG 1
# ifndef DIO_PATH # ifndef DIO_PATH
# define DIO_PATH "ast.xml" # define DIO_PATH "ast.xml"

View File

@@ -15,8 +15,8 @@
# include "../minishell.h" # include "../minishell.h"
void read_hereinput(char *limiter); void read_hereinput(char *limiter, t_node *lst, t_msh *msh);
void parse_heredoc(char *limiter); void parse_heredoc(char *limiter, t_node *lst, t_msh *msh);
void create_heredoc(t_node *lst); void create_heredoc(t_node *lst, t_msh *msh);
#endif #endif

View File

@@ -60,7 +60,7 @@ static int ifremove_quote(char **str)
return (ret); return (ret);
} }
void read_hereinput(char *limiter) void read_hereinput(char *limiter, t_node *lst, t_msh *msh)
{ {
char buf[100000]; char buf[100000];
char c; char c;
@@ -75,6 +75,8 @@ void read_hereinput(char *limiter)
{ {
ft_fprintf(2, "\n"); ft_fprintf(2, "\n");
ft_fprintf(1, "%s\n", limiter); ft_fprintf(1, "%s\n", limiter);
free_linked_list(lst);
free_msh(msh);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
while (r && c != '\n' && c != '\0') while (r && c != '\n' && c != '\0')
@@ -87,6 +89,8 @@ void read_hereinput(char *limiter)
if (ft_strncmp(buf, limiter, ft_strlen(limiter)) == 0) if (ft_strncmp(buf, limiter, ft_strlen(limiter)) == 0)
{ {
ft_fprintf(1, "%s\n", buf); ft_fprintf(1, "%s\n", buf);
free_msh(msh);
free_linked_list(lst);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
buf[i++] = '\n'; buf[i++] = '\n';
@@ -94,7 +98,7 @@ void read_hereinput(char *limiter)
ft_fprintf(1, "%s", buf); ft_fprintf(1, "%s", buf);
} }
void parse_heredoc(char *limiter) void parse_heredoc(char *limiter, t_node *lst, t_msh *msh)
{ {
int fd; int fd;
pid_t pid; pid_t pid;
@@ -107,7 +111,7 @@ void parse_heredoc(char *limiter)
dup2(fd, STDOUT_FILENO); dup2(fd, STDOUT_FILENO);
close(fd); close(fd);
while (1) while (1)
read_hereinput(limiter); read_hereinput(limiter, lst, msh);
} }
else if (pid > 0) else if (pid > 0)
{ {
@@ -122,14 +126,14 @@ void parse_heredoc(char *limiter)
} }
} }
void create_heredoc(t_node *lst) void create_heredoc(t_node *lst, t_msh *msh)
{ {
while (lst) while (lst)
{ {
if (lst->pressision == HEREDOC && lst->next && lst->next->pressision) if (lst->pressision == HEREDOC && lst->next && lst->next->pressision)
{ {
lst = lst->next; lst = lst->next;
parse_heredoc(lst->val); parse_heredoc(lst->val, lst, msh);
} }
lst = lst->next; lst = lst->next;
} }

View File

@@ -46,7 +46,7 @@ t_ast_n *parser(char *input, t_msh *msh)
lst = tokenize(input); lst = tokenize(input);
if (!lst) if (!lst)
return (NULL); return (NULL);
create_heredoc(lst); create_heredoc(lst, msh);
if (DEBUG) if (DEBUG)
{ {
dio = drawio_init(DIO_PATH); dio = drawio_init(DIO_PATH);

View File

@@ -32,15 +32,15 @@ int add_node_back(t_node **head, char *val, t_token token, t_pres pres)
{ {
t_node *tmp; t_node *tmp;
tmp = *head;
if (!val) if (!val)
return (0); return (0);
if (!head || !(*head)) if (!head || !(*head))
{ {
(*head) = create_node(val, token); *head = create_node(val, token);
(*head)->pressision = pres; (*head)->pressision = pres;
return (1); return (1);
} }
tmp = *head;
while (tmp->next != NULL) while (tmp->next != NULL)
tmp = tmp->next; tmp = tmp->next;
tmp->next = create_node(val, token); tmp->next = create_node(val, token);

View File

@@ -26,7 +26,7 @@ static t_node *tokenize_base(char *str)
while (tab[i]) while (tab[i])
{ {
if (!add_node_back(&head, tab[i], 0, 0)) if (!add_node_back(&head, tab[i], 0, 0))
return (free(tab), NULL); return (free_tab(tab), NULL);
i++; i++;
} }
free_tab(tab); free_tab(tab);
@@ -116,12 +116,16 @@ t_node *tokenize(char *str)
head = tokenize_base(str); head = tokenize_base(str);
if (!head) if (!head)
return (NULL); return (NULL);
debug_token_list(head, "tokenizer");
if (!trim_nodes(head)) if (!trim_nodes(head))
return (NULL); return (NULL);
debug_token_list(head, "tokenizer");
if (!unstick_nodes(head)) if (!unstick_nodes(head))
return (NULL); return (NULL);
debug_token_list(head, "tokenizer");
stick_quote_node(head, 39); stick_quote_node(head, 39);
stick_quote_node(head, '"'); stick_quote_node(head, '"');
debug_token_list(head, "tokenizer");
set_token(head); set_token(head);
del_void_nodes(&head); del_void_nodes(&head);
debug_token_list(head, "tokenizer"); debug_token_list(head, "tokenizer");

View File

@@ -53,14 +53,17 @@ char *powerline(t_msh *msh)
char *pwd; char *pwd;
char *input; char *input;
char *prompt; char *prompt;
char *separator;
struct winsize w; struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
pwd = get_pwd(); pwd = get_pwd();
prompt = ft_sprintf("%s%s%s\n%s  MMOAT %s%s %s%s %s%s%s ", SEP, rep_c('-', w.ws_col), RESET, POW1, POW2, POW3, 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,
POW4, pwd, RESET, POW5, RESET); POW4, pwd, RESET, POW5, RESET);
input = readline(prompt); input = readline(prompt);
handle_input(input, msh); handle_input(input, msh);
free(separator);
free(prompt); free(prompt);
free(pwd); free(pwd);
return (input); return (input);