From 497f442d775fcef46971eaa4d7f19058308240da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gu=C3=A9len?= Date: Fri, 25 Apr 2025 18:56:07 +0200 Subject: [PATCH] fix(expand-star): incomplete, committing to preserve --- src/subst/subst.h | 7 ++++--- src/subst/wildcard_exp.c | 24 +++++++++++++----------- src/subst/wildcard_exp_utils2.c | 21 ++++++++++++++++++++- 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/subst/subst.h b/src/subst/subst.h index 0f129ae..554a849 100644 --- a/src/subst/subst.h +++ b/src/subst/subst.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* subst.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: khais +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/04/22 13:14/27 by khais #+# #+# */ -/* Updated: 2025/04/22 13:14:27 by khais ### ########.fr */ +/* Created: 2025/04/22 13:14:27 by khais #+# #+# */ +/* Updated: 2025/04/25 18:02:13 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,5 +44,6 @@ void build_pattern_checks(char *str, t_worddesc *pattern, char **checker); void clean_pattern(t_worddesc *file_pattern); int ispattern(t_worddesc *desc); +t_worddesc *deal_with_potential_pattern_marker(t_worddesc *file_pattern); #endif diff --git a/src/subst/wildcard_exp.c b/src/subst/wildcard_exp.c index 69d2b67..062d05b 100644 --- a/src/subst/wildcard_exp.c +++ b/src/subst/wildcard_exp.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* wildcard_exp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: khais +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/20 15:01:38 by jguelen #+# #+# */ -/* Updated: 2025/04/22 13:18:18 by khais ### ########.fr */ +/* Updated: 2025/04/25 18:54:06 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -160,16 +160,18 @@ char fits_pattern(char *str, t_worddesc *pattern) return (ret); } -/* -** Returns NULL in case of error. -** NOTE: This phase of pre-processing relies partly on processing done before -** it therefore checks more loosely (and quote removal still seems not to be -** done on string comming from a variable expansion) <-----TO RE-CHECK -*/ t_wordlist *expand_star(t_worddesc *file_pattern) { - if (!ispattern(file_pattern)) + t_worddesc *pattern_copy; + t_wordlist *expanded; + + if (!file_pattern || !file_pattern->word) return (NULL); - clean_pattern(file_pattern); - return (expand_star_core(file_pattern)); + pattern_copy = deal_with_potential_pattern_marker(file_pattern); + if (!ispattern(pattern_copy)) + return (worddesc_destroy(pattern_copy), NULL); + clean_pattern(pattern_copy); + expanded = expand_star_core(pattern_copy); + worddesc_destroy(pattern_copy); + return (expanded); } diff --git a/src/subst/wildcard_exp_utils2.c b/src/subst/wildcard_exp_utils2.c index 1decd6b..4056960 100644 --- a/src/subst/wildcard_exp_utils2.c +++ b/src/subst/wildcard_exp_utils2.c @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/15 15:09:56 by jguelen #+# #+# */ -/* Updated: 2025/03/19 09:07:09 by jguelen ### ########.fr */ +/* Updated: 2025/04/25 18:53:04 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -65,3 +65,22 @@ int ispattern(t_worddesc *desc) } return (0); } + +t_worddesc *deal_with_potential_pattern_marker(t_worddesc *file_pattern) +{ + t_worddesc *pattern_copy; + int i; + char quote; + + pattern_copy = worddesc_copy(file_pattern); + if (file_pattern->flags & W_HASDOLLAR) + { + i = 0; + quote = '\0'; + while (file_pattern->word[i]) + { + i++; + } + } + return (pattern_copy); +} \ No newline at end of file