🔨」 fix: fixed quote unclosed

This commit is contained in:
2024-07-16 16:20:23 +02:00
parent bf60c02fd3
commit e0987139dd
6 changed files with 53 additions and 34 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/22 15:07:24 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 "libft.h"
#include "builtins.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; 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); ret = chdir(new_pwd);
free(new_pwd); free(new_pwd);
if (ret == -1) 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("PWD", ft_strdup(ret_cwd()), env);
env_edit("OLDPWD", pwd, 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);
}

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 10:50:52 by mmoussou #+# #+# */ /* Created: 2024/07/03 10:50:52 by mmoussou #+# #+# */
/* Updated: 2024/07/15 18:36:05 by adjoly ### ########.fr */ /* Updated: 2024/07/16 16:17:45 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,6 +17,8 @@ size_t __get_size_in_quote(char *cmd)
char *tmp; char *tmp;
tmp = search_for_next_quote(cmd + 1, __is_quote(*cmd)); tmp = search_for_next_quote(cmd + 1, __is_quote(*cmd));
if (!tmp)
return (0);
return (tmp - cmd); return (tmp - cmd);
} }
@ -45,6 +47,8 @@ char *format_quotes_string(char *cmd)
if (*tmp == DOUBLE || *tmp == SINGLE) if (*tmp == DOUBLE || *tmp == SINGLE)
{ {
inquote = __get_size_in_quote(tmp); inquote = __get_size_in_quote(tmp);
if (inquote == 0)
return (NULL);
ft_strlcat(ret, tmp + 1, ft_strlen(ret) + inquote); ft_strlcat(ret, tmp + 1, ft_strlen(ret) + inquote);
tmp += inquote; tmp += inquote;
} }

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/09 22:53:01 by adjoly #+# #+# */ /* Created: 2024/07/09 22:53:01 by adjoly #+# #+# */
/* Updated: 2024/07/16 14:39:09 by adjoly ### ########.fr */ /* Updated: 2024/07/16 15:49:01 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,4 +36,3 @@ int send_error_exec(char *input)
free(input); free(input);
return (-1); return (-1);
} }

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */ /* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
/* Updated: 2024/07/16 14:40:35 by adjoly ### ########.fr */ /* Updated: 2024/07/16 16:15:38 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -83,6 +83,7 @@ int main(int ac, char **av, char **env)
} }
add_history(rl); add_history(rl);
rl = env_var_replace(rl, env_l); rl = env_var_replace(rl, env_l);
printf ("\t%s\n", rl);
get_rl(&rl); get_rl(&rl);
piped = tokenizer(rl); piped = tokenizer(rl);
get_list(&piped); get_list(&piped);

View File

@ -6,39 +6,36 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/21 11:59:34 by adjoly #+# #+# */ /* 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 "parsing.h"
#include "error_msg.h" #include "error_msg.h"
#include "tokenizer.h" #include "tokenizer.h"
#include <stdio.h>
size_t count_quote(char *readline, t_quote type) bool watch_quote(char *rl)
{ {
char *tmp; char *tmp;
size_t count;
tmp = readline; tmp = rl;
count = 0;
while (*tmp) while (*tmp)
{ {
if (*tmp == type) if (__is_quote(*tmp) != FALSE)
count += search_for_next_quote(tmp, type) - tmp; {
tmp = search_for_next_quote(tmp + 1, __is_quote(*tmp));
if (!tmp)
return (true);
}
tmp++; tmp++;
} }
return (count); return (false);
} }
bool check_quote(char *readline) bool check_quote(char *readline)
{ {
size_t count; if (watch_quote(readline))
return (send_error_parsing("quote not closed"));
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"));
return (false); return (false);
} }

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 20:06:13 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 *search_for_next_quote(char *s, t_quote quote_type)
{ {
char *tmp; char *tmp;
t_quote o_quote;
tmp = s; 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++; tmp++;
if (__is_quote(*tmp) != quote_type)
return (NULL);
return (tmp); return (tmp);
} }