diff --git a/include/parsing.h b/include/parsing.h index f53b9b3..3467091 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/05/30 16:31:48 by adjoly ### ########.fr */ +/* Updated: 2024/05/31 13:17:38 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,7 @@ void check_syntax(char *readline, char **argv); void send_error(char *msg, char **argv); void check_redir(t_list *redir, char **argv); t_cmd *get_redir_fd(void *content); +t_list *get_cmd_list(t_list *list); /** * @brief Take the argv of a command a split the argv and the * command it self @@ -44,7 +45,7 @@ t_cmd *get_redir_fd(void *content); * * @return (t_cmd *) cmd and argv splited into a struct */ -t_cmd *split_cmd(char *cmd_av); +t_cmd *split_cmd(char *cmd_av, t_cmd *cmd); /** * @brief Take a string and an index and check if the character diff --git a/src/main.c b/src/main.c index 3f1e097..9a8bc0c 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: mmoussou content))->redirection, av); -/* while (piped) + check_redir(((t_token *)(piped->content))->redirection, av); + cmd_list = get_cmd_list(piped); + while (cmd_list) { - print_token(piped->content); - piped = piped->next; - }*/ - cmd = get_redir_fd(piped->content); + cmd = cmd_list->content; + cmd_list = cmd_list->next; + } print_cmd(cmd); free(test); ft_lstclear(&piped, free_token); diff --git a/src/parsing/get_cmd_list.c b/src/parsing/get_cmd_list.c new file mode 100644 index 0000000..6665a94 --- /dev/null +++ b/src/parsing/get_cmd_list.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_cmd_list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/31 12:47:13 by adjoly #+# #+# */ +/* Updated: 2024/05/31 13:29:46 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" +#include "parsing.h" + +t_list *get_cmd_list(t_list *list) +{ + t_list *tmp; + t_list *cmd_list; + + tmp = list; + cmd_list = NULL; + while (tmp) + { + ft_lstadd_back(&cmd_list, ft_lstnew(get_redir_fd(tmp->content))); + tmp = tmp->next; + } + return (cmd_list); +} diff --git a/src/parsing/get_infile.c b/src/parsing/get_infile.c deleted file mode 100644 index e69de29..0000000 diff --git a/src/parsing/get_outfile.c b/src/parsing/get_outfile.c deleted file mode 100644 index e69de29..0000000 diff --git a/src/parsing/get_redir_fd.c b/src/parsing/get_redir_fd.c index 9e35851..c47124e 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/05/30 17:47:43 by adjoly ### ########.fr */ +/* Updated: 2024/05/31 19:16:41 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -46,11 +46,10 @@ t_cmd *get_redir_fd(void *content) in.sign = INFILE; in.file_name = tmp_redir->file_name; } - else - { - out.sign = tmp_redir->sign; - out.file_name = tmp_redir->file_name; - } + else if (tmp_redir->sign == OUTFILE) + cmd->outfile = open(tmp_redir->file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644); + else if (tmp_redir->sign == OUT_APPEND) + cmd->outfile = open(tmp_redir->file_name, O_CREAT | O_APPEND | O_WRONLY, 0644); tmp = tmp->next; } if (in.sign == OUTFILE) @@ -62,9 +61,6 @@ t_cmd *get_redir_fd(void *content) } if (out.sign == INFILE) cmd->outfile = STDOUT_FILENO; - else if (out.sign == OUTFILE) - cmd->outfile = open(out.file_name, O_CREAT | O_TRUNC | O_WRONLY); - else if (out.sign == OUT_APPEND) - cmd->outfile = open(out.file_name, O_CREAT | O_APPEND | O_WRONLY); + cmd = split_cmd(token->argv, cmd); return (cmd); } diff --git a/src/parsing/split_cmd.c b/src/parsing/split_cmd.c index d0d2323..cb754ad 100644 --- a/src/parsing/split_cmd.c +++ b/src/parsing/split_cmd.c @@ -6,23 +6,24 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/04 15:00:32 by adjoly #+# #+# */ -/* Updated: 2024/05/30 16:31:04 by adjoly ### ########.fr */ +/* Updated: 2024/05/31 12:57:18 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "parsing.h" #include "libft.h" -/*t_cmd *split_cmd(char *cmd_av) +t_cmd *split_cmd(char *cmd_av, t_cmd *cmd) { + char *tmp; char **split; - char **tmp_split; - t_cmd *cmd; - split = ft_split(cmd_av, 32); - tmp_split = split; - cmd = ft_calloc(sizeof(t_cmd), 1); - cmd->cmd = ft_strdup(*tmp_split); - cmd->argv = tmp_split; + tmp = cmd_av; + split = ft_split(cmd_av, ' '); + cmd->cmd = ft_strdup(*split); + ft_free("a", &split); + while (*tmp && *tmp == ' ') + tmp++; + cmd->argv = ft_strdup(tmp); return (cmd); -}*/ +}