diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-19 22:27:11 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-19 22:27:11 +0200 |
commit | 62afe606a355581c5b48cca361478c43fb6ae4cf (patch) | |
tree | a278fe2fdf44c296892616554743b9d380ff7afa /src | |
parent | Added joe-sh_history to gitignore (diff) | |
download | 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.tar.gz 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.tar.bz2 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.tar.xz 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.tar.zst 42-minishell-62afe606a355581c5b48cca361478c43fb6ae4cf.zip |
Well well well that wasn't too bad, now remake everything
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_echo.c | 8 | ||||
-rw-r--r-- | src/ft_exec.c | 16 | ||||
-rw-r--r-- | src/ft_exit.c | 1 | ||||
-rw-r--r-- | src/main.c | 19 |
4 files changed, 26 insertions, 18 deletions
diff --git a/src/ft_echo.c b/src/ft_echo.c index 1ca8fc2..e8ef75c 100644 --- a/src/ft_echo.c +++ b/src/ft_echo.c @@ -24,17 +24,17 @@ ft_echo(char **com, uint8_t n) i = 1; fd = 1; if (!com[1]) - ft_putendl_fd("", fd); + ft_dprintf(fd, "\n"); else if (!ft_strncmp(com[1], "-n", ft_strlen(com[1]))) i = 2; while (i < n) { - ft_putstr_fd(ft_strtrim(com[i], "\""), fd); + ft_dprintf(fd, "%s", ft_strtrim(com[i], "\"")); if (i != n - 1) - ft_putchar_fd(' ', fd); + ft_dprintf(fd, " "); i++; } if (ft_strncmp(com[1], "-n", ft_strlen(com[1]))) - ft_putchar_fd('\n', fd); + ft_dprintf(fd, "\n"); return (0); } diff --git a/src/ft_exec.c b/src/ft_exec.c index 555be96..408697d 100644 --- a/src/ft_exec.c +++ b/src/ft_exec.c @@ -12,6 +12,7 @@ /* ************************************************************************** */ #include <libft.h> +#include <stdlib.h> #include <minishell.h> #include <unistd.h> @@ -23,13 +24,16 @@ ft_exec(char **com) i = 0; while (com[i]) i++; - if (!ft_strncmp(com[0], "./", 2)) + if (fork() == 0) { - if ((execve(com[0] + 2, com, NULL)) != 0) - return (ft_error(com[0], 127)); + if (!ft_strncmp(com[0], "./", 2)) + { + if ((execve(com[0] + 2, com, NULL)) != 0) + return (ft_error(com[0], 127)); + } + else + if ((execve(com[0], com, NULL)) != 0) + return (ft_error(com[0], 127)); } - else - if ((execve(com[0], com, NULL)) != 0) - return (ft_error(com[0], 127)); return (0); } diff --git a/src/ft_exit.c b/src/ft_exit.c index 1d84615..5285289 100644 --- a/src/ft_exit.c +++ b/src/ft_exit.c @@ -21,7 +21,6 @@ ft_exit(char **com) uint8_t i; i = 0; - ft_putendl("exit"); while (com[i]) i++; if (i == 2) @@ -15,21 +15,26 @@ #include <minishell.h> #include <stdlib.h> #include <stddef.h> +#include <stdint.h> #include <unistd.h> -#include <inttypes.h> int - main(void) +main(int argc, + const char *argv[], + const char *envp[]) { char *arg; - int gnlret; + int8_t gnlret; - ft_putstr(FT_PS1); - while ((gnlret= get_next_line(STDIN_FILENO, &arg)) > 0) + (void)argc; + (void)argv; + (void)envp; + ft_printf(FT_PS1); + while ((gnlret = get_next_line(STDIN_FILENO, &arg)) > 0) { ft_process_arg(arg); - free(arg); - ft_putstr(FT_PS1); + ft_memdel((void*)&arg); + ft_printf(FT_PS1); } free(arg); return (0); |