wildcards (mieux)
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */
|
||||
/* Updated: 2024/04/15 18:54:15 by tomoron ### ########.fr */
|
||||
/* Updated: 2024/04/16 09:34:47 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
#include "minishell.h"
|
||||
@ -15,11 +15,11 @@ int filename_corresponds(char *wildcard, char *value)
|
||||
{
|
||||
if(*value == '.' && *wildcard != '.')
|
||||
return(0);
|
||||
while(*wildcard && *value && (*wildcard == '*' || *wildcard == *value))
|
||||
while(*wildcard && (*wildcard == '*' || *wildcard == *value))
|
||||
{
|
||||
if(*wildcard == '*')
|
||||
{
|
||||
while(*wildcard && *value && *value != wildcard[1])
|
||||
while(*wildcard && *value && *value != wildcard[1] && *wildcard != wildcard[1])
|
||||
value++;
|
||||
wildcard++;
|
||||
}
|
||||
@ -29,7 +29,7 @@ int filename_corresponds(char *wildcard, char *value)
|
||||
value++;
|
||||
}
|
||||
}
|
||||
return(!*wildcard);
|
||||
return(!*wildcard && !*value);
|
||||
}
|
||||
|
||||
t_token *expand_wildcards(t_token *res, char *value)
|
||||
@ -37,7 +37,9 @@ t_token *expand_wildcards(t_token *res, char *value)
|
||||
DIR *dir;
|
||||
char *cwd;
|
||||
struct dirent *content;
|
||||
int found;
|
||||
|
||||
found = 0;
|
||||
if(!ft_strchr(value, '*'))
|
||||
return(token_add_back(res, value));
|
||||
cwd = getcwd(NULL, 100000);
|
||||
@ -51,11 +53,14 @@ t_token *expand_wildcards(t_token *res, char *value)
|
||||
while(content)
|
||||
{
|
||||
if(filename_corresponds(value, content->d_name))
|
||||
{
|
||||
res = token_add_back(res,ft_strdup(content->d_name));
|
||||
found = 1;
|
||||
}
|
||||
content = readdir(dir);
|
||||
}
|
||||
closedir(dir);
|
||||
if(!res)
|
||||
if(!found)
|
||||
return(token_add_back(res, value));
|
||||
free(value);
|
||||
return(res);
|
||||
|
Reference in New Issue
Block a user