refactor: god struct lexer and error message
This commit is contained in:
parent
1722fff4c7
commit
b909668a1a
15
src/main.c
15
src/main.c
@ -12,6 +12,7 @@
|
||||
|
||||
#include "minishell.h"
|
||||
#include "prompt.h"
|
||||
#include <stdio.h>
|
||||
|
||||
void print_banner(void)
|
||||
{
|
||||
@ -26,6 +27,11 @@ void print_list(void *content)
|
||||
{
|
||||
t_token *token;
|
||||
token = (t_token *)content;
|
||||
if (token->type == T_ERROR)
|
||||
{
|
||||
printf("An error occurred near position %i\n", token->position);
|
||||
}
|
||||
else
|
||||
ft_printf("%s\n", token->value);
|
||||
}
|
||||
|
||||
@ -33,7 +39,6 @@ int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
t_enviroment *enviroment;
|
||||
char *line;
|
||||
t_lexer *lexer;
|
||||
t_list *list;
|
||||
t_minishell *minishell;
|
||||
|
||||
@ -53,8 +58,8 @@ int main(int argc, char **argv, char **envp)
|
||||
line = ft_prompt(minishell);
|
||||
if (line != NULL)
|
||||
add_history(line);
|
||||
lexer = ft_lexer_new(line);
|
||||
list = ft_parse_input(lexer);
|
||||
minishell->lexer = ft_lexer_new(line);
|
||||
list = ft_parse_input(minishell->lexer);
|
||||
ft_lstiter(list, print_list);
|
||||
free(line);
|
||||
if (list != NULL && ft_strncmp(((t_token *)list->content)->value, "clear\0", 6) == 0)
|
||||
@ -64,10 +69,10 @@ int main(int argc, char **argv, char **envp)
|
||||
else if (list != NULL && ft_strncmp(((t_token *)list->content)->value, "exit\0", 5) == 0)
|
||||
break;
|
||||
ft_lstclear(&list, ft_clear_tokenlist);
|
||||
ft_lexer_free(lexer);
|
||||
ft_lexer_free(minishell->lexer);
|
||||
}
|
||||
ft_lstclear(&list, ft_clear_tokenlist);
|
||||
ft_lexer_free(lexer);
|
||||
ft_lexer_free(minishell->lexer);
|
||||
// print_enviroment(enviroment);
|
||||
free_enviroment(enviroment);
|
||||
free(minishell);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user