From 7cb969cabaeb75614f805cc91ba7e8e6472d5db6 Mon Sep 17 00:00:00 2001 From: mdev9 Date: Wed, 24 Apr 2024 20:40:16 +0200 Subject: [PATCH] fixed wildcards --- srcs/parsing.c | 8 +++++--- srcs/path.c | 4 ++-- srcs/wildcards.c | 19 +++++++++++++------ 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/srcs/parsing.c b/srcs/parsing.c index ff7d70d..747b107 100755 --- a/srcs/parsing.c +++ b/srcs/parsing.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/09 15:26:01 by tomoron #+# #+# */ -/* Updated: 2024/04/24 18:08:42 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 20:39:35 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -50,7 +50,8 @@ char *get_token(char **cmd, int *quotes[2], t_env *env, int *is_var) i += add_var_to_str(res + i, cmd, env, is_var); else if (**cmd == '~' && !*(quotes[0]) && !*(quotes[1])) i += add_home_to_str(res + i); - else if (((**cmd == '\'' && *(quotes[1])) || (**cmd == '"' && *(quotes[0]))) + else if (((**cmd == '\'' && *(quotes[1])) + || (**cmd == '"' && *(quotes[0]))) || (**cmd != '\'' && **cmd != '"')) res[i++] = **cmd; (*cmd)++; @@ -72,7 +73,8 @@ t_token *parse_tokens(char *command, t_env *env) is_var = 0; while (command && *command) { - value = get_token(&command, (int *[2]){&in_quote, &in_dquote}, env, &is_var); + value = get_token(&command, (int *[2]){&in_quote, &in_dquote}, + env, &is_var); if (!value) return (free_token(res)); res = expand_wildcards(res, value, is_var); diff --git a/srcs/path.c b/srcs/path.c index 90f1c4c..f801f70 100755 --- a/srcs/path.c +++ b/srcs/path.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/21 21:47:15 by marde-vr #+# #+# */ -/* Updated: 2024/04/24 17:48:14 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 20:37:41 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -94,7 +94,7 @@ void get_cmd_path(t_msh *msh) get_path(msh, &found); if (!found) { - if(!*(msh->tokens->value)) + if (!*(msh->tokens->value)) ft_printf_fd(2, "'': command not found\n"); else ft_printf_fd(2, "%s: command not found\n", msh->tokens->value); diff --git a/srcs/wildcards.c b/srcs/wildcards.c index d884fc9..8f94ced 100644 --- a/srcs/wildcards.c +++ b/srcs/wildcards.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/04/15 12:53:29 by tomoron #+# #+# */ -/* Updated: 2024/04/24 18:02:49 by tomoron ### ########.fr */ +/* Updated: 2024/04/24 20:37:10 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" @@ -15,20 +15,27 @@ int filename_corresponds(char *wildcard, char *value) { if (*value == '.' && *wildcard != '.') return (0); - while (*wildcard && (*wildcard == '*' || *wildcard == *value)) + while (*wildcard && *value) { if (*wildcard == '*') { - while (*wildcard && *value && *value != wildcard[1] - && *wildcard != wildcard[1]) + if (!wildcard[1]) + return (1); + while (*value) + { + if (filename_corresponds(wildcard + 1, value)) + return (1); value++; - wildcard++; + } + return (0); } - while (*wildcard && *value && *value == *wildcard && *wildcard != '*') + else if (*wildcard == *value) { wildcard++; value++; } + else + return (0); } return (!*wildcard && !*value); }