Browse Source

fix : new_type change on empty token, wrong type applied on tokens

master
narnaud 3 years ago
parent
commit
b12579b7a8
  1. 2
      Makefile
  2. 13
      lexer.c
  3. 6
      minishell.c
  4. 5
      minishell.h

2
Makefile

@ -23,7 +23,7 @@ clean:
fclean: clean fclean: clean
${MAKE} -C ./libft fclean ${MAKE} -C ./libft fclean
rm libft.a rm -rf libft.a
rm -rf ${NAME} rm -rf ${NAME}
re: fclean all re: fclean all

13
lexer.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:44:57 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; t_type type;
type = lex->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; lex->next_type = WORD;
if (!str[0]) if (!str[0])
return (0); return (0);
@ -34,6 +37,8 @@ int create_token(t_lexer *lex, char str[])
} }
tok->type = type; tok->type = type;
tok->value = strdup(str); tok->value = strdup(str);
if (DEBUG)
printf("token value : %s - token type : %d\n", tok->value, type);
if (!lex->tokens) if (!lex->tokens)
lex->tokens = tok; lex->tokens = tok;
return (1); return (1);
@ -47,7 +52,7 @@ int check_register(t_lexer *lex, char **line, char *tmp)
if (lex->state != ROOT_ST) if (lex->state != ROOT_ST)
return (0); return (0);
spaces = 0; spaces = 0;
if (ft_isspace(**line)) if (ft_isspace(**line) )
{ {
while (ft_isspace(**line)) while (ft_isspace(**line))
(*line)++; (*line)++;
@ -76,7 +81,7 @@ int check_register(t_lexer *lex, char **line, char *tmp)
create_token(lex, tmp); create_token(lex, tmp);
return (create_token(lex, "|")); return (create_token(lex, "|"));
} }
if (!spaces) if (!spaces || !*tmp)
return (0); return (0);
return (create_token(lex, tmp)); return (create_token(lex, tmp));
} }

6
minishell.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 12:14:09 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); update_redir(cmd, tok);
else else
cmd->argv[i++] = tok->value; cmd->argv[i++] = tok->value;
if (DEBUG)
printf("token : %s, type: %d\n", tok->value, tok->type);
tok = tok->next; tok = tok->next;
} }
cmd->argv[i] = NULL; cmd->argv[i] = NULL;
@ -52,8 +50,6 @@ t_token *lexer(char *line)
tmp_i = 0; tmp_i = 0;
while (*line) while (*line)
{ {
if (DEBUG)
printf("%c\n", *line);
if (check_state(lex, &line)) if (check_state(lex, &line))
continue; continue;
if (lex->state != S_QUOTE_ST && *line == '$') if (lex->state != S_QUOTE_ST && *line == '$')

5
minishell.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ /* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/05/02 13:50:44 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 replace_var(char **line, char *tmp, int tmp_i);
int check_state(t_lexer *lex, char **line); int check_state(t_lexer *lex, char **line);
#endif #endif

Loading…
Cancel
Save