diff --git a/inc/tokenizer.h b/inc/tokenizer.h index cfd415e..42ed9e1 100644 --- a/inc/tokenizer.h +++ b/inc/tokenizer.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* tokenizer.h :+: :+: */ -/* +:+ */ -/* By: qmennen +#+ */ -/* +#+ */ -/* Created: 2025/02/05 12:36:00 by whaffman #+# #+# */ -/* Updated: 2025/02/26 15:45:26 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* tokenizer.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/05 12:36:00 by whaffman #+# #+# */ +/* Updated: 2025/02/27 18:27:33 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,10 +24,12 @@ t_list *ft_parse_input(t_minishell *msh); /** * Token */ -t_token *ft_token_next(t_minishell *msh, t_lexer *lexer); -t_token *token_new(t_minishell *msh, t_token_type type, char *c, int pos); -void ft_token_free(t_minishell *msh, t_token *token); -void ft_clear_tokenlist(t_minishell *msh, void *content); -t_token *token_parse(t_minishell *msh, t_lexer *lexer); +t_token *ft_token_next(t_minishell *msh, t_lexer *lexer); +t_token *token_new(t_minishell *msh, t_token_type type, char *c, int pos); +void ft_token_free(t_minishell *msh, t_token *token); +void ft_clear_tokenlist(t_minishell *msh, void *content); +t_token *token_parse(t_minishell *msh, t_lexer *lexer); +char *token_type_convert(t_token_type type); +t_token_type token_char_convert(char c, int is_double); #endif // TOKENIZER_H diff --git a/src/token/token_char_convert.c b/src/token/token_char_convert.c new file mode 100644 index 0000000..fbfd1f5 --- /dev/null +++ b/src/token/token_char_convert.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token_char_convert.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/27 18:25:34 by qmennen #+# #+# */ +/* Updated: 2025/02/27 18:28:13 by qmennen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +# include "minishell.h" + +t_token_type token_char_convert(char c, int is_double) +{ + if (c == '<') + { + if (is_double) + return (T_HEREDOC); + return (T_REDIRECT_IN); + } + else if (c == '>') + { + if (is_double) + return (T_APPEND_OUT); + return (T_REDIRECT_OUT); + } + else if (c == '&' && is_double) + return (T_AND); + else if (c == '|') + { + if (is_double) + return (T_OR); + return (T_PIPE); + } + return (T_ERROR); +} diff --git a/src/token/token_parse.c b/src/token/token_parse.c index f18eb52..5974479 100644 --- a/src/token/token_parse.c +++ b/src/token/token_parse.c @@ -1,61 +1,17 @@ /* ************************************************************************** */ /* */ -/* :::::::: */ -/* token_parse.c :+: :+: */ -/* +:+ */ -/* By: qmennen +#+ */ -/* +#+ */ -/* Created: 2025/02/05 19:10:17 by qmennen #+# #+# */ -/* Updated: 2025/02/26 16:15:19 by whaffman ######## odam.nl */ +/* ::: :::::::: */ +/* token_parse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/05 19:10:17 by qmennen #+# #+# */ +/* Updated: 2025/02/27 18:27:40 by qmennen ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static t_token_type token_from_char(char c, int is_double) -{ - if (c == '<') - { - if (is_double) - return (T_HEREDOC); - return (T_REDIRECT_IN); - } - else if (c == '>') - { - if (is_double) - return (T_APPEND_OUT); - return (T_REDIRECT_OUT); - } - else if (c == '&' && is_double) - return (T_AND); - else if (c == '|') - { - if (is_double) - return (T_OR); - return (T_PIPE); - } - return (T_ERROR); -} - -static char *char_from_type(t_token_type type) -{ - if (type == T_HEREDOC) - return ("<<"); - else if (type == T_REDIRECT_IN) - return ("<"); - else if (type == T_APPEND_OUT) - return (">>"); - else if (type == T_REDIRECT_OUT) - return (">"); - else if (type == T_AND) - return ("&&"); - else if (type == T_OR) - return ("||"); - else if (type == T_PIPE) - return ("|"); - return (NULL); -} - t_token *token_parse(t_minishell *msh, t_lexer *lexer) { int is_double; @@ -65,8 +21,8 @@ t_token *token_parse(t_minishell *msh, t_lexer *lexer) c = lexer->current_char; is_double = lexer->input[lexer->pos + 1] == c; - type = token_from_char(c, is_double); - token = token_new(msh, type, char_from_type(type), lexer->pos); + type = token_char_convert(c, is_double); + token = token_new(msh, type, token_type_convert(type), lexer->pos); if (is_double) lexer_readchar(lexer); lexer_readchar(lexer); diff --git a/src/token/token_type_convert.c b/src/token/token_type_convert.c new file mode 100644 index 0000000..c42e681 --- /dev/null +++ b/src/token/token_type_convert.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* token_type_convert.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: qmennen +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/27 18:25:34 by qmennen #+# #+# */ +/* Updated: 2025/02/27 18:26:40 by qmennen ### ########.fr */ +/* */ +/* ************************************************************************** */ + +# include "minishell.h" + +char *token_type_convert(t_token_type type) +{ + if (type == T_HEREDOC) + return ("<<"); + else if (type == T_REDIRECT_IN) + return ("<"); + else if (type == T_APPEND_OUT) + return (">>"); + else if (type == T_REDIRECT_OUT) + return (">"); + else if (type == T_AND) + return ("&&"); + else if (type == T_OR) + return ("||"); + else if (type == T_PIPE) + return ("|"); + return (NULL); +}