processing heredocs
This commit is contained in:
parent
873d6b48fc
commit
e0e77f4012
10
.vscode/settings.json
vendored
10
.vscode/settings.json
vendored
@ -1,6 +1,14 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"minishell.h": "c",
|
||||
"signal.h": "c"
|
||||
"signal.h": "c",
|
||||
"optional": "c",
|
||||
"ostream": "c",
|
||||
"system_error": "c",
|
||||
"array": "c",
|
||||
"functional": "c",
|
||||
"tuple": "c",
|
||||
"type_traits": "c",
|
||||
"utility": "c"
|
||||
}
|
||||
}
|
||||
|
||||
43
sources.mk
43
sources.mk
@ -1,22 +1,23 @@
|
||||
VPATH = src:src/prompt:src/utils:src/lexer:src/token:src/environment:src/executor:src/parser:src/signal:src/debug:src/expander:src/builtin:src/redirect:
|
||||
SOURCES = history_load.c history_write.c prompt.c ft_lstclear_safe.c \
|
||||
ft_lstnew_safe.c ft_strdup_safe.c ft_strjoin_safe.c init_minishell.c \
|
||||
malloc_safe.c print_banner.c error_msg.c check_malloc.c \
|
||||
free_command_list.c free_freelist.c free_lexer.c free_minishell.c \
|
||||
free_minishell_line.c free_safe.c free_token.c free_token_list.c \
|
||||
lexer_read_char.c lexer_new.c lexer_parse_input.c lexer_read_word.c \
|
||||
lexer_token_next.c token_new.c token_parse.c environment_add.c \
|
||||
environment_del.c environment_free.c environment_free_list.c \
|
||||
environment_get.c environment_get_arr.c environment_parse.c \
|
||||
environment_print.c executor_close_fds.c executor_absolute_path.c \
|
||||
executor_child.c executor_count_fds.c executor_create_pipes.c \
|
||||
executor_create_redirects.c executor_execute_pipeline.c \
|
||||
executor_fork.c executor_open_fds.c parser_get_arguments.c \
|
||||
parser_get_commands.c parser_new_command.c signal.c print_commands.c \
|
||||
print_freelist.c expander_expand_dollar.c expander_is_character.c \
|
||||
expander_allocate_memory.c expander_get_variable.c \
|
||||
expander_parse_string.c expander_parse_variables.c builtin_echo.c \
|
||||
builtin_router.c simple_builtins.c is_builtin.c builtin_cd.c \
|
||||
builtin_env.c builtin_exit.c builtin_export.c builtin_pwd.c \
|
||||
builtin_unset.c redirect_valid_type.c redirect_get_inputs.c \
|
||||
VPATH = src:src/prompt:src/utils:src/lexer:src/token:src/environment:src/executor:src/parser:src/debug:src/expander:src/builtin:src/signal:src/redirect:
|
||||
SOURCES = history_load.c history_write.c prompt.c error_msg.c \
|
||||
ft_lstclear_safe.c ft_lstnew_safe.c ft_strdup_safe.c \
|
||||
ft_strjoin_safe.c init_minishell.c malloc_safe.c print_banner.c \
|
||||
check_malloc.c free_command_list.c free_freelist.c free_lexer.c \
|
||||
free_minishell.c free_minishell_line.c free_safe.c free_token.c \
|
||||
free_token_list.c lexer_read_char.c lexer_new.c lexer_parse_input.c \
|
||||
lexer_read_word.c lexer_token_next.c token_new.c token_parse.c \
|
||||
environment_add.c environment_del.c environment_free.c \
|
||||
environment_free_list.c environment_get.c environment_get_arr.c \
|
||||
environment_parse.c environment_print.c executor_close_fds.c \
|
||||
executor_absolute_path.c executor_child.c executor_count_fds.c \
|
||||
executor_create_pipes.c executor_create_redirects.c \
|
||||
executor_execute_pipeline.c executor_fork.c executor_open_fds.c \
|
||||
parser_get_arguments.c parser_get_commands.c parser_new_command.c \
|
||||
print_commands.c print_freelist.c expander_is_character.c \
|
||||
expander_expand_dollar.c expander_allocate_memory.c \
|
||||
expander_get_variable.c expander_parse_string.c \
|
||||
expander_parse_variables.c builtin_echo.c builtin_router.c \
|
||||
simple_builtins.c is_builtin.c builtin_cd.c builtin_env.c \
|
||||
builtin_exit.c builtin_export.c builtin_pwd.c builtin_unset.c \
|
||||
signal.c redirect_valid_type.c redirect_get_inputs.c \
|
||||
redirect_get_outputs.c redirect_new.c main.c \
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* builtin_pwd.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* ::: :::::::: */
|
||||
/* builtin_pwd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/20 11:32:28 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/25 15:17:51 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/25 20:07:22 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* :::::::: */
|
||||
/* parser_get_arguments.c :+: :+: */
|
||||
/* +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* ::: :::::::: */
|
||||
/* parser_get_arguments.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: qmennen <qmennen@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/11 16:20:09 by qmennen #+# #+# */
|
||||
/* Updated: 2025/02/25 16:40:26 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/25 20:14:18 by qmennen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -56,9 +56,7 @@ char **parser_get_arguments(t_list *list, t_minishell *minishell)
|
||||
while ((++i) < cmds && current)
|
||||
{
|
||||
if (parser_should_expand(current))
|
||||
{
|
||||
args[i] = expander_parse_string(((t_token *)current->content)->value, minishell);
|
||||
}
|
||||
else if (((t_token *)current->content)->type == T_WORD ||
|
||||
((t_token *)current->content)->type == T_SQWORD)
|
||||
args[i] = ft_strdup_safe(minishell, ((t_token *)current->content)->value);
|
||||
|
||||
@ -12,6 +12,31 @@
|
||||
|
||||
#include "redirect.h"
|
||||
|
||||
static void process_heredoc(t_minishell *ms, t_token *heredoc, t_token *delim)
|
||||
{
|
||||
char *line;
|
||||
int fd;
|
||||
|
||||
fd = open(".ms_heredoc", O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (fd < 0)
|
||||
return ;
|
||||
|
||||
|
||||
while (TRUE)
|
||||
{
|
||||
line = readline("heredoc>");
|
||||
if ((*line && ft_strcmp(line, delim->value) == 0) || !line)
|
||||
break ;
|
||||
if (!*line)
|
||||
ft_putendl_fd("", fd);
|
||||
else
|
||||
ft_putendl_fd(line, fd);
|
||||
}
|
||||
close(fd);
|
||||
heredoc->type = T_REDIRECT_IN;
|
||||
delim->value = ft_strdup_safe(ms, ".ms_heredoc");
|
||||
}
|
||||
|
||||
t_list *redirect_get_inputs(t_minishell *minishell, t_list *list)
|
||||
{
|
||||
t_list *current;
|
||||
@ -30,9 +55,11 @@ t_list *redirect_get_inputs(t_minishell *minishell, t_list *list)
|
||||
current = current->next;
|
||||
continue ;
|
||||
}
|
||||
if (token->type == T_HEREDOC && redirect_is_valid(current, token))
|
||||
process_heredoc(minishell, token, current->next->content);
|
||||
if (redirect_is_valid(current, token))
|
||||
{
|
||||
ft_lstadd_front(&redirects, ft_lstnew_safe(minishell,
|
||||
ft_lstadd_back(&redirects, ft_lstnew_safe(minishell,
|
||||
redirect_new(minishell, token->type,
|
||||
ft_strdup_safe(minishell,
|
||||
((t_token *)current->next->content)->value))));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user