Skip to content

Commit

Permalink
Fix multiple bugs (minishell with redirections & no command argument …
Browse files Browse the repository at this point in the history
…redirections, >> cat)
  • Loading branch information
arzelcm committed Jun 14, 2024
1 parent 9d18cf5 commit 38c400b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ $(READLINE_DIR):
libft_fclean \
b \

test:
rm -rf 42_minishell_tester-master
rm -rf $(HOME)/42_minishell_tester
curl -sLO https://github.com/zstenger93/42_minishell_tester/archive/refs/heads/master.zip
unzip master.zip > /dev/null
chmod 744 ./42_minishell_tester-master/install.sh
./42_minishell_tester-master/install.sh
./42_minishell_tester-master/tester.sh m

-include $(DEPS)
-include $(MDEPS)
-include $(BDEPS)
Expand Down
2 changes: 2 additions & 0 deletions src/executor/execute_command.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ void execute_command(t_pdata *pdata, t_token *token, t_context *context)
clean_exit(pdata);
redirect_fds(pdata->fds[READ_FD], pdata->fds[WRITE_FD]);
close_pdata_fds(pdata);
if (!token->argc)
exit(EXIT_SUCCESS);
if (is_builtin(token->args[0]))
exit(execute_builtin(token->args[0], token, context));
if (!is_directory(token->args[0]))
Expand Down
2 changes: 1 addition & 1 deletion src/executor/executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void execute(t_token *token, t_context *context)
return (free_pdata(&p_data));
}
config_echoctl_terminal(ON);
if (token->type == CMD && is_builtin(token->args[0]))
if (token->type == CMD && token->argc && is_builtin(token->args[0]))
execute_cmd_builtin(&p_data, token, context);
else if (token->type == CMD || token->type == PIPE)
execute_pipe(&p_data, token, context);
Expand Down
9 changes: 7 additions & 2 deletions src/minishell.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "tokenizer.h"
#include "environment.h"
#include "environment_helper.h"
#include "unistd.h"

int g_sigval;

Expand All @@ -33,12 +34,16 @@ int main(int argc, char **argv, char **envp)
ft_bzero(&context, sizeof(t_context));
ft_bzero(&token, sizeof(t_token *));
init_env(&context, envp);
ft_printf(CREDITS);
if (isatty(STDIN_FILENO))
ft_printf(CREDITS);
while (42)
{
config_echoctl_terminal(OFF);
listen_signals(MAIN, MAIN);
line = readline(PROMPT);
if (isatty(STDIN_FILENO))
line = readline(PROMPT);
else
line = get_next_line(STDIN_FILENO, 0);
if (g_sigval == SIGINT)
{
context.err_code = 1;
Expand Down
2 changes: 2 additions & 0 deletions src/tokenizer/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void set_arg(char *line, int *i, t_token *token, t_context *context)
j = 0;
while (words[j])
push_arg(&token->args, words[j++], &token->argc);
free(words);
free(word);
}
}

Expand Down

0 comments on commit 38c400b

Please sign in to comment.