parsing et execution partielle de hugo
This commit is contained in:
@@ -6,13 +6,60 @@
|
||||
/* By: lperrey <lperrey@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/10/04 05:59:26 by lperrey #+# #+# */
|
||||
/* Updated: 2021/10/30 15:32:49 by hulamy ### ########.fr */
|
||||
/* Updated: 2021/11/02 13:37:12 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
static char **tokens_list_to_argv(t_token *t); // temp test
|
||||
void close_fd(t_cmd *cmd);
|
||||
void execute_cmd(char **envp, t_cmd **cmd_arr);
|
||||
|
||||
void shell_loop(t_all *c)
|
||||
{
|
||||
char *line_input;
|
||||
|
||||
line_input = NULL;
|
||||
while (1)
|
||||
{
|
||||
if (line_input)
|
||||
free(line_input);
|
||||
line_input = readline(c->prompt);
|
||||
if (line_input && *line_input)
|
||||
{
|
||||
add_history(line_input);
|
||||
c->token_list = input_to_tokens(line_input);
|
||||
c->cmd_arr = parsing(c->token_list, c->envp);
|
||||
execute_cmd(c->envp, c->cmd_arr);
|
||||
ft_lstclear((t_list **)&c->token_list, free);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void wip_test()
|
||||
{
|
||||
char term_desc[2048];
|
||||
char *term_type;
|
||||
int term_width;
|
||||
int term_height;
|
||||
int ret;
|
||||
|
||||
term_type = getenv("TERM");
|
||||
if (term_type == 0)
|
||||
ft_putstr_fd("Specify a terminal type with `setenv TERM <yourtype>'.\n", 2);
|
||||
ret = tgetent(term_desc, term_type);
|
||||
if (ret < 0)
|
||||
ft_putstr_fd("Could not access the termcap data base.\n", 2);
|
||||
if (ret == 0)
|
||||
ft_putstr_fd("Terminal type `%s' is not defined.\n", 2);
|
||||
term_height = tgetnum ("li");
|
||||
term_width = tgetnum ("co");
|
||||
/* Extract information that termcap functions use. */
|
||||
/* temp = tgetstr ("pc", BUFFADDR);
|
||||
PC = temp ? *temp : 0;
|
||||
BC = tgetstr ("le", BUFFADDR);
|
||||
UP = tgetstr ("up", BUFFADDR); */
|
||||
}
|
||||
|
||||
void close_fd(t_cmd *cmd)
|
||||
{
|
||||
@@ -49,89 +96,3 @@ void execute_cmd(char **envp, t_cmd **cmd_arr)
|
||||
// waitpid pour la derniere commande (pour '$?')
|
||||
while ((wpid = wait(&status)) > 0);
|
||||
}
|
||||
|
||||
void shell_loop(t_all *c)
|
||||
{
|
||||
char *line_input;
|
||||
|
||||
line_input = NULL;
|
||||
while (1)
|
||||
{
|
||||
if (line_input)
|
||||
free(line_input);
|
||||
line_input = readline(c->prompt);
|
||||
if (line_input && *line_input)
|
||||
{
|
||||
add_history(line_input);
|
||||
c->token_list = input_to_tokens(line_input);
|
||||
|
||||
// EXEC_PIPES_AND_CO()
|
||||
|
||||
// temp placeholder
|
||||
(void)tokens_list_to_argv;
|
||||
// if (ft_strncmp(c->token_list->content, "env", 4) == 0)
|
||||
// builtin_env(0, NULL, c);
|
||||
// else if (ft_strncmp(c->token_list->content, "exit", 5) == 0)
|
||||
// builtin_exit(0, NULL, c);
|
||||
// else if (ft_strncmp(c->token_list->content, "echo", 5) == 0)
|
||||
// builtin_echo(ft_lstsize((t_list *)c->token_list) + 1, tokens_list_to_argv(c->token_list), c);
|
||||
// else
|
||||
// {
|
||||
|
||||
c->cmd_arr = parsing(c->token_list, c->envp);
|
||||
|
||||
if (c->cmd_arr == NULL)
|
||||
ft_putstr_fd("Syntax KO:\n-----------\n", 1);
|
||||
// else
|
||||
// ft_putstr_fd("Syntax OK:\n-----------\n", 1);
|
||||
// ft_putstr_fd("TOKENS LIST :\n-----------\n", 1);
|
||||
// ft_lstprint((t_list *)c->token_list, 1);
|
||||
|
||||
execute_cmd(c->envp, c->cmd_arr);
|
||||
ft_lstclear((t_list **)&c->token_list, free);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static char **tokens_list_to_argv(t_token *t) // temp test
|
||||
{
|
||||
size_t i;
|
||||
char **argv;
|
||||
|
||||
i = ft_lstsize((t_list *)t);
|
||||
argv = ft_calloc(i + 1, sizeof(char*));
|
||||
i = 0;
|
||||
while (t)
|
||||
{
|
||||
argv[i] = t->content;
|
||||
i++;
|
||||
t = t->next;
|
||||
}
|
||||
return (argv);
|
||||
}
|
||||
|
||||
void wip_test()
|
||||
{
|
||||
char term_desc[2048];
|
||||
char *term_type;
|
||||
int term_width;
|
||||
int term_height;
|
||||
int ret;
|
||||
|
||||
term_type = getenv("TERM");
|
||||
if (term_type == 0)
|
||||
ft_putstr_fd("Specify a terminal type with `setenv TERM <yourtype>'.\n", 2);
|
||||
ret = tgetent(term_desc, term_type);
|
||||
if (ret < 0)
|
||||
ft_putstr_fd("Could not access the termcap data base.\n", 2);
|
||||
if (ret == 0)
|
||||
ft_putstr_fd("Terminal type `%s' is not defined.\n", 2);
|
||||
term_height = tgetnum ("li");
|
||||
term_width = tgetnum ("co");
|
||||
/* Extract information that termcap functions use. */
|
||||
/* temp = tgetstr ("pc", BUFFADDR);
|
||||
PC = temp ? *temp : 0;
|
||||
BC = tgetstr ("le", BUFFADDR);
|
||||
UP = tgetstr ("up", BUFFADDR); */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user