From 0f8b18b32ff2b51f36b6eafa87a8f9a848a4c527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gu=C3=A9len?= Date: Wed, 19 Mar 2025 09:20:51 +0100 Subject: [PATCH] Expansion: Fixed inclusions and Norm checked Now on to remake tests properly. --- Makefile | 2 +- src/subst/simple_filename_exp.c | 30 +++++---------------------- src/subst/simple_filename_exp_utils.c | 6 ++++-- src/subst/subst.h | 12 ++++++++++- src/subst/variable_subst_utils.c | 7 ++++--- src/subst/wildcard_exp.c | 29 ++------------------------ src/subst/wildcard_exp_utils.c | 4 ++-- src/subst/wildcard_exp_utils2.c | 7 ++++--- 8 files changed, 33 insertions(+), 64 deletions(-) diff --git a/Makefile b/Makefile index 370e780..3c50bc9 100644 --- a/Makefile +++ b/Makefile @@ -68,8 +68,8 @@ srcs = \ src/subst/variable_subst.c \ src/subst/variable_subst_utils.c \ src/subst/wildcard_exp.c \ - src/subst/wildcard_exp_utils.c \ src/subst/wildcard_exp_utils2.c \ + src/subst/wildcard_exp_utils.c \ objs = $(srcs:.c=.o) export objs diff --git a/src/subst/simple_filename_exp.c b/src/subst/simple_filename_exp.c index 017abb5..2d1c2b7 100644 --- a/src/subst/simple_filename_exp.c +++ b/src/subst/simple_filename_exp.c @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/02 13:40:10 by jguelen #+# #+# */ -/* Updated: 2025/03/18 18:38:53 by jguelen ### ########.fr */ +/* Updated: 2025/03/19 09:01:54 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,31 +14,11 @@ #include "libft.h" #include "../ft_errno.h" #include "../env/env_manip.h" +#include "path_split.h" +#include "subst.h" #include #include -/* -** Returns a malloc-allocated string corresponding to -** "path_dir/name" -*/ -char *alloc_path(char *path_dir, char *name) -{ - char *path; - size_t dir_len; - size_t name_len; - - dir_len = ft_strlen(path_dir); - name_len = ft_strlen(name); - path = malloc((dir_len + name_len + 2) * sizeof(char)); - if (!path) - return (NULL); - ft_memcpy(path, path_dir, dir_len); - path[dir_len] = '/'; - ft_memcpy(path + dir_len + 1, name, name_len); - path[dir_len + name_len + 1] = '\0'; - return (path); -} - /* ** The return value of this function is always safe to destroy with ** path_split_destroy. @@ -118,7 +98,7 @@ static char *deal_with_filled_path(char *filename, char **path, /* ** Returns NULL on error or if nothing is found. */ -char *filepath_from_env(char *filename, t_minishell *app) +static char *filepath_from_env(char *filename, t_minishell *app) { char *filepath; char **path; @@ -154,7 +134,7 @@ char *filepath_from_env(char *filename, t_minishell *app) ** NOTE: if name contains a '/' character then name is considered to ** be an absolute path. */ -char *get_filepath(const char *name, t_minishell *app) +char *get_cmdpath(const char *name, t_minishell *app) { char *cmd_path; diff --git a/src/subst/simple_filename_exp_utils.c b/src/subst/simple_filename_exp_utils.c index 7586ce4..02345d4 100644 --- a/src/subst/simple_filename_exp_utils.c +++ b/src/subst/simple_filename_exp_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* simple_filename_exp_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/18 18:40:14 by jguelen #+# #+# */ -/* Updated: 2025/03/18 18:40:33 by jguelen ### ########.fr */ +/* Updated: 2025/03/19 09:02:22 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,9 @@ #include "libft.h" #include "../ft_errno.h" #include "../env/env_manip.h" +#include "subst.h" #include +#include #include /* diff --git a/src/subst/subst.h b/src/subst/subst.h index b247051..52f8abe 100644 --- a/src/subst/subst.h +++ b/src/subst/subst.h @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/23 15:01:40 by jguelen #+# #+# */ -/* Updated: 2025/03/14 14:28:20 by jguelen ### ########.fr */ +/* Updated: 2025/03/19 09:20:02 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,9 +16,12 @@ # include "../parser/wordlist/wordlist.h" # include "../parser/wordlist/wordlist_quicksort.h" # include "../minishell.h" +# include "replace_substr.h" # include # include # include +# include +# include "../../libft/libft.h" # define PATH_SIZE_INIT 64 @@ -33,4 +36,11 @@ t_wordlist *expand_star(t_worddesc *file_pattern); char *construct_repeting_char_string(char c, size_t len); char *ft_get_longest_identifier(char *str); +char *alloc_path(char *path_dir, char *name); +char *get_cmdpath(const char *name, t_minishell *app); + +void destroy_pattern_check(char **pattern_check, size_t len); +void build_pattern_checks(char *str, t_worddesc *pattern, + char **checker); + #endif diff --git a/src/subst/variable_subst_utils.c b/src/subst/variable_subst_utils.c index 96a7b0d..102ab44 100644 --- a/src/subst/variable_subst_utils.c +++ b/src/subst/variable_subst_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* variable_subst_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: khais +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/03/06 13:03/41 by khais #+# #+# */ -/* Updated: 2025/03/08 14:06:20 by jguelen ### ########.fr */ +/* Created: 2025/03/06 13:03:41 by khais #+# #+# */ +/* Updated: 2025/03/19 09:03:31 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include "../minishell.h" #include "replace_substr.h" #include "../env/env.h" +#include "../../libft/libft.h" /* ** Returns a C-compliant malloc-allocated string of length len and composed diff --git a/src/subst/wildcard_exp.c b/src/subst/wildcard_exp.c index 76f2218..4dd97e7 100644 --- a/src/subst/wildcard_exp.c +++ b/src/subst/wildcard_exp.c @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/23 15:02:59 by jguelen #+# #+# */ -/* Updated: 2025/03/18 18:44:05 by jguelen ### ########.fr */ +/* Updated: 2025/03/19 09:18:53 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,6 @@ #include "subst.h" #include "replace_substr.h" -/* -** TODO Pre-process file_pattern worddesc for a congruent marker string -*/ /******************************************************************************/ /* NOTE: The use of errno and the setting of it was OKed by Alexandru in this */ /* context. */ @@ -25,7 +22,7 @@ ** Returns a directory stream corresponding to the current directory. ** */ -DIR *open_current_dir(void) +static DIR *open_current_dir(void) { char *cur_dir_path; size_t size; @@ -51,11 +48,6 @@ DIR *open_current_dir(void) return (dir); } -/* -** TODO produce a clean marker string that denotes file_desc as issued from -** a pattern expansion or as quoted for possible spaces characters in the -** filename not to pose any possible issue. -*/ static t_wordlist *add_file_to_list(t_wordlist **list, char *filename) { t_worddesc *file_desc; @@ -74,20 +66,6 @@ static t_wordlist *add_file_to_list(t_wordlist **list, char *filename) return (*list); } -/* -** TODO Check if return value correct regarding the manual specifically the -** following: -** cf Bash scans each word for the character '*'. -** -** If one of these characters appears, and is not quoted, then the word is -** regarded as a PATTERN, and replaced with an alphabetically sorted list -** of filenames matching the pattern (see: Pattern Matching). If no matching -** filenames are found, the word is left unchanged. -** --> TODO this function should be provided with a properly pre-processed -** file_pattern where file_pattern->matcher denotes the quoted wildcards -** but the quotes themselves unquoted have been removed from word in a manner -** keeping the relationship between word and marker coherent. -*/ /* ** A function designed to present all possible * or ? filename expansions ** for the current directory. (? is not asked by the subject). @@ -164,9 +142,6 @@ char fits_pattern(char *str, t_worddesc *pattern) } /* -** TODO -** Pre-processes file_pattern to give it a proper marker chain and remove -** unquoted quotes from the pattern. ** 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 diff --git a/src/subst/wildcard_exp_utils.c b/src/subst/wildcard_exp_utils.c index fa03dea..5019e8d 100644 --- a/src/subst/wildcard_exp_utils.c +++ b/src/subst/wildcard_exp_utils.c @@ -6,7 +6,7 @@ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/07 17:10:01 by jguelen #+# #+# */ -/* Updated: 2025/03/15 15:33:07 by jguelen ### ########.fr */ +/* Updated: 2025/03/19 09:15:13 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ /* ** Cleanly disposes of a pattern checker two dimensionnal array. */ -static void destroy_pattern_check(char **pattern_check, size_t len) +void destroy_pattern_check(char **pattern_check, size_t len) { size_t i; diff --git a/src/subst/wildcard_exp_utils2.c b/src/subst/wildcard_exp_utils2.c index 02973b6..1decd6b 100644 --- a/src/subst/wildcard_exp_utils2.c +++ b/src/subst/wildcard_exp_utils2.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* wildcard_exp_utils2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/15 15:09:56 by jguelen #+# #+# */ -/* Updated: 2025/03/18 18:54:06 by jguelen ### ########.fr */ +/* Updated: 2025/03/19 09:07:09 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ #include "replace_substr.h" /* -** TODO +** Removes unquoted quotes and from file_pattern->word and keeps +** file_pattern->marker congruent. */ void clean_pattern(t_worddesc *file_pattern) {