🔨」 fix: Fixed merge conflict on main

This commit is contained in:
2024-06-29 15:35:28 +02:00
parent 5e68b7342d
commit 26b8603933
7 changed files with 83 additions and 39 deletions

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */ /* Created: 2024/04/25 12:20:26 by adjoly #+# #+# */
/* Updated: 2024/06/26 12:45:23 by adjoly ### ########.fr */ /* Updated: 2024/06/29 15:31:02 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -43,6 +43,9 @@ char *env_var_replace(char *readline, t_env *env);
size_t get_size_with_env(char *readline, t_env *env); size_t get_size_with_env(char *readline, t_env *env);
size_t strlen_till_char(char *s, int c); size_t strlen_till_char(char *s, int c);
void check_quote(char *readline); void check_quote(char *readline);
t_quote __is_quote(char c);
char *search_for_next_quote(char *s, t_quote quote_type);
char **split_argv(char *readline);
/** /**
* @brief Take the argv of a command a split the argv and the * @brief Take the argv of a command a split the argv and the
* command it self * command it self

View File

@ -6,10 +6,11 @@
/* 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/06/27 15:37:43 by mmoussou ### ########.fr */ /* Updated: 2024/06/29 15:34:53 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include <signal.h>
#include <stdio.h> #include <stdio.h>
#include <readline/readline.h> #include <readline/readline.h>
#include <readline/history.h> #include <readline/history.h>
@ -73,6 +74,8 @@ void sigggg(int code)
void siggg_backslash(int code) void siggg_backslash(int code)
{ {
(void)code; (void)code;
rl_replace_line("", 0);
rl_redisplay();
} }
void siggg_d(int code) void siggg_d(int code)
@ -95,6 +98,7 @@ int main(int ac, char **av, char **env)
piped = NULL; piped = NULL;
if (env_init(env, &env_l)) if (env_init(env, &env_l))
return (EXIT_FAILURE); return (EXIT_FAILURE);
sigemptyset(&(sigset_t){SIGQUIT});
signal(SIGINT, &sigggg); signal(SIGINT, &sigggg);
signal(SIGQUIT, &siggg_backslash); signal(SIGQUIT, &siggg_backslash);
signal(SIGSEGV, &siggg_d); signal(SIGSEGV, &siggg_d);
@ -126,10 +130,10 @@ int main(int ac, char **av, char **env)
continue ; continue ;
} }
else if (is_str(test, "exit")) else if (is_str(test, "exit"))
; exit(EXIT_SUCCESS);
check_quote(test); check_quote(test);
piped = tokenizer(test); piped = tokenizer(test);
//check_redir(((t_token *)(piped->content))->redirection, av); check_redir(((t_token *)(piped->content))->redirection, av);
cmd_list = get_cmd_list(piped, &env_l); cmd_list = get_cmd_list(piped, &env_l);
exec_split_cmd(cmd_list, &env_l); exec_split_cmd(cmd_list, &env_l);
free(test); free(test);

View File

@ -6,7 +6,7 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */ /* Created: 2024/05/30 10:48:41 by adjoly #+# #+# */
/* Updated: 2024/06/20 12:30:56 by adjoly ### ########.fr */ /* Updated: 2024/06/29 15:32:44 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,6 +26,7 @@ t_cmd *get_redir_fd(void *content, t_env *env)
t_redirection_sign in; t_redirection_sign in;
t_cmd *cmd; t_cmd *cmd;
(void)env;
token = (t_token *)content; token = (t_token *)content;
tmp = token->redirection; tmp = token->redirection;
cmd = NULL; cmd = NULL;
@ -69,7 +70,7 @@ t_cmd *get_redir_fd(void *content, t_env *env)
cmd->infile = STDIN_FILENO; cmd->infile = STDIN_FILENO;
if (out == INFILE) if (out == INFILE)
cmd->outfile = STDOUT_FILENO; cmd->outfile = STDOUT_FILENO;
char *ll = env_var_replace(token->argv, env); // char *ll = env_var_replace(token->argv, env);
cmd = split_cmd(ll, cmd); cmd = split_cmd(token->argv, cmd);
return (cmd); return (cmd);
} }

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/06/24 12:50:58 by adjoly ### ########.fr */ /* Updated: 2024/06/29 13:32:54 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,15 +14,6 @@
#include "libft.h" #include "libft.h"
#include <stdio.h> #include <stdio.h>
t_quote __is_quote(char c)
{
if (c == SINGLE)
return (SINGLE);
if (c == DOUBLE)
return (DOUBLE);
return (FALSE);
}
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;

22
src/parsing/is_quote.c Normal file
View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* is_quote.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/29 13:32:35 by adjoly #+# #+# */
/* Updated: 2024/06/29 13:32:50 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "parsing.h"
t_quote __is_quote(char c)
{
if (c == SINGLE)
return (SINGLE);
if (c == DOUBLE)
return (DOUBLE);
return (FALSE);
}

View File

@ -6,52 +6,75 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/05 13:48:57 by adjoly #+# #+# */ /* Created: 2024/06/05 13:48:57 by adjoly #+# #+# */
/* Updated: 2024/06/10 16:29:12 by adjoly ### ########.fr */ /* Updated: 2024/06/29 15:29:48 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libft.h" #include "libft.h"
#include "parsing.h" #include "parsing.h"
#include <stdio.h>
/*char *end_of_arg(char *readline) size_t __get_len_arg(char *s)
{ {
char *tmp; char *tmp;
tmp = readline; if (*s == SINGLE || *s == DOUBLE)
while (*tmp) return (search_for_next_quote((s + 1), __is_quote(*s)) - s + 1);
{ tmp = s;
if (*tmp == 32 && is_inquote(readline, tmp - readline)) while (*tmp && *tmp != ' ')
break ;
tmp++; tmp++;
} return (tmp - s);
return (tmp);
} }
size_t count_args(char *readline) size_t __cpy_arg(char *dst, char *src)
{ {
size_t sizeof_arg;
sizeof_arg = __get_len_arg(src);
ft_strlcpy(dst, src, sizeof_arg + 1);
return (sizeof_arg);
}
size_t __count_args(char *s)
{
size_t i;
char *tmp; char *tmp;
tmp = readline; tmp = s;
i = 0;
while (*tmp) while (*tmp)
{ {
if (*tmp == ' ')
tmp++; tmp++;
else
{
tmp += __get_len_arg(tmp);
i++;
}
} }
return (i);
} }
char **split_argv(char *readline) char **split_argv(char *readline)
{ {
char *tmp;
char **argv; char **argv;
char **tmp_av;
char *tmp;
tmp = readline; tmp = readline;
ft_putnbr_fd(count_args(readline), STDOUT_FILENO); argv = ft_calloc(__count_args(readline) + 1, sizeof(char *));
argv = ft_calloc(count_args(readline), sizof(char *)); tmp_av = argv;
while (*tmp) while (*tmp)
{ {
if (*tmp == ' ')
tmp++; tmp++;
else
{
*tmp_av = ft_calloc(__get_len_arg(tmp), sizeof(char));
tmp += __cpy_arg(*tmp_av, tmp);
tmp_av++;
}
} }
*tmp_av = NULL;
return (argv); return (argv);
} }
*/

View File

@ -6,7 +6,7 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */ /* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 15:00:32 by adjoly #+# #+# */ /* Created: 2024/05/04 15:00:32 by adjoly #+# #+# */
/* Updated: 2024/06/18 12:56:43 by adjoly ### ########.fr */ /* Updated: 2024/06/29 15:30:47 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,7 @@ t_cmd *split_cmd(char *cmd_av, t_cmd *cmd)
{ {
char **split; char **split;
split = ft_split(cmd_av, ' '); split = split_argv(cmd_av);
cmd->cmd = ft_strdup(*split); cmd->cmd = ft_strdup(*split);
cmd->argv = split; cmd->argv = split;
return (cmd); return (cmd);