diff --git a/Makefile b/Makefile index 5cb3f8e..4ab42d3 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ SOURCES = src/execute/execute_utils.c src/builtin/cd.c src/builtin/exit.c src/bu src/parser/parser.c src/parser/parser_state.c src/parser/parser_utils.c src/execute/heredoc.c \ src/expander/expander.c src/splitter.c src/lexer/syntax_analyzer.c src/signal.c $(MEMORY_ALLOCATOR_SOURCES) \ src/redirections/redirections.c src/env/global_env.c src/utils/unsafe_utils.c src/utils/char_classification.c src/utils/string_utils.c \ - src/utils/quote_classification.c + src/utils/quote_classification.c src/expander/expander_2.c MINISHELL_SOURCES = src/main.c $(SOURCES) MINISHELL_OBJECTS = $(MINISHELL_SOURCES:.c=.o) diff --git a/includes/minishell.h b/includes/minishell.h index e6d5a8e..aaa2c40 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* minishell.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hamza +#+ +:+ +#+ */ +/* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/31 09:14:38 by hamza #+# #+# */ -/* Updated: 2024/04/01 07:31:02 by hamza ### ########.fr */ +/* Updated: 2024/04/01 17:49:31 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -185,4 +185,7 @@ char *ft_unsafe_strdup(const char *str); void export_env(char *format); void handle_file_redirections(t_command *cur); +void expand_token(t_token *token, t_token **head, + t_token **token_ptr, t_token **prev_ptr); + #endif diff --git a/includes/utils.h b/includes/utils.h index b2f01b5..9159bb2 100644 --- a/includes/utils.h +++ b/includes/utils.h @@ -3,17 +3,17 @@ /* ::: :::::::: */ /* utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hamza +#+ +:+ +#+ */ +/* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/31 09:28:02 by hamza #+# #+# */ -/* Updated: 2024/04/01 08:58:09 by hamza ### ########.fr */ +/* Updated: 2024/04/01 17:49:02 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef UTILS_H # define UTILS_H -typedef struct s_token t_token; +typedef struct s_token t_token; char *get_cur_folder_name(void); char *ft_str_arr_join(char **str_list, unsigned int str_count); @@ -28,5 +28,6 @@ char **ft_unsafe_strarrdup(char **arr); int is_full_of_spaces(const char *str); t_token *skip_delimiters(t_token *token); void print_error(char *cmd, char *error); +void remove_token(t_token **prev_ptr, t_token **head, t_token *token); #endif diff --git a/memory-allocator/allocator.c b/memory-allocator/allocator.c index f4593ae..9bdbdc9 100644 --- a/memory-allocator/allocator.c +++ b/memory-allocator/allocator.c @@ -6,7 +6,7 @@ /* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/16 15:13:21 by hamza #+# #+# */ -/* Updated: 2024/03/30 17:46:06 by facetint ### ########.fr */ +/* Updated: 2024/04/01 17:49:52 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -65,7 +65,7 @@ int append_memory_block(void *ptr) */ int remove_memory_block(void *ptr) { - t_memory_block *cur; + t_memory_block *cur; t_memory_block *prev; if (!ptr) diff --git a/src/expander/expander.c b/src/expander/expander.c index 5ee37b1..f6a424a 100644 --- a/src/expander/expander.c +++ b/src/expander/expander.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* expander.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hamza +#+ +:+ +#+ */ +/* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:17:39 by facetint #+# #+# */ -/* Updated: 2024/04/01 08:00:15 by hamza ### ########.fr */ +/* Updated: 2024/04/01 17:46:58 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -85,23 +85,7 @@ void expand(t_token **head) while (token) { if (token->type == UNQUOTED_WORD || token->type == DOUBLE_QUOTED_WORD) - { - if (is_nameless_variable(token)) - token->value = ft_strdup(""); - else - { - expand_string(&token->value); - if (is_full_of_spaces(token->value)) - { - if (prev_ptr == NULL) - *head = token->next; - else - (*prev_ptr)->next = token->next; - } - else if (token->type == UNQUOTED_WORD) - internal_field_split(token_ptr); - } - } + expand_token(token, head, token_ptr, prev_ptr); prev_ptr = token_ptr; token_ptr = &token->next; token = token->next; diff --git a/src/expander/expander_2.c b/src/expander/expander_2.c new file mode 100644 index 0000000..b0354ea --- /dev/null +++ b/src/expander/expander_2.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* expander_2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: facetint +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/01 17:50:47 by facetint #+# #+# */ +/* Updated: 2024/04/01 17:50:59 by facetint ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/minishell.h" +#include "../../includes/utils.h" +#include "../../libft/libft.h" + +void expand_token(t_token *token, t_token **head, + t_token **token_ptr, t_token **prev_ptr) +{ + if (is_nameless_variable(token)) + token->value = ft_strdup(""); + else + { + expand_string(&token->value); + if (is_full_of_spaces(token->value)) + remove_token(prev_ptr, head, token); + else if (token->type == UNQUOTED_WORD) + internal_field_split(token_ptr); + } +} diff --git a/src/lexer/syntax_analyzer.c b/src/lexer/syntax_analyzer.c index da7db7f..69e2310 100644 --- a/src/lexer/syntax_analyzer.c +++ b/src/lexer/syntax_analyzer.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* syntax_analyzer.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: hamza +#+ +:+ +#+ */ +/* By: facetint +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/03 13:18:35 by facetint #+# #+# */ -/* Updated: 2024/04/01 08:35:41 by hamza ### ########.fr */ +/* Updated: 2024/04/01 17:50:37 by facetint ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,3 +84,11 @@ int validate_pipes(t_token *token) } return (1); } + +void remove_token(t_token **prev_ptr, t_token **head, t_token *token) +{ + if (prev_ptr == NULL) + *head = token->next; + else + (*prev_ptr)->next = token->next; +}