wildcards

This commit is contained in:
mdev9
2024-04-26 15:33:50 +02:00
parent 5eff48d14b
commit 6012037886

View File

@ -6,11 +6,42 @@
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */ /* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */ /* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */
/* Updated: 2024/04/26 10:49:36 by marde-vr ### ########.fr */ /* Updated: 2024/04/26 15:31:27 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int filename_corresponds(char *wildcard, char *value)
{
if (*value == '.' && *wildcard != '.')
return (0);
while (*wildcard && *value)
{
if (*wildcard == '*')
{
while (*wildcard == '*' && wildcard[1] == '*')
wildcard++;
if (!wildcard[1])
return (1);
while (*value)
{
if (filename_corresponds(wildcard + 1, value))
return (1);
value++;
}
return (0);
}
else if (*wildcard == *value || *wildcard == '?')
{
wildcard++;
value++;
}
else
return (0);
}
return (!*wildcard && !*value);
}
/*
int filename_corresponds(char *wildcard, char *value) int filename_corresponds(char *wildcard, char *value)
{ {
if (*value == '.' && *wildcard != '.') if (*value == '.' && *wildcard != '.')
@ -37,7 +68,7 @@ int filename_corresponds(char *wildcard, char *value)
return (0); return (0);
} }
return (!*wildcard && !*value); return (!*wildcard && !*value);
} }*/
t_token *get_all_files(DIR *dir, char *wildcard, int is_var) t_token *get_all_files(DIR *dir, char *wildcard, int is_var)
{ {