diff --git a/include/defines.h b/include/defines.h index 7b302acb..acb3c921 100644 --- a/include/defines.h +++ b/include/defines.h @@ -212,9 +212,10 @@ typedef enum e_is_open_pair_op typedef enum e_expander_op { - E_EXPAND = 0b001, - E_SPLIT_WORDS = 0b010, - E_RM_QUOTES = 0b100 + E_EXPAND = 0b0001, + E_SPLIT_WORDS = 0b0010, + E_WILDCARD = 0b0100, + E_RM_QUOTES = 0b1000 } t_expander_op; typedef enum e_expander_task_type diff --git a/include/expander.h b/include/expander.h index 53953ec3..c7f038ef 100644 --- a/include/expander.h +++ b/include/expander.h @@ -61,7 +61,8 @@ bool handle_quote_removal(t_list **task_list); bool remove_quote(t_list *task_list); /* wildcard_expansion.c */ -bool handle_wildcard_expansion(t_list **lst, t_list **task_list); +bool handle_wildcard_expansion(t_list **lst, t_list **task_list, + t_expander_op op_mask); /* wildcard_expansion_utils.c */ bool is_wildcard(char *word, t_list *task_list); diff --git a/source/backend/executor/executor_utils.c b/source/backend/executor/executor_utils.c index 42479711..2291887d 100644 --- a/source/backend/executor/executor_utils.c +++ b/source/backend/executor/executor_utils.c @@ -24,7 +24,7 @@ int set_expanded_cmd_name( expanded_list = NULL; ret = expand_list(shell, simple_cmd_list, &expanded_list, \ - E_EXPAND | E_SPLIT_WORDS | E_RM_QUOTES); + E_EXPAND | E_SPLIT_WORDS | E_WILDCARD | E_RM_QUOTES); *cmd_name = ft_lstpop_front_content(&expanded_list); ft_lstclear(&expanded_list, free); return (ret); diff --git a/source/backend/redirection/io_file.c b/source/backend/redirection/io_file.c index e33b28cb..a7c0d137 100644 --- a/source/backend/redirection/io_file.c +++ b/source/backend/redirection/io_file.c @@ -21,7 +21,8 @@ int expand_filename(t_shell *shell, char **filename) int ret; expanded_list = NULL; - ret = expander(*filename, &expanded_list, shell, E_EXPAND | E_RM_QUOTES); + ret = expander(*filename, + &expanded_list, shell, E_EXPAND | E_WILDCARD | E_RM_QUOTES); if (ret == MALLOC_ERROR || ret == BAD_SUBSTITUTION) return (ft_lstclear(&expanded_list, free), ret); if (ft_lstsize_non_null(expanded_list) != 1) diff --git a/source/debug/print_expanded_cmd_table_content.c b/source/debug/print_expanded_cmd_table_content.c index 8940c11e..37b85163 100644 --- a/source/debug/print_expanded_cmd_table_content.c +++ b/source/debug/print_expanded_cmd_table_content.c @@ -21,7 +21,7 @@ bool expand_and_print(char *str, t_shell *shell) expanded_list = NULL; ret = expander(str, &expanded_list, shell, - E_EXPAND | E_SPLIT_WORDS | E_RM_QUOTES); + E_EXPAND | E_SPLIT_WORDS | E_WILDCARD | E_RM_QUOTES); if (ret == MALLOC_ERROR) return (printf("malloc failed in expander"), false); if (ret == BAD_SUBSTITUTION) diff --git a/source/frontend/expander/expander.c b/source/frontend/expander/expander.c index 3fd4fc64..d1605be3 100644 --- a/source/frontend/expander/expander.c +++ b/source/frontend/expander/expander.c @@ -42,7 +42,7 @@ bool handle_expansion(t_list **lst, t_shell *shell, t_expander_op op_mask) !handle_word_splitting(lst, op_mask, &task_list) || \ !set_wildcard_task_list(&task_list, *lst, op_mask) || \ !handle_quote_removal(&task_list) || \ - !handle_wildcard_expansion(lst, &task_list)) + !handle_wildcard_expansion(lst, &task_list, op_mask)) return (ft_lstclear(&task_list, (void *)free_expander_task), false); ft_lstclear(&task_list, (void *)free_expander_task); return (true); diff --git a/source/frontend/expander/wildcard_expansion.c b/source/frontend/expander/wildcard_expansion.c index 168b6df4..5d8d447d 100644 --- a/source/frontend/expander/wildcard_expansion.c +++ b/source/frontend/expander/wildcard_expansion.c @@ -88,11 +88,12 @@ static bool iter_word_list(t_list **lst, t_list *file_list, t_list **task_list) return (true); } -bool handle_wildcard_expansion(t_list **lst, t_list **task_list) +bool handle_wildcard_expansion( + t_list **lst, t_list **task_list, t_expander_op op_mask) { t_list *file_list; - if (!any_wildcard(*lst, *task_list)) + if (!(op_mask & E_WILDCARD) || !any_wildcard(*lst, *task_list)) return (true); file_list = NULL; if (!set_file_list(&file_list)) diff --git a/source/frontend/expander/wildcard_task_list.c b/source/frontend/expander/wildcard_task_list.c index a9b4a9c7..4125fb87 100644 --- a/source/frontend/expander/wildcard_task_list.c +++ b/source/frontend/expander/wildcard_task_list.c @@ -62,7 +62,8 @@ bool set_wildcard_task_list( t_list *new_task_list; bool ret; - (void)op_mask; + if (!(op_mask & E_WILDCARD)) + return (true); ret = true; new_task_list = NULL; while (lst && ret) diff --git a/source/utils/final_cmd_table_setup.c b/source/utils/final_cmd_table_setup.c index e35e8a5e..e5f79581 100644 --- a/source/utils/final_cmd_table_setup.c +++ b/source/utils/final_cmd_table_setup.c @@ -19,7 +19,7 @@ int setup_simple_cmd(t_shell *shell, t_list *simple_cmd_list) expanded_list = NULL; ret = expand_list(shell, simple_cmd_list, &expanded_list, - E_EXPAND | E_SPLIT_WORDS | E_RM_QUOTES); + E_EXPAND | E_SPLIT_WORDS | E_WILDCARD | E_RM_QUOTES); if (ret != SUCCESS) return (ft_lstclear(&expanded_list, free), ret); shell->final_cmd_table->simple_cmd = \ diff --git a/todo b/todo index f95907df..c4dad70c 100644 --- a/todo +++ b/todo @@ -2,7 +2,11 @@ - [x] Get a list of all files of the current directoy. - [ ] Rename `lst` to `expanded_list` in expander. -- [ ] Rename all occurances of parameter to variable +- [ ] Rename all occurances of parameter to variable. +- [ ] Rename `E_EXPAND` to `E_PARAM` or `E_VAR`. +- [x] Check op_masks WHEN wildcard expansion should happen! + - [ ] Not for values when assigning env variables. + - [x] Not in heredoc content. ### Sorting - Numeric before alphabetic.