77 lines
2.0 KiB
C
Raw Normal View History

2024-04-25 11:46:41 +02:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
2024-04-25 11:46:41 +02:00
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
2024-07-06 13:36:03 +02:00
/* Updated: 2024/07/04 20:17:22 by adjoly ### ########.fr */
2024-04-25 11:46:41 +02:00
/* */
/* ************************************************************************** */
#include <signal.h>
2024-05-13 17:33:29 +02:00
#include <stdio.h>
2024-04-25 11:46:41 +02:00
#include <readline/readline.h>
#include "error_msg.h"
2024-04-30 12:36:16 +02:00
#include <readline/history.h>
2024-04-27 17:39:26 +02:00
#include <stdlib.h>
2024-04-30 12:36:16 +02:00
#include <stdbool.h>
#include <fcntl.h>
2024-05-09 16:46:13 +02:00
#include "libft.h"
2024-06-25 10:38:07 +02:00
#include "builtins.h"
2024-04-30 12:36:16 +02:00
#include "minishell.h"
2024-05-09 16:46:13 +02:00
#include "parsing.h"
#include "prompt.h"
2024-04-25 11:46:41 +02:00
void sig_c(int code)
{
(void)code;
ft_putchar_fd('\n', STDOUT_FILENO);
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
}
2024-04-25 11:46:41 +02:00
int main(int ac, char **av, char **env)
{
char *rl;
2024-05-02 15:50:58 +02:00
char *prompt;
t_env env_l;
t_list *cmd_list;
t_list *piped;
2024-04-25 11:46:41 +02:00
(void)ac;
get_program_name(av[0]);
if (env_init(env, &env_l))
return (EXIT_FAILURE);
signal(SIGINT, &sig_c);
2024-04-25 11:46:41 +02:00
while (1)
{
prompt = get_prompt(env_l);
rl = readline(prompt);
2024-05-02 15:54:16 +02:00
free(prompt);
if (!rl)
exit(727);
if (!*rl)
continue ;
if (check_syntax(rl))
continue ;
if (check_quote(rl))
continue ;
if (check_pipe(rl))
continue ;
piped = tokenizer(rl);
if (check_argv(piped))
continue ;
add_history(rl);
cmd_list = get_cmd_list(piped);
ft_lstclear(&piped, &free_token);
format_quotes(cmd_list);
exec_split_cmd(cmd_list, &env_l);
ft_lstclear(&cmd_list, &free_cmd);
free(rl);
2024-04-25 11:46:41 +02:00
}
return (0);
}