This commit is contained in:
Loic Deridder
2025-02-12 13:48:54 +01:00
parent 256724e601
commit 3ac1625f5a
12 changed files with 89 additions and 61 deletions

View File

@@ -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);

View File

@@ -13,6 +13,8 @@
#ifndef AST_H
# define AST_H
# include <unistd.h>
typedef struct s_node t_node;
typedef struct s_msh t_msh;
@@ -79,7 +81,8 @@ 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);

View File

@@ -41,4 +41,5 @@ 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);
#endif

View File

@@ -13,7 +13,6 @@
#ifndef HEREDOC_H
# define HEREDOC_H
typedef struct s_node t_node;
typedef struct s_msh t_msh;

View File

@@ -22,5 +22,7 @@ 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

View File

@@ -48,11 +48,13 @@ typedef struct s_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 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);
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);
@@ -62,7 +64,7 @@ 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 debug_token_list(t_node *lst, char *msg);
void set_token(t_node *head);
#endif

View File

@@ -13,6 +13,7 @@
#include "../includes/minishell.h"
#include <readline/history.h>
#include <readline/readline.h>
#include <termios.h>
static void add_prevhistory(t_msh *msh)
{

View File

@@ -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);

View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* heredoc_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@@ -11,6 +11,7 @@
/* ************************************************************************** */
#include "../includes/minishell.h"
#include <sys/ioctl.h>
static void handle_input(char *in, t_msh *msh)
{
@@ -59,7 +60,8 @@ char *powerline(t_msh *msh)
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);

View File

@@ -43,5 +43,4 @@ void handle_sigint(int sig)
void handle_sigquit(int sig)
{
(void)sig;
// ft_printf("\b\b");
}