diff --git a/Makefile b/Makefile index e0087aa..9955aab 100644 --- a/Makefile +++ b/Makefile @@ -84,6 +84,7 @@ srcs = \ src/parser/wordsplit/wordsplit.c \ src/parser/wordsplit/wordsplit_utils.c \ src/postprocess/expansion/expand_vars.c \ + src/postprocess/expansion/expand_wildcard.c \ src/postprocess/fieldsplit/fieldsplit.c \ src/subst/path_split.c \ src/subst/replace_substr.c \ diff --git a/src/minishell.c b/src/minishell.c index 3231c22..1e76190 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */ -/* Updated: 2025/04/15 15:05:48 by khais ### ########.fr */ +/* Updated: 2025/04/15 11:49:23 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,6 +24,7 @@ #include "postprocess/expansion/expand_vars.h" #include "parser/cmd_parsing.h" #include "postprocess/fieldsplit/fieldsplit.h" +#include "postprocess/expansion/expand_wildcard.h" /* ** execute command @@ -43,6 +44,8 @@ static t_cmd *post_process_command(t_cmd *cmd, t_minishell *app) return (simple_cmd_destroy(cmd), NULL); if (simple_cmd_fieldsplit(cmd) == NULL) return (simple_cmd_destroy(cmd), NULL); + if (simple_cmd_expand_wildcards(cmd) == NULL) + return (simple_cmd_destroy(cmd), NULL); return (cmd); } diff --git a/src/postprocess/expansion/expand_wildcard.c b/src/postprocess/expansion/expand_wildcard.c new file mode 100644 index 0000000..12c7587 --- /dev/null +++ b/src/postprocess/expansion/expand_wildcard.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* expand_wildcard.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/03 19:28:28 by khais #+# #+# */ +/* Updated: 2025/04/03 19:52:29 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "expand_wildcard.h" +#include "../../subst/subst.h" + +t_simple_cmd *simple_cmd_expand_wildcards(t_simple_cmd *cmd) +{ + t_wordlist *outlist; + t_wordlist *inlist; + t_worddesc *current; + t_wordlist *expansion_result; + + outlist = NULL; + inlist = cmd->words; + while (inlist != NULL) + { + current = wordlist_pop(&inlist); + expansion_result = expand_star(current); + if (expansion_result == NULL) + outlist = wordlist_push(outlist, current); + else + { + while (expansion_result != NULL) + outlist = wordlist_push(outlist, + wordlist_pop(&expansion_result)); + worddesc_destroy(current); + } + } + cmd->words = outlist; + return (cmd); +} diff --git a/src/postprocess/expansion/expand_wildcard.h b/src/postprocess/expansion/expand_wildcard.h new file mode 100644 index 0000000..bf204b7 --- /dev/null +++ b/src/postprocess/expansion/expand_wildcard.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* expand_wildcard.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/03 19:22:10 by khais #+# #+# */ +/* Updated: 2025/04/03 19:23:24 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef EXPAND_WILDCARD_H +# define EXPAND_WILDCARD_H + +# include "../../minishell.h" + +t_simple_cmd *simple_cmd_expand_wildcards(t_simple_cmd *cmd); + +#endif // EXPAND_WILDCARD_H diff --git a/test.sh b/test.sh index 9b108f2..04ae548 100755 --- a/test.sh +++ b/test.sh @@ -509,6 +509,18 @@ expecting <