norm 2
This commit is contained in:
parent
a5e877fdd5
commit
c2efcca0fa
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
static int is_command_token(t_token *token)
|
static int is_command_token(t_token *token)
|
||||||
{
|
{
|
||||||
return (token->type < 3 || redirect_token_type(token));
|
return (token->type < 3 || redirect_token_type(token));
|
||||||
}
|
}
|
||||||
@ -31,7 +31,8 @@ t_list *parser_get_commands(t_minishell *minishell)
|
|||||||
while (current)
|
while (current)
|
||||||
{
|
{
|
||||||
token = (t_token *) current->content;
|
token = (t_token *) current->content;
|
||||||
command = parser_command_new(minishell, ft_strdup_safe(minishell, token->value));
|
command = parser_command_new(minishell,
|
||||||
|
ft_strdup_safe(minishell, token->value));
|
||||||
command->args = parser_get_arguments(current, minishell);
|
command->args = parser_get_arguments(current, minishell);
|
||||||
command->redirect_in = redirect_get_inputs(minishell, current);
|
command->redirect_in = redirect_get_inputs(minishell, current);
|
||||||
command->redirect_out = redirect_get_outputs(minishell, current);
|
command->redirect_out = redirect_get_outputs(minishell, current);
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */
|
/* Created: 2025/02/11 16:18:21 by qmennen #+# #+# */
|
||||||
/* Updated: 2025/02/25 14:41:57 by whaffman ######## odam.nl */
|
/* Updated: 2025/02/26 15:32:45 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,7 +17,6 @@ t_command *parser_command_new(t_minishell *minishell, char *cmd)
|
|||||||
t_command *command;
|
t_command *command;
|
||||||
|
|
||||||
command = malloc_safe(minishell, sizeof(t_command));
|
command = malloc_safe(minishell, sizeof(t_command));
|
||||||
\
|
|
||||||
command->args = NULL;
|
command->args = NULL;
|
||||||
command->fd_in = 0;
|
command->fd_in = 0;
|
||||||
command->fd_out = 1;
|
command->fd_out = 1;
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* :::::::: */
|
||||||
/* prompt.c :+: :+: :+: */
|
/* prompt.c :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ */
|
||||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
|
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/25 18:41:56 by qmennen ### ########.fr */
|
/* Updated: 2025/02/26 15:33:15 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ char *get_user(t_minishell *minishell)
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_home_len(t_minishell *minishell, char *cwd)
|
int get_home_len(t_minishell *minishell, char *cwd)
|
||||||
{
|
{
|
||||||
t_environment *home;
|
t_environment *home;
|
||||||
int home_len;
|
int home_len;
|
||||||
@ -83,7 +83,7 @@ char *get_path(t_minishell *minishell)
|
|||||||
ft_strlcpy(result, BLUE, len);
|
ft_strlcpy(result, BLUE, len);
|
||||||
ft_strlcat(result, cwd, len);
|
ft_strlcat(result, cwd, len);
|
||||||
ft_strlcat(result, RESET "> ", len);
|
ft_strlcat(result, RESET "> ", len);
|
||||||
free_safe(minishell,(void **) &cwd);
|
free_safe(minishell, (void **) &cwd);
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "redirect.h"
|
#include "redirect.h"
|
||||||
|
|
||||||
static void process_heredoc(t_minishell *ms, t_token *heredoc, t_token *delim)
|
static void process_heredoc(t_minishell *msh, t_token *heredoc, t_token *delim)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
int fd;
|
int fd;
|
||||||
@ -20,7 +20,6 @@ static void process_heredoc(t_minishell *ms, t_token *heredoc, t_token *delim)
|
|||||||
fd = open(".ms_heredoc", O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
fd = open(".ms_heredoc", O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||||
if (fd < 0) //TODO: Will this work?
|
if (fd < 0) //TODO: Will this work?
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
line = readline(">");
|
line = readline(">");
|
||||||
@ -33,14 +32,14 @@ static void process_heredoc(t_minishell *ms, t_token *heredoc, t_token *delim)
|
|||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
heredoc->type = T_REDIRECT_IN;
|
heredoc->type = T_REDIRECT_IN;
|
||||||
delim->value = ft_strdup_safe(ms, ".ms_heredoc");
|
delim->value = ft_strdup_safe(msh, ".ms_heredoc");
|
||||||
}
|
}
|
||||||
|
|
||||||
t_list *redirect_get_inputs(t_minishell *minishell, t_list *list)
|
t_list *redirect_get_inputs(t_minishell *minishell, t_list *list)
|
||||||
{
|
{
|
||||||
t_list *current;
|
t_list *current;
|
||||||
t_list *redirects;
|
t_list *redirects;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
redirects = NULL;
|
redirects = NULL;
|
||||||
current = list;
|
current = list;
|
||||||
|
|||||||
@ -12,11 +12,11 @@
|
|||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
t_list *redirect_get_outputs(t_minishell *minishell, t_list *list)
|
t_list *redirect_get_outputs(t_minishell *msh, t_list *list)
|
||||||
{
|
{
|
||||||
t_list *current;
|
t_list *current;
|
||||||
t_list *redirects;
|
t_list *redirects;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
redirects = NULL;
|
redirects = NULL;
|
||||||
current = list;
|
current = list;
|
||||||
@ -33,13 +33,13 @@ t_list *redirect_get_outputs(t_minishell *minishell, t_list *list)
|
|||||||
if (redirect_is_valid(current, token))
|
if (redirect_is_valid(current, token))
|
||||||
{
|
{
|
||||||
ft_lstadd_front(&redirects,
|
ft_lstadd_front(&redirects,
|
||||||
ft_lstnew_safe(minishell, redirect_new(minishell, token->type, ft_strdup_safe(minishell, ((t_token *)current->next->content)->value))));
|
ft_lstnew_safe(msh, redirect_new(msh, token->type, ft_strdup_safe(msh, ((t_token *)current->next->content)->value))));
|
||||||
current = current->next;
|
current = current->next;
|
||||||
continue ;
|
continue ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_lstadd_front(&redirects, ft_lstnew_safe(minishell, redirect_new(minishell, T_ERROR, NULL)));
|
ft_lstadd_front(&redirects, ft_lstnew_safe(msh, redirect_new(msh, T_ERROR, NULL)));
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
current = current->next;
|
current = current->next;
|
||||||
|
|||||||
@ -12,14 +12,14 @@
|
|||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
t_redirect *redirect_new(t_minishell * minishell, t_token_type type, char *value)
|
t_redirect *redirect_new(t_minishell *msh, t_token_type type, char *value)
|
||||||
{
|
{
|
||||||
t_redirect *result;
|
t_redirect *result;
|
||||||
|
|
||||||
result = malloc_safe(minishell, sizeof(t_redirect));
|
result = malloc_safe(msh, sizeof(t_redirect));
|
||||||
result->type = type;
|
result->type = type;
|
||||||
result->value = NULL;
|
result->value = NULL;
|
||||||
if (value)
|
if (value)
|
||||||
result->value = value;
|
result->value = value;
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,26 +12,31 @@
|
|||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int redirect_token_type(t_token *token)
|
int redirect_token_type(t_token *token)
|
||||||
{
|
{
|
||||||
return (token->type == T_REDIRECT_IN || token->type == T_HEREDOC ||
|
return (token->type == T_REDIRECT_IN
|
||||||
token->type == T_REDIRECT_OUT || token->type == T_APPEND_OUT);
|
|| token->type == T_HEREDOC
|
||||||
|
|| token->type == T_REDIRECT_OUT
|
||||||
|
|| token->type == T_APPEND_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int redirect_is_valid(t_list *lst, t_token *token)
|
int redirect_is_valid(t_list *lst, t_token *token)
|
||||||
{
|
{
|
||||||
t_token *next;
|
t_token *next;
|
||||||
|
|
||||||
if (!lst->next)
|
|
||||||
return (0);
|
|
||||||
next = (t_token *)lst->next->content;
|
|
||||||
if (!next)
|
|
||||||
return (0);
|
|
||||||
return (redirect_token_type(token) && next->type < 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
int redirect_is_delimiter(t_token *token)
|
if (!lst->next)
|
||||||
|
return (0);
|
||||||
|
next = (t_token *)lst->next->content;
|
||||||
|
if (!next)
|
||||||
|
return (0);
|
||||||
|
return (redirect_token_type(token) && next->type < 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
int redirect_is_delimiter(t_token *token)
|
||||||
{
|
{
|
||||||
return (token->type == T_PIPE || token->type == T_AND ||
|
return (token->type == T_PIPE
|
||||||
token->type == T_OR || token->type == T_EOF || token->type == T_ERROR);
|
|| token->type == T_AND
|
||||||
|
|| token->type == T_OR
|
||||||
|
|| token->type == T_EOF
|
||||||
|
|| token->type == T_ERROR);
|
||||||
}
|
}
|
||||||
@ -6,13 +6,12 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */
|
/* Created: 2025/02/19 12:18:47 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/19 17:30:12 by whaffman ######## odam.nl */
|
/* Updated: 2025/02/26 15:42:30 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
|
||||||
void sigint_minishell_handler(int signum)
|
void sigint_minishell_handler(int signum)
|
||||||
{
|
{
|
||||||
(void)signum;
|
(void)signum;
|
||||||
@ -36,30 +35,3 @@ void sig_parent_handler(int signum)
|
|||||||
(void)signum;
|
(void)signum;
|
||||||
ft_putstr_fd("\n", 1);
|
ft_putstr_fd("\n", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void signal_init_minishell(void)
|
|
||||||
{
|
|
||||||
signal(SIGINT, sigint_minishell_handler);
|
|
||||||
signal(SIGQUIT, SIG_IGN);
|
|
||||||
}
|
|
||||||
|
|
||||||
void signal_init_parent(void)
|
|
||||||
{
|
|
||||||
signal(SIGINT, sig_parent_handler);
|
|
||||||
signal(SIGQUIT, sig_parent_handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void signal_init_child(void)
|
|
||||||
{
|
|
||||||
signal(SIGINT, SIG_DFL);
|
|
||||||
signal(SIGQUIT, SIG_DFL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void signal_init_heredoc(void)
|
|
||||||
{
|
|
||||||
signal(SIGINT, sigint_heredoc_handler);
|
|
||||||
signal(SIGQUIT, SIG_IGN);
|
|
||||||
}
|
|
||||||
|
|||||||
37
src/signal/signal_init.c.c
Normal file
37
src/signal/signal_init.c.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* :::::::: */
|
||||||
|
/* signal_init.c.c :+: :+: */
|
||||||
|
/* +:+ */
|
||||||
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
|
/* +#+ */
|
||||||
|
/* Created: 2025/02/26 15:39:01 by whaffman #+# #+# */
|
||||||
|
/* Updated: 2025/02/26 15:39:46 by whaffman ######## odam.nl */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void signal_init_minishell(void)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sigint_minishell_handler);
|
||||||
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void signal_init_parent(void)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sig_parent_handler);
|
||||||
|
signal(SIGQUIT, sig_parent_handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
void signal_init_child(void)
|
||||||
|
{
|
||||||
|
signal(SIGINT, SIG_DFL);
|
||||||
|
signal(SIGQUIT, SIG_DFL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void signal_init_heredoc(void)
|
||||||
|
{
|
||||||
|
signal(SIGINT, sigint_heredoc_handler);
|
||||||
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
}
|
||||||
@ -12,10 +12,9 @@
|
|||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
void check_malloc(t_minishell *minishell, void *ptr)
|
||||||
void check_malloc(t_minishell *minishell, void *ptr)
|
|
||||||
{
|
{
|
||||||
t_list *new;
|
t_list *new;
|
||||||
|
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
|
||||||
void error_msg(char *func, char *msg)
|
void error_msg(char *func, char *msg)
|
||||||
{
|
{
|
||||||
if (errno)
|
if (errno)
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/05 16:03:57 by whaffman #+# #+# */
|
/* Created: 2025/02/05 16:03:57 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/25 16:02:57 by whaffman ######## odam.nl */
|
/* Updated: 2025/02/26 15:43:00 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
void free_minishell(t_minishell **minishell)
|
void free_minishell(t_minishell **minishell)
|
||||||
{
|
{
|
||||||
// if ((*minishell)->line)
|
|
||||||
// free_minishell_line(*minishell);
|
|
||||||
// if ((*minishell)->environment)
|
|
||||||
// environment_free_list(*minishell);
|
|
||||||
free_freelist(*minishell);
|
free_freelist(*minishell);
|
||||||
free(*minishell);
|
free(*minishell);
|
||||||
*minishell = NULL;
|
*minishell = NULL;
|
||||||
|
|||||||
@ -6,16 +6,12 @@
|
|||||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||||
/* +#+ */
|
/* +#+ */
|
||||||
/* Created: 2025/02/25 15:09:34 by whaffman #+# #+# */
|
/* Created: 2025/02/25 15:09:34 by whaffman #+# #+# */
|
||||||
/* Updated: 2025/02/25 18:06:06 by whaffman ######## odam.nl */
|
/* Updated: 2025/02/26 15:43:08 by whaffman ######## odam.nl */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
#include <execinfo.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
|
|
||||||
void free_safe(t_minishell *minishell, void **ptr)
|
void free_safe(t_minishell *minishell, void **ptr)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -20,4 +20,3 @@ char *ft_strjoin_safe(t_minishell *minishell, const char *s1, const char *s2)
|
|||||||
check_malloc(minishell, new_str);
|
check_malloc(minishell, new_str);
|
||||||
return (new_str);
|
return (new_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user