From de6bb00acf0ebc93cbff85a95c3e508dd5512e29 Mon Sep 17 00:00:00 2001 From: whaffman Date: Tue, 4 Feb 2025 16:42:55 +0100 Subject: [PATCH] added prompt header and made main --- Makefile | 4 ++-- inc/enviroment.h | 31 ++++++++++++++++++++++--------- inc/minishell.h | 5 ++++- inc/prompt.h | 18 ++++++++++++++++++ src/enviroment/parse_enviroment.c | 19 +++++++++++++++++++ src/main.c | 26 ++++++++++++++++++++++++++ src/prompt/load_history.c | 0 src/{ => prompt}/prompt.c | 28 ++++++---------------------- 8 files changed, 97 insertions(+), 34 deletions(-) create mode 100644 inc/prompt.h create mode 100644 src/enviroment/parse_enviroment.c create mode 100644 src/main.c create mode 100644 src/prompt/load_history.c rename src/{ => prompt}/prompt.c (68%) diff --git a/Makefile b/Makefile index b8c5cb7..aa15911 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: whaffman +#+ # # +#+ # # Created: 2024/10/15 11:48:46 by whaffman #+# #+# # -# Updated: 2025/02/04 16:13:00 by whaffman ######## odam.nl # +# Updated: 2025/02/04 16:40:44 by whaffman ######## odam.nl # # # # **************************************************************************** # @@ -22,7 +22,7 @@ LIBFT = $(LIBFT_PATH)/libft.a OBJ_PATH = obj -VPATH = src:src/enviroment +VPATH = src:src/enviroment:src/prompt SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c")) OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o)) diff --git a/inc/enviroment.h b/inc/enviroment.h index 5facf9e..681e846 100644 --- a/inc/enviroment.h +++ b/inc/enviroment.h @@ -1,16 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* enviroment.h :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/02/04 16:26:35 by whaffman #+# #+# */ +/* Updated: 2025/02/04 16:28:59 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + #ifndef ENVIROMENT_H # define ENVIROMENT_H typedef struct s_enviroment { - char *name; - char *value; - struct s_enviroment *next; -} t_enviroment; + char *name; + char *value; + struct s_enviroment *next; +} t_enviroment; -void add_enviroment(t_enviroment **enviroment, char *name, char *value); -void print_enviroment(t_enviroment *enviroment); -char *get_enviroment(t_enviroment *enviroment, char *name); -void free_enviroment(t_enviroment *enviroment); +void add_enviroment(t_enviroment **enviroment, char *name, char *value); +void print_enviroment(t_enviroment *enviroment); +char *get_enviroment(t_enviroment *enviroment, char *name); +void free_enviroment(t_enviroment *enviroment); +int parse_enviroment(char **envp, t_enviroment **enviroment); -#endif +#endif // ENVIROMENT_H diff --git a/inc/minishell.h b/inc/minishell.h index 26e6365..a1d7132 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -6,13 +6,16 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/04 16:13:13 by whaffman #+# #+# */ -/* Updated: 2025/02/04 16:13:14 by whaffman ######## odam.nl */ +/* Updated: 2025/02/04 16:28:30 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #ifndef MINISHELL_H # define MINISHELL_H +# define SUCCESS 1 +# define FAILURE 0 + # include "allowed.h" # include "libft.h" # include "enviroment.h" diff --git a/inc/prompt.h b/inc/prompt.h new file mode 100644 index 0000000..3c88433 --- /dev/null +++ b/inc/prompt.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* prompt.h :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/02/04 16:35:35 by whaffman #+# #+# */ +/* Updated: 2025/02/04 16:36:04 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#ifndef PROMPT_H +# define PROMPT_H + + + +#endif // PROMPT_H diff --git a/src/enviroment/parse_enviroment.c b/src/enviroment/parse_enviroment.c new file mode 100644 index 0000000..a8ae268 --- /dev/null +++ b/src/enviroment/parse_enviroment.c @@ -0,0 +1,19 @@ +#include "minishell.h" + +int parse_enviroment(char **envp, t_enviroment **enviroment) +{ + char **env; + + *enviroment = NULL; + + if (envp == NULL) + return (FAILURE); + while (*envp != NULL) + { + env = ft_split(*envp, '='); + add_enviroment(enviroment, env[0], env[1]); + ft_free_arr(env); + envp++; + } + return (SUCCESS); +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..aad1069 --- /dev/null +++ b/src/main.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* :::::::: */ +/* main.c :+: :+: */ +/* +:+ */ +/* By: whaffman +#+ */ +/* +#+ */ +/* Created: 2025/02/04 16:19:22 by whaffman #+# #+# */ +/* Updated: 2025/02/04 16:39:58 by whaffman ######## odam.nl */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int main(int argc, char **argv, char **envp) +{ + t_enviroment *enviroment; + char *line; + + (void)argc; + (void)argv; + parse_enviroment(envp, &enviroment); + //print_enviroment(enviroment); + free_enviroment(enviroment); + return (EXIT_SUCCESS); +} diff --git a/src/prompt/load_history.c b/src/prompt/load_history.c new file mode 100644 index 0000000..e69de29 diff --git a/src/prompt.c b/src/prompt/prompt.c similarity index 68% rename from src/prompt.c rename to src/prompt/prompt.c index 689d4eb..21c0131 100644 --- a/src/prompt.c +++ b/src/prompt/prompt.c @@ -6,40 +6,24 @@ /* By: whaffman +#+ */ /* +#+ */ /* Created: 2025/02/04 16:13:08 by whaffman #+# #+# */ -/* Updated: 2025/02/04 16:13:09 by whaffman ######## odam.nl */ +/* Updated: 2025/02/04 16:39:39 by whaffman ######## odam.nl */ /* */ /* ************************************************************************** */ #include "minishell.h" -void print_prompt(void) +char *prompt(void) { + char *line; + char *cwd = getcwd(NULL, 0); if (cwd == NULL) { perror("getcwd"); return; } - printf("%s$ ", cwd); + line = readline(cwd); free(cwd); + return (line); } -int main(int argc, char **argv, char **envp) -{ - (void)argc; - (void)argv; - char **env; - t_enviroment *enviroment = NULL; - - while (*envp != NULL) - { - env = ft_split(*envp, '='); - add_enviroment(&enviroment, env[0], env[1]); - ft_free_arr(env); - envp++; - } - - print_enviroment(enviroment); - free_enviroment(enviroment); - return 0; -}