diff --git a/include/parsing.h b/include/parsing.h index 26b3eef..47f2f1e 100644 --- a/include/parsing.h +++ b/include/parsing.h @@ -6,7 +6,7 @@ /* 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 strlen_till_char(char *s, int c); 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 * command it self diff --git a/src/main.c b/src/main.c index c350b17..39a6579 100644 --- a/src/main.c +++ b/src/main.c @@ -6,10 +6,11 @@ /* By: mmoussou #include #include #include @@ -73,6 +74,8 @@ void sigggg(int code) void siggg_backslash(int code) { (void)code; + rl_replace_line("", 0); + rl_redisplay(); } void siggg_d(int code) @@ -95,6 +98,7 @@ int main(int ac, char **av, char **env) piped = NULL; if (env_init(env, &env_l)) return (EXIT_FAILURE); + sigemptyset(&(sigset_t){SIGQUIT}); signal(SIGINT, &sigggg); signal(SIGQUIT, &siggg_backslash); signal(SIGSEGV, &siggg_d); @@ -126,10 +130,10 @@ int main(int ac, char **av, char **env) continue ; } else if (is_str(test, "exit")) - ; + exit(EXIT_SUCCESS); check_quote(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); exec_split_cmd(cmd_list, &env_l); free(test); diff --git a/src/parsing/get_redir_fd.c b/src/parsing/get_redir_fd.c index 5027921..cc73a5d 100644 --- a/src/parsing/get_redir_fd.c +++ b/src/parsing/get_redir_fd.c @@ -6,7 +6,7 @@ /* 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_cmd *cmd; + (void)env; token = (t_token *)content; tmp = token->redirection; cmd = NULL; @@ -69,7 +70,7 @@ t_cmd *get_redir_fd(void *content, t_env *env) cmd->infile = STDIN_FILENO; if (out == INFILE) cmd->outfile = STDOUT_FILENO; - char *ll = env_var_replace(token->argv, env); - cmd = split_cmd(ll, cmd); +// char *ll = env_var_replace(token->argv, env); + cmd = split_cmd(token->argv, cmd); return (cmd); } diff --git a/src/parsing/is_inquote.c b/src/parsing/is_inquote.c index 95ad475..953d02c 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/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 -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 *tmp; diff --git a/src/parsing/is_quote.c b/src/parsing/is_quote.c new file mode 100644 index 0000000..eace2bd --- /dev/null +++ b/src/parsing/is_quote.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* is_quote.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/src/parsing/split_argv.c b/src/parsing/split_argv.c index 682434a..03108fe 100644 --- a/src/parsing/split_argv.c +++ b/src/parsing/split_argv.c @@ -6,52 +6,75 @@ /* 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 "parsing.h" +#include -/*char *end_of_arg(char *readline) +size_t __get_len_arg(char *s) { char *tmp; - - tmp = readline; - while (*tmp) - { - if (*tmp == 32 && is_inquote(readline, tmp - readline)) - break ; + + if (*s == SINGLE || *s == DOUBLE) + return (search_for_next_quote((s + 1), __is_quote(*s)) - s + 1); + tmp = s; + while (*tmp && *tmp != ' ') tmp++; - } - return (tmp); + return (tmp - s); } -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; - tmp = readline; + tmp = s; + i = 0; while (*tmp) { - - tmp++; + if (*tmp == ' ') + tmp++; + else + { + tmp += __get_len_arg(tmp); + i++; + } } + return (i); } char **split_argv(char *readline) { - char *tmp; char **argv; + char **tmp_av; + char *tmp; tmp = readline; - ft_putnbr_fd(count_args(readline), STDOUT_FILENO); - argv = ft_calloc(count_args(readline), sizof(char *)); + argv = ft_calloc(__count_args(readline) + 1, sizeof(char *)); + tmp_av = argv; while (*tmp) { - - tmp++; + if (*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); } -*/ diff --git a/src/parsing/split_cmd.c b/src/parsing/split_cmd.c index 7dac039..b4a0122 100644 --- a/src/parsing/split_cmd.c +++ b/src/parsing/split_cmd.c @@ -6,7 +6,7 @@ /* By: mmoussou cmd = ft_strdup(*split); cmd->argv = split; return (cmd);