116 lines
2.6 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/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"
#include "prompt.h"
2024-04-25 11:46:41 +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);
}
/*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;
while (tmp)
2024-05-09 16:46:13 +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;
char **lll;
t_list *piped;
t_env env_l;
t_list *cmd_list;
2024-04-25 11:46:41 +02:00
(void)ac;
(void)av;
piped = NULL;
if (env_init(env, &env_l))
return (EXIT_FAILURE);
2024-04-25 11:46:41 +02:00
while (1)
{
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);
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)
continue ;
2024-04-27 17:39:26 +02:00
if (is_str(test, "exit"))
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);
exec_split_cmd(cmd_list, &env_l);
/*while (cmd_list)
{
cmd = cmd_list->content;
cmd_list = cmd_list->next;
2024-06-18 12:21:40 +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);
}
/*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))
print_quote_type(d);
}*/