fixed wildcards

This commit is contained in:
mdev9
2024-04-26 15:45:28 +02:00
parent 6012037886
commit 2290d638b6

View File

@ -6,42 +6,24 @@
/* 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 15:31:27 by marde-vr ### ########.fr */ /* Updated: 2024/04/26 15:44:12 by marde-vr ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int filename_corresponds(char *wildcard, char *value) int filename_corresponds(char *wildcard, char *value);
int recursive_filename_check(char *wildcard, char **value)
{ {
if (*value == '.' && *wildcard != '.') while (**value)
return (0); {
while (*wildcard && *value) if (filename_corresponds(wildcard + 1, *value))
{ return (1);
if (*wildcard == '*') (*value)++;
{ }
while (*wildcard == '*' && wildcard[1] == '*') return (0);
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 != '.')
@ -54,9 +36,7 @@ int filename_corresponds(char *wildcard, char *value)
wildcard++; wildcard++;
if (!wildcard[1]) if (!wildcard[1])
return (1); return (1);
while (*value) recursive_filename_check(wildcard, &value);
if (filename_corresponds(wildcard + 1, value++))
return (1);
return (0); return (0);
} }
else if (*wildcard == *value) else if (*wildcard == *value)
@ -68,7 +48,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)
{ {