From b12579b7a8102517b33deb84908fbfd883577261 Mon Sep 17 00:00:00 2001 From: narnaud Date: Tue, 3 May 2022 11:45:22 +0200 Subject: [PATCH] fix : new_type change on empty token, wrong type applied on tokens --- Makefile | 2 +- lexer.c | 13 +++++++++---- minishell.c | 6 +----- minishell.h | 5 +---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index e46ce2d..53020d7 100755 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ clean: fclean: clean ${MAKE} -C ./libft fclean - rm libft.a + rm -rf libft.a rm -rf ${NAME} re: fclean all diff --git a/lexer.c b/lexer.c index 1edd571..1bc322e 100644 --- a/lexer.c +++ b/lexer.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:44:57 by narnaud #+# #+# */ -/* Updated: 2022/05/03 09:19:36 by narnaud ### ########.fr */ +/* Updated: 2022/05/03 11:42:26 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,10 @@ int create_token(t_lexer *lex, char str[]) t_type type; type = lex->type; - lex->type = (lex->next_type || WORD); + if (lex->next_type) + lex->type = lex->next_type; + else + lex->type = WORD; lex->next_type = WORD; if (!str[0]) return (0); @@ -34,6 +37,8 @@ int create_token(t_lexer *lex, char str[]) } tok->type = type; tok->value = strdup(str); + if (DEBUG) + printf("token value : %s - token type : %d\n", tok->value, type); if (!lex->tokens) lex->tokens = tok; return (1); @@ -47,7 +52,7 @@ int check_register(t_lexer *lex, char **line, char *tmp) if (lex->state != ROOT_ST) return (0); spaces = 0; - if (ft_isspace(**line)) + if (ft_isspace(**line) ) { while (ft_isspace(**line)) (*line)++; @@ -76,7 +81,7 @@ int check_register(t_lexer *lex, char **line, char *tmp) create_token(lex, tmp); return (create_token(lex, "|")); } - if (!spaces) + if (!spaces || !*tmp) return (0); return (create_token(lex, tmp)); } diff --git a/minishell.c b/minishell.c index ce91e2f..8cd35f2 100644 --- a/minishell.c +++ b/minishell.c @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 12:14:09 by narnaud #+# #+# */ -/* Updated: 2022/05/03 10:39:02 by narnaud ### ########.fr */ +/* Updated: 2022/05/03 11:06:49 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,8 +30,6 @@ t_command *parser(t_token *tok, t_command *prev) update_redir(cmd, tok); else cmd->argv[i++] = tok->value; - if (DEBUG) - printf("token : %s, type: %d\n", tok->value, tok->type); tok = tok->next; } cmd->argv[i] = NULL; @@ -52,8 +50,6 @@ t_token *lexer(char *line) tmp_i = 0; while (*line) { - if (DEBUG) - printf("%c\n", *line); if (check_state(lex, &line)) continue; if (lex->state != S_QUOTE_ST && *line == '$') diff --git a/minishell.h b/minishell.h index a5d5fd5..b70d334 100644 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/05/02 13:50:44 by narnaud #+# #+# */ -/* Updated: 2022/05/03 09:34:27 by narnaud ### ########.fr */ +/* Updated: 2022/05/03 11:39:52 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -105,7 +105,4 @@ int check_register(t_lexer *lex, char **line, char *tmp); int replace_var(char **line, char *tmp, int tmp_i); int check_state(t_lexer *lex, char **line); - - - #endif