diff --git a/src/builtins/ft_cd.c b/src/builtins/ft_cd.c index b6c03c7..4cd5c91 100644 --- a/src/builtins/ft_cd.c +++ b/src/builtins/ft_cd.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/22 15:07:24 by adjoly #+# #+# */ -/* Updated: 2024/07/16 13:39:26 by adjoly ### ########.fr */ +/* Updated: 2024/07/16 15:48:44 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,20 +16,10 @@ #include "libft.h" #include "builtins.h" -void ft_cd(t_env *env, char *args) +void change_dir(char *new_pwd, char *pwd, t_env *env) { - char *pwd; - char *new_pwd; int ret; - new_pwd = NULL; - pwd = ft_strdup(ret_cwd()); - if (!args) - new_pwd = env_get_value("HOME", env); - else if (args[0] == '-') - new_pwd = env_get_value("OLDPWD", env); - else - new_pwd = ft_strdup(args); ret = chdir(new_pwd); free(new_pwd); if (ret == -1) @@ -41,3 +31,24 @@ void ft_cd(t_env *env, char *args) env_edit("PWD", ft_strdup(ret_cwd()), env); env_edit("OLDPWD", pwd, env); } + +void ft_cd(t_env *env, char *args) +{ + char *pwd; + char *new_pwd; + + new_pwd = NULL; + pwd = ft_strdup(ret_cwd()); + if (!args) + new_pwd = env_get_value("HOME", env); + else if (args[0] == '-') + new_pwd = env_get_value("OLDPWD", env); + else + new_pwd = ft_strdup(args); + if (!new_pwd) + { + free(pwd); + return ; + } + change_dir(new_pwd, pwd, env); +} diff --git a/src/exec/format_quotes.c b/src/exec/format_quotes.c index 49a65ff..083763f 100644 --- a/src/exec/format_quotes.c +++ b/src/exec/format_quotes.c @@ -6,7 +6,7 @@ /* By: mmoussou +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/06/21 11:59:34 by adjoly #+# #+# */ -/* Updated: 2024/07/15 18:16:52 by adjoly ### ########.fr */ +/* Updated: 2024/07/16 16:15:41 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "parsing.h" #include "error_msg.h" #include "tokenizer.h" +#include -size_t count_quote(char *readline, t_quote type) +bool watch_quote(char *rl) { char *tmp; - size_t count; - tmp = readline; - count = 0; + tmp = rl; while (*tmp) { - if (*tmp == type) - count += search_for_next_quote(tmp, type) - tmp; + if (__is_quote(*tmp) != FALSE) + { + tmp = search_for_next_quote(tmp + 1, __is_quote(*tmp)); + if (!tmp) + return (true); + } tmp++; } - return (count); + return (false); } bool check_quote(char *readline) { - size_t count; - - count = count_quote(readline, DOUBLE); - if (count % 2) - return (send_error_parsing("double quote not closed")); - count = count_quote(readline, SINGLE); - if (count % 2) - return (send_error_parsing("single quote not closed")); + if (watch_quote(readline)) + return (send_error_parsing("quote not closed")); return (false); } diff --git a/src/parsing/is_inquote.c b/src/parsing/is_inquote.c index 3d07518..04736bd 100644 --- a/src/parsing/is_inquote.c +++ b/src/parsing/is_inquote.c @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/20 20:06:13 by adjoly #+# #+# */ -/* Updated: 2024/07/06 14:52:02 by adjoly ### ########.fr */ +/* Updated: 2024/07/16 15:55:00 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,10 +17,17 @@ char *search_for_next_quote(char *s, t_quote quote_type) { char *tmp; + t_quote o_quote; tmp = s; - while (*tmp && __is_quote(*tmp) != quote_type) + if (quote_type == DOUBLE) + o_quote = SINGLE; + else if (quote_type == SINGLE) + o_quote = DOUBLE; + while (*tmp && __is_quote(*tmp) != quote_type && __is_quote(*tmp) != o_quote) tmp++; + if (__is_quote(*tmp) != quote_type) + return (NULL); return (tmp); }