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. 11
      lexer.c
  3. 6
      minishell.c
  4. 5
      minishell.h

2
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

11
lexer.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
@ -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));
}

6
minishell.c

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 == '$')

5
minishell.h

@ -6,7 +6,7 @@
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

Loading…
Cancel
Save