mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「✨」 feat: Parsing working but not handling error
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
|
18
src/main.c
18
src/main.c
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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)
|
||||
{
|
||||
//ft_heredoc("EOF");
|
||||
char *test;
|
||||
char *prompt;
|
||||
char **lll;
|
||||
t_list *piped;
|
||||
t_env env_l;
|
||||
t_cmd *cmd;
|
||||
//t_token *token;
|
||||
t_list *cmd_list;
|
||||
|
||||
(void)ac;
|
||||
(void)av;
|
||||
(void)env;
|
||||
piped = NULL;
|
||||
if (env_init(env, &env_l))
|
||||
return (EXIT_FAILURE);
|
||||
@ -90,13 +88,13 @@ int main(int ac, char **av, char **env)
|
||||
if (is_str(test, "exit"))
|
||||
break ;
|
||||
piped = tokenizer(test);
|
||||
// check_redir(((t_token *)(piped->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);
|
||||
|
29
src/parsing/get_cmd_list.c
Normal file
29
src/parsing/get_cmd_list.c
Normal 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);
|
||||
}
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
@ -6,23 +6,24 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}*/
|
||||
}
|
||||
|
Reference in New Issue
Block a user