2024-04-25 11:46:41 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* main.c :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
2024-05-22 14:51:52 +02:00
|
|
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
2024-04-25 11:46:41 +02:00
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
2024-06-21 09:59:31 +02:00
|
|
|
/* Updated: 2024/06/21 09:33:03 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-05-23 20:53:07 +02:00
|
|
|
#include "prompt.h"
|
2024-04-25 11:46:41 +02:00
|
|
|
|
2024-05-30 17:59:49 +02:00
|
|
|
void free_redir(void *redir_v)
|
|
|
|
{
|
|
|
|
t_redirection *redir;
|
|
|
|
|
|
|
|
redir = redir_v;
|
|
|
|
free(redir->file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_token(void *token_v)
|
|
|
|
{
|
|
|
|
t_token *token;
|
|
|
|
|
|
|
|
token = token_v;
|
|
|
|
free(token->argv);
|
|
|
|
ft_lstclear(&(token->redirection), free_redir);
|
|
|
|
}
|
|
|
|
|
2024-05-23 20:53:07 +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-05-23 20:53:07 +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;
|
2024-05-23 20:53:07 +02:00
|
|
|
while (tmp)
|
2024-05-09 16:46:13 +02:00
|
|
|
{
|
2024-05-23 20:53:07 +02:00
|
|
|
ft_putendl_fd(tmp->content, STDOUT_FILENO);
|
2024-05-09 16:46:13 +02:00
|
|
|
tmp = tmp->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-25 11:46:41 +02:00
|
|
|
int main(int ac, char **av, char **env)
|
|
|
|
{
|
|
|
|
char *test;
|
2024-05-02 15:50:58 +02:00
|
|
|
char *prompt;
|
2024-05-23 20:53:07 +02:00
|
|
|
char **lll;
|
|
|
|
t_list *piped;
|
2024-05-28 14:21:41 +02:00
|
|
|
t_env env_l;
|
2024-05-31 19:26:09 +02:00
|
|
|
t_list *cmd_list;
|
2024-04-25 11:46:41 +02:00
|
|
|
|
|
|
|
(void)ac;
|
|
|
|
(void)av;
|
2024-05-30 17:59:49 +02:00
|
|
|
piped = NULL;
|
|
|
|
if (env_init(env, &env_l))
|
|
|
|
return (EXIT_FAILURE);
|
2024-04-25 11:46:41 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2024-05-28 14:21:41 +02:00
|
|
|
prompt = get_prompt(env_l);
|
2024-05-02 15:50:58 +02:00
|
|
|
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-05-30 17:59:49 +02:00
|
|
|
check_syntax(test, av);
|
2024-04-25 11:46:41 +02:00
|
|
|
lll = ft_split(test, ' ');
|
2024-04-27 17:39:26 +02:00
|
|
|
if (!*lll)
|
2024-05-22 14:53:27 +02:00
|
|
|
continue ;
|
2024-04-27 17:39:26 +02:00
|
|
|
if (is_str(test, "exit"))
|
2024-05-30 17:59:49 +02:00
|
|
|
break ;
|
|
|
|
piped = tokenizer(test);
|
2024-06-20 14:28:54 +02:00
|
|
|
//check_redir(((t_token *)(piped->content))->redirection, av);
|
|
|
|
cmd_list = get_cmd_list(piped, &env_l);
|
2024-06-21 09:59:31 +02:00
|
|
|
exec_split_cmd(cmd_list, &env_l);
|
2024-06-04 22:28:13 +02:00
|
|
|
/*while (cmd_list)
|
2024-05-30 17:59:49 +02:00
|
|
|
{
|
2024-05-31 19:26:09 +02:00
|
|
|
cmd = cmd_list->content;
|
|
|
|
cmd_list = cmd_list->next;
|
2024-06-18 12:21:40 +02:00
|
|
|
}*/
|
2024-06-21 09:59:31 +02:00
|
|
|
//print_cmd(cmd_list->content);
|
|
|
|
free(test);
|
|
|
|
ft_lstclear(&piped, free_token);
|
|
|
|
ft_free("a", &lll);
|
2024-04-25 11:46:41 +02:00
|
|
|
}
|
2024-05-07 11:04:20 +02:00
|
|
|
ft_free("a", &lll);
|
2024-04-25 11:46:41 +02:00
|
|
|
return (0);
|
|
|
|
}
|
2024-05-23 20:53:07 +02:00
|
|
|
|
|
|
|
/*int main()
|
|
|
|
{
|
|
|
|
char *ll = "asdf\"xf\"asfffd";
|
|
|
|
t_quote d;
|
|
|
|
|
|
|
|
d = is_inquote(ll, 6);
|
2024-06-18 12:21:40 +02:00
|
|
|
ft_printf("%c\n", *(ll+6))
|
2024-05-23 20:53:07 +02:00
|
|
|
print_quote_type(d);
|
|
|
|
}*/
|