norm 2
This commit is contained in:
parent
a5e877fdd5
commit
c2efcca0fa
@ -12,7 +12,7 @@
|
||||
|
||||
#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));
|
||||
}
|
||||
@ -31,7 +31,8 @@ t_list *parser_get_commands(t_minishell *minishell)
|
||||
while (current)
|
||||
{
|
||||
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->redirect_in = redirect_get_inputs(minishell, current);
|
||||
command->redirect_out = redirect_get_outputs(minishell, current);
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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;
|
||||
|
||||
command = malloc_safe(minishell, sizeof(t_command));
|
||||
\
|
||||
command->args = NULL;
|
||||
command->fd_in = 0;
|
||||
command->fd_out = 1;
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* prompt.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/25 18:41:56 by qmennen ### ########.fr */
|
||||
/* :::::::: */
|
||||
/* prompt.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/26 15:33:15 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -33,7 +33,7 @@ char *get_user(t_minishell *minishell)
|
||||
return (result);
|
||||
}
|
||||
|
||||
int get_home_len(t_minishell *minishell, char *cwd)
|
||||
int get_home_len(t_minishell *minishell, char *cwd)
|
||||
{
|
||||
t_environment *home;
|
||||
int home_len;
|
||||
@ -83,7 +83,7 @@ char *get_path(t_minishell *minishell)
|
||||
ft_strlcpy(result, BLUE, len);
|
||||
ft_strlcat(result, cwd, len);
|
||||
ft_strlcat(result, RESET "> ", len);
|
||||
free_safe(minishell,(void **) &cwd);
|
||||
free_safe(minishell, (void **) &cwd);
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
#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;
|
||||
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);
|
||||
if (fd < 0) //TODO: Will this work?
|
||||
return ;
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
line = readline(">");
|
||||
@ -33,14 +32,14 @@ static void process_heredoc(t_minishell *ms, t_token *heredoc, t_token *delim)
|
||||
}
|
||||
close(fd);
|
||||
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 *current;
|
||||
t_list *redirects;
|
||||
t_token *token;
|
||||
t_list *current;
|
||||
t_list *redirects;
|
||||
t_token *token;
|
||||
|
||||
redirects = NULL;
|
||||
current = list;
|
||||
|
||||
@ -12,11 +12,11 @@
|
||||
|
||||
#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 *redirects;
|
||||
t_token *token;
|
||||
t_list *current;
|
||||
t_list *redirects;
|
||||
t_token *token;
|
||||
|
||||
redirects = NULL;
|
||||
current = list;
|
||||
@ -33,13 +33,13 @@ t_list *redirect_get_outputs(t_minishell *minishell, t_list *list)
|
||||
if (redirect_is_valid(current, token))
|
||||
{
|
||||
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;
|
||||
continue ;
|
||||
}
|
||||
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 ;
|
||||
}
|
||||
current = current->next;
|
||||
|
||||
@ -12,14 +12,14 @@
|
||||
|
||||
#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->type = type;
|
||||
result->value = NULL;
|
||||
if (value)
|
||||
result->value = value;
|
||||
return (result);
|
||||
result = malloc_safe(msh, sizeof(t_redirect));
|
||||
result->type = type;
|
||||
result->value = NULL;
|
||||
if (value)
|
||||
result->value = value;
|
||||
return (result);
|
||||
}
|
||||
|
||||
@ -12,26 +12,31 @@
|
||||
|
||||
#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 ||
|
||||
token->type == T_REDIRECT_OUT || token->type == T_APPEND_OUT);
|
||||
return (token->type == T_REDIRECT_IN
|
||||
|| 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;
|
||||
|
||||
if (!lst->next)
|
||||
return (0);
|
||||
next = (t_token *)lst->next->content;
|
||||
if (!next)
|
||||
return (0);
|
||||
return (redirect_token_type(token) && next->type < 3);
|
||||
}
|
||||
t_token *next;
|
||||
|
||||
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 ||
|
||||
token->type == T_OR || token->type == T_EOF || token->type == T_ERROR);
|
||||
return (token->type == T_PIPE
|
||||
|| 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> +#+ */
|
||||
/* +#+ */
|
||||
/* 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"
|
||||
|
||||
|
||||
void sigint_minishell_handler(int signum)
|
||||
{
|
||||
(void)signum;
|
||||
@ -36,30 +35,3 @@ void sig_parent_handler(int signum)
|
||||
(void)signum;
|
||||
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"
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
|
||||
void error_msg(char *func, char *msg)
|
||||
{
|
||||
if (errno)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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)
|
||||
{
|
||||
// if ((*minishell)->line)
|
||||
// free_minishell_line(*minishell);
|
||||
// if ((*minishell)->environment)
|
||||
// environment_free_list(*minishell);
|
||||
free_freelist(*minishell);
|
||||
free(*minishell);
|
||||
*minishell = NULL;
|
||||
|
||||
@ -6,16 +6,12 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* 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 <execinfo.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
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);
|
||||
return (new_str);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user