mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
redirection parsing: handle commands with no redirections
This commit is contained in:
parent
42bccd0a06
commit
06ebcf132a
7 changed files with 116 additions and 3 deletions
1
Makefile
1
Makefile
|
|
@ -50,6 +50,7 @@ srcs = \
|
||||||
src/parser/wordsplit/tokenizing_6_10.c \
|
src/parser/wordsplit/tokenizing_6_10.c \
|
||||||
src/parser/wordsplit/wordsplit.c \
|
src/parser/wordsplit/wordsplit.c \
|
||||||
src/parser/wordsplit/wordsplit_utils.c \
|
src/parser/wordsplit/wordsplit_utils.c \
|
||||||
|
src/postprocess/redirections/redirections.c \
|
||||||
|
|
||||||
objs = $(srcs:.c=.o)
|
objs = $(srcs:.c=.o)
|
||||||
export objs
|
export objs
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/21 12:24:57 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
|
# define SIMPLE_CMD_H
|
||||||
|
|
||||||
# include "../wordlist/wordlist.h"
|
# include "../wordlist/wordlist.h"
|
||||||
|
# include "../../postprocess/redirections/redirections.h"
|
||||||
|
|
||||||
typedef struct s_simple_cmd
|
typedef struct s_simple_cmd
|
||||||
{
|
{
|
||||||
t_wordlist *words;
|
t_wordlist *words;
|
||||||
|
t_redir_list *redirections;
|
||||||
} t_simple_cmd;
|
} t_simple_cmd;
|
||||||
|
|
||||||
t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words);
|
t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words);
|
||||||
|
|
|
||||||
19
src/postprocess/redirections/redirections.c
Normal file
19
src/postprocess/redirections/redirections.c
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirections.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/07 12:30:04 by khais #+# #+# */
|
||||||
|
/* Updated: 2025/03/07 12:32:02 by khais ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "redirections.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
struct s_simple_cmd *parse_redirections(struct s_simple_cmd *cmd)
|
||||||
|
{
|
||||||
|
return (cmd);
|
||||||
|
}
|
||||||
54
src/postprocess/redirections/redirections.h
Normal file
54
src/postprocess/redirections/redirections.h
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redirections.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* 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
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
# make gets confused if a file with the same name exists in the sources, so some
|
# make gets confused if a file with the same name exists in the sources, so some
|
||||||
# file are prefixed with test_
|
# file are prefixed with test_
|
||||||
rawtests = \
|
rawtests = \
|
||||||
|
test_redirection_parsing \
|
||||||
quote_removal \
|
quote_removal \
|
||||||
cmdlist_use_after_free \
|
cmdlist_use_after_free \
|
||||||
metacharacters \
|
metacharacters \
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/21 12:20:20 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
36
tests/test_redirection_parsing.c
Normal file
36
tests/test_redirection_parsing.c
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* test_redirection_parsing.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/03/07 11:55:37 by khais #+# #+# */
|
||||||
|
/* Updated: 2025/03/07 12:00:13 by khais ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#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);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue