diff --git a/Makefile b/Makefile index fecfddc..61635b9 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,7 @@ srcs = \ src/parser/wordsplit/tokenizing_6_10.c \ src/parser/wordsplit/wordsplit.c \ src/parser/wordsplit/wordsplit_utils.c \ + src/postprocess/redirections/redirections.c \ objs = $(srcs:.c=.o) export objs diff --git a/src/parser/simple_cmd/simple_cmd.h b/src/parser/simple_cmd/simple_cmd.h index 7b3f386..cee6bd1 100644 --- a/src/parser/simple_cmd/simple_cmd.h +++ b/src/parser/simple_cmd/simple_cmd.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/21 12:24:57 by khais #+# #+# */ -/* Updated: 2025/02/21 12:48:53 by khais ### ########.fr */ +/* Updated: 2025/03/07 12:29:16 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,12 @@ # define SIMPLE_CMD_H # include "../wordlist/wordlist.h" +# include "../../postprocess/redirections/redirections.h" typedef struct s_simple_cmd { - t_wordlist *words; + t_wordlist *words; + t_redir_list *redirections; } t_simple_cmd; t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words); diff --git a/src/postprocess/redirections/redirections.c b/src/postprocess/redirections/redirections.c new file mode 100644 index 0000000..8538db0 --- /dev/null +++ b/src/postprocess/redirections/redirections.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* redirections.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/07 12:30:04 by khais #+# #+# */ +/* Updated: 2025/03/07 12:32:02 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "redirections.h" +#include + +struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd) +{ + return (cmd); +} diff --git a/src/postprocess/redirections/redirections.h b/src/postprocess/redirections/redirections.h new file mode 100644 index 0000000..7ba777b --- /dev/null +++ b/src/postprocess/redirections/redirections.h @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* redirections.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/07 11:59:31 by khais #+# #+# */ +/* Updated: 2025/03/07 14:23:48 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef REDIRECTIONS_H +# define REDIRECTIONS_H + +# include "../../parser/worddesc/worddesc.h" + +/* +** Type of redirection. +*/ +typedef enum e_redirection_type +{ + // Invalid + REDIR_INVALID, + // < + REDIR_INPUT, + // > + REDIR_OUTPUT, + // << + REDIR_HERE_DOC, + // >> + REDIR_APPEND, +} t_redir_type; + +typedef struct s_redirection +{ + // type of this redirection + t_redir_type type; + // either the filepath to the given file, or the delimiter for a here_doc + // redirection + t_worddesc *marker; +} t_redirection; + +typedef struct s_redirection_list +{ + t_redirection *redirection; + struct s_redirection_list *next; +} t_redir_list; + +struct s_simple_cmd; + +struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd); + +#endif // REDIRECTIONS_H diff --git a/tests/Makefile b/tests/Makefile index ec4c042..8eb475e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,7 @@ # make gets confused if a file with the same name exists in the sources, so some # file are prefixed with test_ rawtests = \ + test_redirection_parsing \ quote_removal \ cmdlist_use_after_free \ metacharacters \ diff --git a/tests/parse_simple_cmds.c b/tests/parse_simple_cmds.c index 8a08f64..567f61e 100644 --- a/tests/parse_simple_cmds.c +++ b/tests/parse_simple_cmds.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/21 12:20:20 by khais #+# #+# */ -/* Updated: 2025/02/21 12:49:55 by khais ### ########.fr */ +/* Updated: 2025/03/07 12:32:04 by khais ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/tests/test_redirection_parsing.c b/tests/test_redirection_parsing.c new file mode 100644 index 0000000..ea76762 --- /dev/null +++ b/tests/test_redirection_parsing.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test_redirection_parsing.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/03/07 11:55:37 by khais #+# #+# */ +/* Updated: 2025/03/07 12:00:13 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "../src/parser/simple_cmd/simple_cmd.h" +#include "../src/parser/wordsplit/wordsplit.h" +#include "../src/postprocess/redirections/redirections.h" + +static t_simple_cmd *parse_simple_cmd(char *input) +{ + t_wordlist *words = minishell_wordsplit(input); + t_simple_cmd *cmd = simple_cmd_from_wordlist(words); + return (cmd); +} + +static void test_redirection_parsing_no_redirections(void) +{ + t_simple_cmd *cmd = parse_simple_cmd("echo hello world"); + assert(parse_redirections(cmd) != NULL); + assert(cmd->redirections == NULL); + simple_cmd_destroy(cmd); +} + +int main(void) { + test_redirection_parsing_no_redirections(); + return (0); +}