」 feat: Parsing working but not handling error

This commit is contained in:
2024-05-31 19:26:09 +02:00
parent 6bbdef9d7c
commit 5a71c50897
7 changed files with 57 additions and 32 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/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 send_error(char *msg, char **argv);
void check_redir(t_list *redir, char **argv); void check_redir(t_list *redir, char **argv);
t_cmd *get_redir_fd(void *content); 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 * @brief Take the argv of a command a split the argv and the
* command it self * command it self
@ -44,7 +45,7 @@ t_cmd *get_redir_fd(void *content);
* *
* @return (t_cmd *) cmd and argv splited into a struct * @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 * @brief Take a string and an index and check if the character

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/05/30 16:37:57 by adjoly ### ########.fr */ /* Updated: 2024/05/31 13:29:26 by adjoly ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -62,18 +62,16 @@ void print_pipe(t_list *pipe)
int main(int ac, char **av, char **env) int main(int ac, char **av, char **env)
{ {
//ft_heredoc("EOF");
char *test; char *test;
char *prompt; char *prompt;
char **lll; char **lll;
t_list *piped; t_list *piped;
t_env env_l; t_env env_l;
t_cmd *cmd; t_cmd *cmd;
//t_token *token; t_list *cmd_list;
(void)ac; (void)ac;
(void)av; (void)av;
(void)env;
piped = NULL; piped = NULL;
if (env_init(env, &env_l)) if (env_init(env, &env_l))
return (EXIT_FAILURE); return (EXIT_FAILURE);
@ -90,13 +88,13 @@ int main(int ac, char **av, char **env)
if (is_str(test, "exit")) if (is_str(test, "exit"))
break ; break ;
piped = tokenizer(test); piped = tokenizer(test);
// check_redir(((t_token *)(piped->content))->redirection, av); check_redir(((t_token *)(piped->content))->redirection, av);
/* while (piped) cmd_list = get_cmd_list(piped);
while (cmd_list)
{ {
print_token(piped->content); cmd = cmd_list->content;
piped = piped->next; cmd_list = cmd_list->next;
}*/ }
cmd = get_redir_fd(piped->content);
print_cmd(cmd); print_cmd(cmd);
free(test); free(test);
ft_lstclear(&piped, free_token); ft_lstclear(&piped, free_token);

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_cmd_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

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/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.sign = INFILE;
in.file_name = tmp_redir->file_name; in.file_name = tmp_redir->file_name;
} }
else else if (tmp_redir->sign == OUTFILE)
{ cmd->outfile = open(tmp_redir->file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
out.sign = tmp_redir->sign; else if (tmp_redir->sign == OUT_APPEND)
out.file_name = tmp_redir->file_name; cmd->outfile = open(tmp_redir->file_name, O_CREAT | O_APPEND | O_WRONLY, 0644);
}
tmp = tmp->next; tmp = tmp->next;
} }
if (in.sign == OUTFILE) if (in.sign == OUTFILE)
@ -62,9 +61,6 @@ t_cmd *get_redir_fd(void *content)
} }
if (out.sign == INFILE) if (out.sign == INFILE)
cmd->outfile = STDOUT_FILENO; cmd->outfile = STDOUT_FILENO;
else if (out.sign == OUTFILE) cmd = split_cmd(token->argv, cmd);
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);
return (cmd); return (cmd);
} }

View File

@ -6,23 +6,24 @@
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/04 15:00:32 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 "parsing.h"
#include "libft.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 **split;
char **tmp_split;
t_cmd *cmd;
split = ft_split(cmd_av, 32); tmp = cmd_av;
tmp_split = split; split = ft_split(cmd_av, ' ');
cmd = ft_calloc(sizeof(t_cmd), 1); cmd->cmd = ft_strdup(*split);
cmd->cmd = ft_strdup(*tmp_split); ft_free("a", &split);
cmd->argv = tmp_split; while (*tmp && *tmp == ' ')
tmp++;
cmd->argv = ft_strdup(tmp);
return (cmd); return (cmd);
}*/ }