diff --git a/Makefile b/Makefile index 23ba6dd..931d191 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,9 @@ srcs = \ src/postprocess/redirections/redirection_parsing.c \ src/postprocess/redirections/redirection_type.c \ src/subst/replace_substr.c \ + src/subst/variable_subst.c \ + src/subst/variable_subst_utils.c \ + src/subst/wildcard_exp.c \ objs = $(srcs:.c=.o) export objs diff --git a/src/minishell.h b/src/minishell.h index 4c32047..ac86588 100644 --- a/src/minishell.h +++ b/src/minishell.h @@ -3,16 +3,18 @@ /* ::: :::::::: */ /* minishell.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/24 12:51:21 by jguelen #+# #+# */ -/* Updated: 2025/03/01 16:59:30 by jguelen ### ########.fr */ +/* Created: 2025/03/06 12:46/06 by khais #+# #+# */ +/* Updated: 2025/03/06 12:46:06 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H # define MINISHELL_H +# include "env/env.h" + typedef struct s_minishell { t_env *env; diff --git a/src/subst/subst.h b/src/subst/subst.h index 7e350b2..505067b 100644 --- a/src/subst/subst.h +++ b/src/subst/subst.h @@ -3,22 +3,24 @@ /* ::: :::::::: */ /* subst.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/23 15:01:40 by jguelen #+# #+# */ -/* Updated: 2025/03/01 17:00:52 by jguelen ### ########.fr */ +/* Created: 2025/03/06 13:06/10 by khais #+# #+# */ +/* Updated: 2025/03/06 13:06:10 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef SUBST_H # define SUBST_H -# include # include "../parser/wordlist/wordlist.h" # include "../minishell.h" -int expand_question_mark(t_minishell *app); -t_wordlist *wordlist_var_expansion(t_wordlist *list, t_env *env); +char *expand_question_mark(t_minishell *app); +t_wordlist *wordlist_var_expansion(t_wordlist *list, t_minishell *app); +t_worddesc *word_var_expansion(t_worddesc *word, t_minishell *app); t_wordlist *expand_star(char *file_pattern); +char *construct_repeting_char_string(char c, size_t len); +char *ft_get_longest_identifier(char *str); #endif diff --git a/src/subst/variable_subst.c b/src/subst/variable_subst.c index 9b844de..a4c26b4 100644 --- a/src/subst/variable_subst.c +++ b/src/subst/variable_subst.c @@ -3,17 +3,16 @@ /* ::: :::::::: */ /* variable_subst.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/23 15:02:37 by jguelen #+# #+# */ -/* Updated: 2025/03/01 17:01:47 by jguelen ### ########.fr */ +/* Created: 2025/03/06 12:48/00 by khais #+# #+# */ +/* Updated: 2025/03/06 12:48:00 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include "subst.h" #include "../minishell.h" #include "replace_substr.h" -#include "../env/env.h" #include "../env/env_manip.h" static char *word_update(t_worddesc *word, size_t i, size_t id_len, char *rep) diff --git a/src/subst/variable_subst_utils.c b/src/subst/variable_subst_utils.c index 2487060..0ab9ca2 100644 --- a/src/subst/variable_subst_utils.c +++ b/src/subst/variable_subst_utils.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* variable_subst_utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/03/01 13:04:27 by jguelen #+# #+# */ -/* Updated: 2025/03/01 17:02:27 by jguelen ### ########.fr */ +/* Created: 2025/03/06 13:03/41 by khais #+# #+# */ +/* Updated: 2025/03/06 13:03:41 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ #include "../minishell.h" #include "replace_substr.h" #include "../env/env.h" -#include "../env/env_manip.h" /* ** Returns a C-compliant malloc-allocated string of length len and complosed diff --git a/src/subst/wildcard_exp.c b/src/subst/wildcard_exp.c index 289a23a..27377fd 100644 --- a/src/subst/wildcard_exp.c +++ b/src/subst/wildcard_exp.c @@ -3,14 +3,16 @@ /* ::: :::::::: */ /* wildcard_exp.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/23 15:02:59 by jguelen #+# #+# */ -/* Updated: 2025/02/25 10:07:59 by jguelen ### ########.fr */ +/* Created: 2025/03/06 13:02/36 by khais #+# #+# */ +/* Updated: 2025/03/06 13:02:36 by khais ### ########.fr */ /* */ /* ************************************************************************** */ +#include "ft_printf.h" #include "subst.h" +#include "unistd.h" /* ** TODO @@ -26,4 +28,7 @@ */ t_wordlist *expand_star(char *file_pattern) { + (void)file_pattern; + ft_dprintf(STDERR_FILENO, "Not implemented: expand_star\n"); + return (NULL); } diff --git a/tests/expansion.c b/tests/expansion.c index 090951e..788feb9 100644 --- a/tests/expansion.c +++ b/tests/expansion.c @@ -3,20 +3,20 @@ /* ::: :::::::: */ /* expansion.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jguelen +#+ +:+ +#+ */ +/* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/23 15:00:18 by jguelen #+# #+# */ -/* Updated: 2025/03/01 11:07:17 by jguelen ### ########.fr */ +/* Created: 2025/03/06 13:01/15 by khais #+# #+# */ +/* Updated: 2025/03/06 13:01:15 by khais ### ########.fr */ /* */ /* ************************************************************************** */ #include #include #include "testutil.h" -#include "../src/subst/subst.h" #include "../src/subst/replace_substr.h" -#include "../../env/env.h" -#include "../../env/env_manip.h" +#include "../src/subst/subst.h" +#include "../src/env/env.h" +#include "../src/env/env_manip.h" /* ** Test file for the different expansion/substitution types of minishell. @@ -46,48 +46,52 @@ static void test_insert_instr(void) //Test to be remade since structures changed in the function calls and returns. static void test_env_variable_expansion(void) { - char *token; - char *tk; + t_worddesc *token; + t_worddesc *tk; t_env *env; + struct s_minishell app; - token = ft_strdup("$USER"); + app.last_return_value = 0; + + token = worddesc_create(ft_strdup("$USER"), W_HASDOLLAR); if (!token) assert("ft_strdup failed" && false); env = NULL; + app.env = env; env = env_set_entry(&env, "USER", "jguelen"); if (env == NULL) assert("malloc failed" && false); env = env_set_entry(&env, "_canard", "coing coing"); if (!env) assert("malloc failed: slipped on a duck" && false); - tk = word_var_expansion(&token, env); + tk = word_var_expansion(token, &app); if (!tk) assert("internal word_var_expansion failure" && false); - assert_strequal("jguelen", tk); + assert_strequal("jguelen", tk->word); free(token); - token = ft_strdup("\"$_caneton\""); + token = worddesc_create(ft_strdup("\"$_caneton\""), W_HASDOLLAR); if (!token) assert("ft_strdup failed" && false); - tk = word_var_expansion(&token, env); + tk = word_var_expansion(token, &app); if (!tk) assert("internal word_var_expansion failure" && false); - assert_strequal("\"\"", tk); + assert_strequal("\"\"", tk->word); free(token); - token = ft_strdup("$_canard$USER$''$USER\"\"\"$_canard\"$"); + token = worddesc_create(ft_strdup("$_canard$USER$''$USER\"\"\"$_canard\"$"), W_HASDOLLAR); if (!token) assert("ft_strdup failed" && false); - tk = word_var_expansion(token, env); + tk = word_var_expansion(token, &app); if (!tk) assert("internal word_var_expansion failure" && false); - assert_strequal("coing coingjguelen''jguelencoing coing$", tk); + assert_strequal("coing coingjguelen''jguelencoing coing$", tk->word); free(token); - token = ft_strdup("$_can'a'rd"); + token = worddesc_create(ft_strdup("$_can'a'rd"), W_HASDOLLAR); if (!token) assert("ft_strdup failed" && false); - tk = word_var_expansion(token, env); + tk = word_var_expansion(token, &app); if (!tk) assert("internal word_var_expansion failure" && false); - assert_strequal("'a'rd", tk); + assert_strequal("'a'rd", tk->word); free(token); env_destroy(env); }