mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🔨」 fix: fixed quote unclosed
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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;
|
||||
|
||||
tmp = search_for_next_quote(cmd + 1, __is_quote(*cmd));
|
||||
if (!tmp)
|
||||
return (0);
|
||||
return (tmp - cmd);
|
||||
}
|
||||
|
||||
@ -45,6 +47,8 @@ char *format_quotes_string(char *cmd)
|
||||
if (*tmp == DOUBLE || *tmp == SINGLE)
|
||||
{
|
||||
inquote = __get_size_in_quote(tmp);
|
||||
if (inquote == 0)
|
||||
return (NULL);
|
||||
ft_strlcat(ret, tmp + 1, ft_strlen(ret) + inquote);
|
||||
tmp += inquote;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
rl = env_var_replace(rl, env_l);
|
||||
printf ("\t%s\n", rl);
|
||||
get_rl(&rl);
|
||||
piped = tokenizer(rl);
|
||||
get_list(&piped);
|
||||
|
@ -6,39 +6,36 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <stdio.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user