diff --git a/srcs/wildcards.c b/srcs/wildcards.c index ff492ef..43c02c8 100644 --- a/srcs/wildcards.c +++ b/srcs/wildcards.c @@ -6,11 +6,42 @@ /* 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" +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) { if (*value == '.' && *wildcard != '.') @@ -37,7 +68,7 @@ int filename_corresponds(char *wildcard, char *value) return (0); } return (!*wildcard && !*value); -} +}*/ t_token *get_all_files(DIR *dir, char *wildcard, int is_var) {