78 lines
1.8 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 #+# #+# */
/* Updated: 2024/05/22 14:53:00 by mmoussou ### ########.fr */
2024-04-25 11:46:41 +02:00
/* */
/* ************************************************************************** */
2024-05-13 17:33:29 +02:00
#include <stdio.h>
2024-04-25 11:46:41 +02:00
#include <readline/readline.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-04-30 12:36:16 +02:00
#include "minishell.h"
2024-05-09 16:46:13 +02:00
#include "parsing.h"
2024-04-25 11:46:41 +02:00
2024-05-07 11:04:20 +02:00
void print_cmd(t_cmd cmd)
2024-04-25 11:46:41 +02:00
{
2024-05-07 11:04:20 +02:00
ft_putendl_fd(cmd.cmd, 1);
while (*(cmd.argv))
2024-04-27 17:39:26 +02:00
{
2024-05-07 11:04:20 +02:00
ft_putendl_fd(*(cmd.argv), 1);
(cmd.argv)++;
2024-04-27 17:39:26 +02:00
}
2024-04-25 11:46:41 +02:00
}
2024-05-09 16:46:13 +02:00
void print_pipe(t_list *pipe)
{
t_list *tmp;
tmp = pipe;
if (!pipe->next)
{
print_cmd(*(t_cmd*)tmp->content);
return;
}
while (tmp)
{
print_cmd(*(t_cmd*)tmp->content);
tmp = tmp->next;
}
}
int main(void)//(int ac, char **av, char **env)
2024-04-25 11:46:41 +02:00
{
char *test;
2024-04-25 11:46:41 +02:00
char **lll;
2024-05-02 15:50:58 +02:00
char *prompt;
2024-05-09 16:46:13 +02:00
t_list *cmd;
2024-04-25 11:46:41 +02:00
(void)ac;
(void)av;
(void)env;
while (1)
{
2024-05-02 15:50:58 +02:00
prompt = get_prompt();
test = readline(prompt);
2024-05-02 15:54:16 +02:00
free(prompt);
2024-04-30 12:36:16 +02:00
add_history(test);
2024-04-25 11:46:41 +02:00
lll = ft_split(test, ' ');
2024-04-27 17:39:26 +02:00
if (!*lll)
continue ;
2024-04-27 17:39:26 +02:00
if (is_str(test, "exit"))
break ;
2024-05-09 16:46:13 +02:00
cmd = split_pipe(test);
2024-05-10 11:10:17 +02:00
print_pipe(cmd);
2024-05-07 11:04:20 +02:00
ft_free("a", &lll);
2024-04-25 11:46:41 +02:00
}
2024-05-07 11:04:20 +02:00
ft_free("a", &lll);
return (0);
2024-04-25 11:46:41 +02:00
}