mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
minishell: do wildcard expansion
This commit is contained in:
parent
f06f6e26e2
commit
be183b99ee
5 changed files with 78 additions and 1 deletions
1
Makefile
1
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 \
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
41
src/postprocess/expansion/expand_wildcard.c
Normal file
41
src/postprocess/expansion/expand_wildcard.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* expand_wildcard.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
20
src/postprocess/expansion/expand_wildcard.h
Normal file
20
src/postprocess/expansion/expand_wildcard.h
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* expand_wildcard.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
12
test.sh
12
test.sh
|
|
@ -509,6 +509,18 @@ expecting <<EOF
|
|||
-hello there-
|
||||
EOF
|
||||
|
||||
when_run <<EOF "wildcards"
|
||||
echo *
|
||||
touch hi there hello
|
||||
echo *
|
||||
echo h*
|
||||
EOF
|
||||
expecting <<EOF
|
||||
*
|
||||
hello hi there
|
||||
hello hi
|
||||
EOF
|
||||
|
||||
when_run <<EOF "quoted parentheses are not operators"
|
||||
echo unclosed '('
|
||||
EOF
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue