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