From 8bd58675e98d81ab0d643e19b336017b27e02119 Mon Sep 17 00:00:00 2001 From: Etienne Rey-bethbeder Date: Fri, 17 Feb 2023 16:54:58 +0100 Subject: [PATCH] Ajout Pwd et dans le .h --- Makefile | 2 +- echo.c | 5 +++-- minishell.h | 17 +++++++++++++---- pwd.c | 26 ++++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) create mode 100644 pwd.c diff --git a/Makefile b/Makefile index a483424..c35c260 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ UTILS_SRC = utils/ft_is_in_quote.c utils/ft_strncpy.c utils/ft_strreplace.c utils/ft_strnchr.c utils/ft_split_quoted.c utils/ft_strshift.c utils/ft_quote_remover.c utils/ft_str_is_empty.c -SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c execution.c spacer.c env_fill.c +SRCS = ${UTILS_SRC} main.c file.c infile.c outfile.c heredoc.c syntatics.c cmd.c cmds.c env.c execution.c spacer.c env_fill.c echo.c pwd.c OBJS = ${SRCS:.c=.o} diff --git a/echo.c b/echo.c index 8dfdc5f..0b98c2c 100644 --- a/echo.c +++ b/echo.c @@ -6,7 +6,7 @@ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/02/17 13:09:08 by erey-bet #+# #+# */ -/* Updated: 2023/02/17 16:03:06 by erey-bet ### ########.fr */ +/* Updated: 2023/02/17 16:53:04 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,7 +45,7 @@ int check_argument(char *str, int *check, int i) return (i); } -void echo(int fd, char *str) +int echo(int fd, char *str) { int check; int i; @@ -59,4 +59,5 @@ void echo(int fd, char *str) ft_putchar_fd(fd, str[i++]); if (!check) write(fd, "\n", 1); + return (0); } diff --git a/minishell.h b/minishell.h index 1f8cd51..7c67f58 100644 --- a/minishell.h +++ b/minishell.h @@ -6,7 +6,7 @@ /* By: cchauvet # include # define DEBUG 0 -t_list **init_env(char **env); -int set_value_by_key(char *key, char *value, t_list **env); -char *get_value_by_key(char *key, t_list **head); int ft_syntatic_verif(const char *str); int ft_file_is_readable(const char *path); int ft_file_is_writable(const char *path); @@ -44,6 +41,18 @@ char *ft_normalizer(char *str); char *ft_env_filler(t_list **env, const char *str); char **env_to_strs(t_list **head); +/* Environnement */ +t_list **init_env(char **env); +char **env_to_strs(t_list **head); +int create_value_by_key(char *key, char *value, t_list **head); +int set_value_by_key(char *key, char *value, t_list **head); +char *get_value_by_key(char *key, t_list **head); + +/* Echo */ +int echo(int fd, char *str); +/* PWD */ +int pwd(t_list **env, int fd); + typedef struct s_cmd { int fd_in; diff --git a/pwd.c b/pwd.c new file mode 100644 index 0000000..524ce56 --- /dev/null +++ b/pwd.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pwd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: erey-bet +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */ +/* Updated: 2023/02/17 16:53:36 by erey-bet ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int pwd(t_list **env, int fd) +{ + ft_putstr_fd(get_value_by_key("PWD", env), fd); + write(fd, "\n", 1); + return (0); +} + +int main(int argc, char *argv[], char **env) +{ + pwd(init_env(env), 1); + return (0); +}