minishell BATCH MODE
This commit is contained in:
parent
a29defbc65
commit
cfcd59acbd
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ obj/
|
||||
.ms_heredoc
|
||||
pipetester.c
|
||||
pipetest
|
||||
*.txt
|
||||
|
||||
93
src/main.c
93
src/main.c
@ -6,7 +6,7 @@
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ */
|
||||
/* +#+ */
|
||||
/* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */
|
||||
/* Updated: 2025/02/19 17:59:24 by whaffman ######## odam.nl */
|
||||
/* Updated: 2025/02/28 15:25:57 by whaffman ######## odam.nl */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,17 +14,37 @@
|
||||
#include "minishell.h"
|
||||
#include "utils.h"
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
t_minishell *msh;
|
||||
// int main(int argc, char **argv, char **envp)
|
||||
// {
|
||||
// t_minishell *msh;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
print_banner();
|
||||
history_load();
|
||||
msh = init_minishell();
|
||||
signal_init_minishell();
|
||||
environment_parse(msh, envp);
|
||||
// (void)argc;
|
||||
// (void)argv;
|
||||
// print_banner();
|
||||
// history_load();
|
||||
// msh = init_minishell();
|
||||
// signal_init_minishell();
|
||||
// environment_parse(msh, envp);
|
||||
// while (TRUE)
|
||||
// {
|
||||
// msh->line = ft_prompt(msh);
|
||||
// if (msh->line == NULL)
|
||||
// break ;
|
||||
// msh->lexer = ft_lexer_new(msh);
|
||||
// msh->tokens = ft_parse_input(msh);
|
||||
// ft_lstiter(msh->tokens, token_print);
|
||||
// msh->commands = parser_get_commands(msh);
|
||||
// simple_builtins(msh);
|
||||
// free_minishell_line(msh);
|
||||
// }
|
||||
// ft_lstclear_safe(msh, &msh->commands, free_command_list);
|
||||
// free_minishell(&msh);
|
||||
// rl_clear_history();
|
||||
// return (EXIT_SUCCESS);
|
||||
// }
|
||||
|
||||
static void main_loop(t_minishell *msh)
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
msh->line = ft_prompt(msh);
|
||||
@ -37,8 +57,57 @@ int main(int argc, char **argv, char **envp)
|
||||
simple_builtins(msh);
|
||||
free_minishell_line(msh);
|
||||
}
|
||||
ft_lstclear_safe(msh, &msh->commands, free_command_list);
|
||||
}
|
||||
static void main_loop_from_file(t_minishell *msh, char *file_in, char *file_out)
|
||||
{
|
||||
int fd_in;
|
||||
int fd_out;
|
||||
|
||||
fd_in = open(file_in, O_RDONLY);
|
||||
if (fd_in < 0)
|
||||
{
|
||||
error_msg("open", file_in);
|
||||
return ;
|
||||
}
|
||||
fd_out = open(file_out, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (fd_out < 0)
|
||||
{
|
||||
error_msg("open", file_out);
|
||||
close(fd_in);
|
||||
return ;
|
||||
}
|
||||
dup2(fd_out, STDOUT_FILENO);
|
||||
close(fd_out);
|
||||
while (TRUE)
|
||||
{
|
||||
msh->line = get_next_line(fd_in);
|
||||
if (msh->line == NULL)
|
||||
break ;
|
||||
msh->lexer = ft_lexer_new(msh);
|
||||
msh->tokens = ft_parse_input(msh);
|
||||
msh->commands = parser_get_commands(msh);
|
||||
simple_builtins(msh);
|
||||
free_minishell_line(msh);
|
||||
}
|
||||
close(fd_in);
|
||||
close(STDOUT_FILENO);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv, char **envp)
|
||||
{
|
||||
t_minishell *msh;
|
||||
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
print_banner();
|
||||
history_load();
|
||||
msh = init_minishell();
|
||||
signal_init_minishell();
|
||||
environment_parse(msh, envp);
|
||||
// main_loop(msh);
|
||||
main_loop_from_file(msh, argv[1], argv[2]);
|
||||
free_minishell(&msh);
|
||||
rl_clear_history();
|
||||
return (EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user