fixes + norm

This commit is contained in:
gazhonsepaskwa
2025-02-11 16:47:02 +01:00
parent 23791a53d9
commit ced584b17a
13 changed files with 239 additions and 194 deletions

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* parsing.h :+: :+: :+: */ /* parsing.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/24 14:45:28 by nalebrun #+# #+# */ /* Created: 2025/01/24 14:45:28 by nalebrun #+# #+# */
/* Updated: 2025/01/24 14:45:28 by nalebrun ### ########.fr */ /* Updated: 2025/02/11 16:45:11 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -17,4 +17,8 @@
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);
#endif #endif

View File

@@ -64,5 +64,7 @@ int find_quote_node(t_node *head, char q);
int syntax_error(t_node *head); int syntax_error(t_node *head);
char *copy_meta(char *val, int *copied); char *copy_meta(char *val, int *copied);
char *copy_unmeta(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 #endif

32
srcs/interpret_cmd.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* interpret_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 16:42:53 by nalebrun #+# #+# */
/* Updated: 2025/02/11 16:45:31 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
void interpret_cmd(char **input, t_msh *msh)
{
msh->head = parser(*input, msh);
if (!msh->head)
{
ft_free(input);
return ;
}
msh->here_fd = open(".heredoc", O_RDONLY);
msh->ex_code = execute_command(msh->head);
get_next_line(msh->here_fd, 1);
if (msh->here_fd != -1)
close(msh->here_fd);
unlink(".heredoc");
free_ast(msh->head);
msh->head = NULL;
ft_free(input);
}

View File

@@ -3,30 +3,30 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* main.c :+: :+: :+: */ /* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/27 14:16:52 by lderidde #+# #+# */ /* Created: 2025/01/27 14:16:52 by lderidde #+# #+# */
/* Updated: 2025/02/11 13:22:49 by lderidde ### ########.fr */ /* Updated: 2025/02/11 16:44:10 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../includes/minishell.h" #include "../includes/minishell.h"
#include <readline/history.h> #include <readline/history.h>
#include <readline/readline.h> #include <readline/readline.h>
int g_sig = 0; int g_sig = 0;
void handle_sigint(int sig) void handle_sigint(int sig)
{ {
(void)sig; (void)sig;
g_sig = SIGINT; g_sig = SIGINT;
rl_replace_line("", 0); rl_replace_line("", 0);
// rl_on_new_line(); // rl_on_new_line();
rl_done = 1; rl_done = 1;
rl_redisplay(); rl_redisplay();
} }
void handle_sigquit(int sig) void handle_sigquit(int sig)
{ {
(void)sig; (void)sig;
// ft_printf("\b\b"); // ft_printf("\b\b");
@@ -48,23 +48,23 @@ static void add_prevhistory(t_msh *msh)
} }
} }
static void interpret_cmd(char **input, t_msh *msh) int interactive_mode(t_msh *msh)
{ {
msh->head = parser(*input, msh); msh->input = malloc(1);
if (!msh->head) msh->input[0] = 0;
while (!msh->input[0] || is_only_space(msh->input) || g_sig == SIGINT)
{ {
ft_free(input); g_sig = 0;
return ; free(msh->input);
msh->input = powerline(msh);
if (!msh->input)
return (0);
} }
msh->here_fd = open(".heredoc", O_RDONLY); if (!msh->input)
msh->ex_code = execute_command(msh->head); return (1);
get_next_line(msh->here_fd, 1); if (g_sig != SIGINT)
if (msh->here_fd != -1) interpret_cmd(&msh->input, msh);
close(msh->here_fd); return (1);
unlink(".heredoc");
free_ast(msh->head);
msh->head = NULL;
ft_free(input);
} }
int main(int ac, char **av, char **envp) int main(int ac, char **av, char **envp)
@@ -79,22 +79,8 @@ int main(int ac, char **av, char **envp)
if (ac == 1) if (ac == 1)
{ {
while (1) while (1)
{ if (!interactive_mode(msh))
msh->input = malloc (1); break ;
msh->input[0] = 0;
while (!msh->input[0] || is_only_space(msh->input) || g_sig == SIGINT)
{
g_sig = 0;
free(msh->input);
msh->input = powerline(msh);
if (!msh->input)
break;
}
if (!msh->input)
break;
if (g_sig != SIGINT)
interpret_cmd(&msh->input, msh);
}
} }
else else
{ {

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* msh_struct.c :+: :+: :+: */ /* msh_struct.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/06 15:32:03 by lderidde #+# #+# */ /* Created: 2025/02/06 15:32:03 by lderidde #+# #+# */
/* Updated: 2025/02/11 13:18:58 by lderidde ### ########.fr */ /* Updated: 2025/02/11 16:34:46 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -15,7 +15,7 @@
static char **ft_setnewenv(void) static char **ft_setnewenv(void)
{ {
char **envp; char **envp;
envp = malloc(sizeof(char *) * 2); envp = malloc(sizeof(char *) * 2);
if (!envp) if (!envp)
@@ -27,7 +27,7 @@ static char **ft_setnewenv(void)
return (envp); return (envp);
} }
t_msh *init_msh(char **envp) t_msh *init_msh(char **envp)
{ {
t_msh *msh; t_msh *msh;
int fd; int fd;
@@ -47,7 +47,7 @@ t_msh *init_msh(char **envp)
return (msh); return (msh);
} }
void free_msh(t_msh *msh) void free_msh(t_msh *msh)
{ {
free_tab(msh->env); free_tab(msh->env);
if (msh->hist != -1) if (msh->hist != -1)

View File

@@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* heredoc.c :+: :+: :+: */ /* heredoc.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 09:01:14 by lderidde #+# #+# */ /* Created: 2025/02/11 09:01:14 by lderidde #+# #+# */
/* Updated: 2025/02/11 10:45:08 by lderidde ### ########.fr */ /* Updated: 2025/02/11 16:31:50 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -25,8 +25,8 @@ static void remove_quote(char **str, char c)
new = ft_calloc(len - 1, sizeof(char)); new = ft_calloc(len - 1, sizeof(char));
while (i < len - 2) while (i < len - 2)
{ {
if ((&((*str)[k]) == ft_strchr(*str, c)) || if ((&((*str)[k]) == ft_strchr(*str, c))
(&((*str)[k]) == ft_strrchr(*str, c))) || (&((*str)[k]) == ft_strrchr(*str, c)))
{ {
k++; k++;
} }
@@ -37,11 +37,11 @@ static void remove_quote(char **str, char c)
*str = new; *str = new;
} }
static int ifremove_quote(char **str) static int ifremove_quote(char **str)
{ {
char c; char c;
int ret; int ret;
ret = 0; ret = 0;
if (!ft_strchr(*str, '\'') && !ft_strchr(*str, '\"')) if (!ft_strchr(*str, '\'') && !ft_strchr(*str, '\"'))
c = 0; c = 0;
@@ -73,8 +73,8 @@ void read_hereinput(char *limiter)
r = read(0, &c, 1); r = read(0, &c, 1);
if (r == 0) if (r == 0)
{ {
ft_fprintf (2, "\n"); ft_fprintf(2, "\n");
ft_fprintf (1, "%s\n", limiter); ft_fprintf(1, "%s\n", limiter);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
while (r && c != '\n' && c != '\0') while (r && c != '\n' && c != '\0')
@@ -96,7 +96,7 @@ void read_hereinput(char *limiter)
void parse_heredoc(char *limiter) void parse_heredoc(char *limiter)
{ {
int fd; int fd;
pid_t pid; pid_t pid;
fd = open(".heredoc", O_WRONLY | O_CREAT | O_APPEND, 0666); fd = open(".heredoc", O_WRONLY | O_CREAT | O_APPEND, 0666);
@@ -105,20 +105,20 @@ void parse_heredoc(char *limiter)
{ {
ifremove_quote(&limiter); ifremove_quote(&limiter);
dup2(fd, STDOUT_FILENO); dup2(fd, STDOUT_FILENO);
close (fd); close(fd);
while (1) while (1)
read_hereinput(limiter); read_hereinput(limiter);
} }
else if (pid > 0) else if (pid > 0)
{ {
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
close (fd); close(fd);
} }
else else
{ {
close (fd); close(fd);
perror("fork"); perror("fork");
exit (EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }

View File

@@ -6,7 +6,7 @@
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/07 12:08:53 by nalebrun #+# #+# */ /* Created: 2025/02/07 12:08:53 by nalebrun #+# #+# */
/* Updated: 2025/02/07 17:58:30 by nalebrun ### ########.fr */ /* Updated: 2025/02/11 16:31:12 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -14,7 +14,7 @@
int syntax_err_mess(char *token_base, int selected) int syntax_err_mess(char *token_base, int selected)
{ {
char *token; char *token;
token = ft_strdup(token_base); token = ft_strdup(token_base);
if (selected == 0) if (selected == 0)
@@ -33,19 +33,9 @@ int syntax_err_mess(char *token_base, int selected)
return (1); return (1);
} }
int unexpected_token(t_node *node) static int check_unclosed(char *c, t_node *node)
{ {
if ((!ft_strncmp(node->val, "&", 1) && ft_strncmp(node->val, "&&", 2)) t_node *cpy;
|| !ft_strncmp(node->val, ";", 1) || !ft_strncmp(node->val, "[", 1)
|| !ft_strncmp(node->val, "]", 1) || !ft_strncmp(node->val, "{", 1)
|| !ft_strncmp(node->val, "}", 1))
return (1);
return (0);
}
int check_unclosed(char *c, t_node *node)
{
t_node *cpy;
int count; int count;
cpy = node; cpy = node;
@@ -65,28 +55,28 @@ int check_unclosed(char *c, t_node *node)
return (0); return (0);
} }
int check_unclosed_quote(char *c, t_node *node) static int check_unclosed_quote(char *c, t_node *node)
{ {
t_node *cpy; t_node *cpy;
int count; int count;
int len; int len;
cpy = node; cpy = node;
count = 0; count = 0;
while (cpy) while (cpy)
{ {
len = ft_strlen(cpy->val); len = ft_strlen(cpy->val);
if (len > 0 && cpy->val[0] == c[0]) if (len > 0 && cpy->val[0] == c[0])
{ {
if (len == 1 || cpy->val[len - 1] != c[0]) if (len == 1 || cpy->val[len - 1] != c[0])
count++; count++;
} }
cpy = cpy->next; cpy = cpy->next;
} }
return (count % 2); return (count % 2);
} }
int unclosed(t_node *head) int unclosed(t_node *head)
{ {
if (check_unclosed("()", head) != 0) if (check_unclosed("()", head) != 0)
return (syntax_err_mess("()", check_unclosed("()", head))); return (syntax_err_mess("()", check_unclosed("()", head)));
@@ -97,17 +87,6 @@ int unclosed(t_node *head)
return (0); return (0);
} }
int is_aop_operator(t_node *node)
{
if (!node || node->token != OPERATOR)
return (0);
if (node->pressision == AND
|| node->pressision == OR
|| node->pressision == PIPE)
return (1);
return (0);
}
int syntax_error(t_node *head) int syntax_error(t_node *head)
{ {
t_node *cpy; t_node *cpy;

View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* syntax_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 16:00:49 by nalebrun #+# #+# */
/* Updated: 2025/02/11 16:34:22 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/minishell.h"
int is_aop_operator(t_node *node)
{
if (!node || node->token != OPERATOR)
return (0);
if (node->pressision == AND || node->pressision == OR
|| node->pressision == PIPE)
return (1);
return (0);
}
int unexpected_token(t_node *node)
{
if ((!ft_strncmp(node->val, "&", 1) && ft_strncmp(node->val, "&&", 2))
|| !ft_strncmp(node->val, ";", 1) || !ft_strncmp(node->val, "[", 1)
|| !ft_strncmp(node->val, "]", 1) || !ft_strncmp(node->val, "{", 1)
|| !ft_strncmp(node->val, "}", 1))
return (1);
return (0);
}

View File

@@ -6,7 +6,7 @@
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 13:27:57 by lderidde #+# #+# */ /* Created: 2025/01/15 13:27:57 by lderidde #+# #+# */
/* Updated: 2025/02/07 17:26:04 by nalebrun ### ########.fr */ /* Updated: 2025/02/11 16:31:30 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -33,26 +33,6 @@ static t_node *tokenize_base(char *str)
return (head); return (head);
} }
static void set_token(t_node *head)
{
t_node *it;
t_token last_token;
t_pres last_pres;
it = head;
last_token = UNSET;
last_pres = UNDEFINED;
while (it != NULL)
{
it->token = get_token(it->val);
it->pressision = get_pressision(it->val, it->token, last_token,
last_pres);
last_token = it->token;
last_pres = it->pressision;
it = it->next;
}
}
static int unstick_nodes(t_node *head) static int unstick_nodes(t_node *head)
{ {
t_node *it; t_node *it;
@@ -89,7 +69,8 @@ static int stick_quote_node(t_node *head, char q)
it = head; it = head;
while (it != NULL) while (it != NULL)
{ {
if (ft_strchr(it->val, q) && ft_strchr(it->val, q) == ft_strrchr(it->val, q)) if (ft_strchr(it->val, q) && ft_strchr(it->val,
q) == ft_strrchr(it->val, q))
{ {
while (it->next && !ft_strchr(it->next->val, q)) while (it->next && !ft_strchr(it->next->val, q))
if (!merge_with_next_node(it)) if (!merge_with_next_node(it))
@@ -102,36 +83,19 @@ static int stick_quote_node(t_node *head, char q)
return (1); return (1);
} }
void debug_token_list(t_node* lst, char *msg) static void del_void_nodes(t_node **head)
{ {
t_node *cpy; t_node *cpy;
t_node *tmp;
cpy = lst;
if (DEBUG)
{
ft_debug("==================================================================={%s}\n", msg);
while (cpy)
{
ft_fprintf(2, "| %10s | TOKEN : %3d | PRESSISION : %3d |\n", cpy->val, cpy->token, cpy->pressision);
cpy = cpy->next;
}
ft_debug("===================================================================\n\n");
}
}
void del_void_nodes(t_node **head)
{
t_node *cpy;
t_node *tmp;
cpy = *head; cpy = *head;
if (ft_strlen((*head)->val) == 0) if (ft_strlen((*head)->val) == 0)
{ {
cpy = (*head)->next; cpy = (*head)->next;
free ((*head)->val); free((*head)->val);
free (*head); free(*head);
} }
*head = cpy; *head = cpy;
while (cpy) while (cpy)
{ {
if (cpy->next && ft_strlen(cpy->next->val) == 0) if (cpy->next && ft_strlen(cpy->next->val) == 0)
@@ -152,19 +116,12 @@ 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, "tokenize_base");
if (!trim_nodes(head)) if (!trim_nodes(head))
return (NULL); return (NULL);
debug_token_list(head, "trim_nodes");
if (!unstick_nodes(head)) if (!unstick_nodes(head))
return (NULL); return (NULL);
debug_token_list(head, "unstick_nodes");
stick_quote_node(head, 39); stick_quote_node(head, 39);
stick_quote_node(head, '"'); stick_quote_node(head, '"');
debug_token_list(head, "stick quote node");
// if (!trim_nodes(head))
// return (NULL);
// debug_token_list(head, "trim_nodes");
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

@@ -6,7 +6,7 @@
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/22 14:24:05 by nalebrun #+# #+# */ /* Created: 2025/01/22 14:24:05 by nalebrun #+# #+# */
/* Updated: 2025/02/07 18:04:31 by nalebrun ### ########.fr */ /* Updated: 2025/02/11 16:33:45 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@@ -15,16 +15,15 @@
int is_meta(char c) int is_meta(char c)
{ {
if (c == '&' || c == '|' || c == '<' || c == '>' || c == '(' || c == ')' if (c == '&' || c == '|' || c == '<' || c == '>' || c == '(' || c == ')'
|| c == ';' || c == '{' || c == '}' || c == '[' || c == ';' || c == '{' || c == '}' || c == '[' || c == ']')
|| c == ']')
return (1); return (1);
return (0); return (0);
} }
int unic(int *meta) int unic(int *meta)
{ {
int i; int i;
int ref_meta; int ref_meta;
i = -1; i = -1;
ref_meta = meta[0]; ref_meta = meta[0];
@@ -38,7 +37,7 @@ int is_sticked(char *val)
{ {
int i; int i;
int meta[100]; int meta[100];
int meta_it; int meta_it;
int unmeta; int unmeta;
i = 0; i = 0;
@@ -85,8 +84,7 @@ int trim_nodes(t_node *head)
in_quote = 0; in_quote = 0;
while (it != NULL) while (it != NULL)
{ {
if (ft_str_count(it->val, 39) == 1 if (ft_str_count(it->val, 39) == 1 || ft_str_count(it->val, '"') == 1)
|| ft_str_count(it->val, '"') == 1)
{ {
if (!in_quote) if (!in_quote)
in_quote = it->val[0]; in_quote = it->val[0];
@@ -103,17 +101,3 @@ int trim_nodes(t_node *head)
} }
return (1); return (1);
} }
int find_quote_node(t_node *head, char q)
{
t_node *it;
it = head;
while (it != NULL)
{
if (it->val[0] == q)
return (1);
it = it->next;
}
return (0);
}

View File

@@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tokenizer_utils2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/11 16:10:17 by nalebrun #+# #+# */
/* Updated: 2025/02/11 16:33:26 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../../includes/minishell.h"
void debug_token_list(t_node *lst, char *msg)
{
t_node *cpy;
cpy = lst;
if (DEBUG)
{
ft_debug("====================================================\
==============={%s}\n",
msg);
while (cpy)
{
ft_fprintf(2, "| %10s | TOKEN : %3d | PRESSISION : %3d |\n",
cpy->val, cpy->token, cpy->pressision);
cpy = cpy->next;
}
ft_debug("====================================================\
===============\n\n");
}
}
void set_token(t_node *head)
{
t_node *it;
t_token last_token;
t_pres last_pres;
it = head;
last_token = UNSET;
last_pres = UNDEFINED;
while (it != NULL)
{
it->token = get_token(it->val);
it->pressision = get_pressision(it->val, it->token, last_token,
last_pres);
last_token = it->token;
last_pres = it->pressision;
it = it->next;
}
}
int find_quote_node(t_node *head, char q)
{
t_node *it;
it = head;
while (it != NULL)
{
if (it->val[0] == q)
return (1);
it = it->next;
}
return (0);
}

View File

@@ -3,16 +3,16 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* powerline.c :+: :+: :+: */ /* powerline.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: lderidde <lderidde@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/10 12:19:10 by lderidde #+# #+# */ /* Created: 2025/02/10 12:19:10 by lderidde #+# #+# */
/* Updated: 2025/02/11 14:19:32 by lderidde ### ########.fr */ /* Updated: 2025/02/11 16:34:51 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../includes/minishell.h" #include "../includes/minishell.h"
static void handle_input(char *in, t_msh *msh) static void handle_input(char *in, t_msh *msh)
{ {
if (ft_strlen(in) > 0 && !is_only_space(in)) if (ft_strlen(in) > 0 && !is_only_space(in))
{ {
@@ -21,12 +21,12 @@ static void handle_input(char *in, t_msh *msh)
} }
} }
char *get_pwd() char *get_pwd(void)
{ {
char *pwd; char *pwd;
char *pwd_base; char *pwd_base;
char *cpy; char *cpy;
char *out; char *out;
pwd = getcwd(NULL, 0); pwd = getcwd(NULL, 0);
if (!pwd) if (!pwd)
@@ -55,8 +55,8 @@ char *powerline(t_msh *msh)
char *prompt; char *prompt;
pwd = get_pwd(); pwd = get_pwd();
prompt = ft_sprintf("\n%s  MMOAT %s%s %s%s %s%s%s ", prompt = ft_sprintf("\n%s  MMOAT %s%s %s%s %s%s%s ", POW1, POW2, POW3,
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(prompt); free(prompt);

View File

@@ -3,30 +3,30 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* sig.c :+: :+: :+: */ /* sig.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */ /* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/10 08:32:20 by nalebrun #+# #+# */ /* Created: 2025/02/10 08:32:20 by nalebrun #+# #+# */
/* Updated: 2025/02/10 08:32:20 by nalebrun ### ########.fr */ /* Updated: 2025/02/11 16:34:59 by nalebrun ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "../includes/minishell.h" #include "../includes/minishell.h"
#include <readline/chardefs.h> #include <readline/chardefs.h>
void init_sig() void init_sig(void)
{ {
int i; int i;
struct sigaction sa[2]; struct sigaction sa[2];
i = -1; i = -1;
while (++i < 2) while (++i < 2)
{ {
ft_memset(&(sa[i]), 0, sizeof(sa[i])); ft_memset(&(sa[i]), 0, sizeof(sa[i]));
(sa[i]).sa_flags = SA_RESTART; (sa[i]).sa_flags = SA_RESTART;
sigemptyset(&((sa[i]).sa_mask)); sigemptyset(&((sa[i]).sa_mask));
} }
(sa[0]).sa_handler = handle_sigint; (sa[0]).sa_handler = handle_sigint;
sigaction(SIGINT, &(sa[0]), NULL); sigaction(SIGINT, &(sa[0]), NULL);
(sa[1]).sa_handler = handle_sigquit; (sa[1]).sa_handler = handle_sigquit;
sigaction(SIGQUIT, &(sa[1]), NULL); sigaction(SIGQUIT, &(sa[1]), NULL);
} }