diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5551c3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +minishell +a.out +*.d +*.o +obj/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d02354e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "lib/libft"] + path = lib/libft + url = https://gitea.duinvoetje.nl/willem/libft.git diff --git a/LULDOC-LOLDICK b/LULDOC-LOLDICK deleted file mode 100644 index d39edd5..0000000 --- a/LULDOC-LOLDICK +++ /dev/null @@ -1,5 +0,0 @@ - -Ik heb even alle allowed function door de AI in de readme laten zetten, en een header file gemaakt wat iig alles include -ik ga dit weekend wel door met een basic Makefile en mss een Prompt maken voor readline ofzo. maar drink vooral veel bier en geniet van je weekend -classic de Ai maakt er veel bier van - diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..304bd12 --- /dev/null +++ b/Makefile @@ -0,0 +1,75 @@ +# **************************************************************************** # +# # +# ::: o_ :::::: ::: # +# Makefile :+: / :+::+: :+: # +# +:+ > +:++:+ +:+ # +# By: whaffman +#+ +:+ +#++#++:++#++ # +# +#+ +#+#+ +#++#+ +#+ \o/ # +# Created: 2024/10/15 11:48:46 by whaffman #+#+# #+#+# #+# #+# | # +# Updated: 2024/11/07 15:28:08 by whaffman ### ### ### ### / \ # +# # +# **************************************************************************** # + +NAME = minishell + +SRC_PATH = src +INC_PATH = inc +LIB_PATH = lib + +LIBFT_PATH = $(LIB_PATH)/libft +LIBFT_INC_PATH = $(LIBFT_PATH)/inc +LIBFT = $(LIBFT_PATH)/libft.a + +OBJ_PATH = obj + +VPATH = src +SOURCES = $(shell basename -a $(shell find $(SRC_PATH) -type f -name "*.c")) + +OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o)) +DEPENDS = ${OBJECTS:.o=.d} + +CC = cc +RM = rm -rf + +INCLUDES = -I./$(INC_PATH) -I./$(LIBFT_INC_PATH) +CFLAGS = -Wall -Wextra -Werror -MMD + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + LDLIBS := -L$(LIBFT_PATH) -lft +endif + +all: $(NAME) + +$(NAME): $(LIBFT) $(OBJECTS) + $(CC) $(CFLAGS) $(OBJECTS) $(LDLIBS) -o $(NAME) + +-include ${DEPENDS} + +$(LIBFT): $(LIBFT_PATH) + $(MAKE) -C $(LIBFT_PATH) + +$(LIBFT_PATH): + git submodule add https://gitea.duinvoetje.nl/willem/libft.git $(LIBFT_PATH) + +$(OBJ_PATH): + mkdir -p $@ + +$(OBJ_PATH)/%.o: %.c $(LIBFT) | $(OBJ_PATH) + $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ + +clean: + $(RM) $(OBJECTS) $(OBJ_PATH) + $(MAKE) -C $(LIBFT_PATH) clean + $(MAKE) -C $(MLX42_PATH)/build clean + +fclean: clean + $(RM) $(NAME) + $(MAKE) -C $(LIBFT_PATH) fclean + +re: fclean all + +run: all + ./$(NAME) + +.PHONY: all clean fclean re run diff --git a/README.md b/README.md index 6d2763e..b7de134 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ * `ssize_t read(int fd, void *buf, size_t count);` * Reads up to count bytes from file descriptor fd into the buffer starting at buf. * `close` - * `int close(int fd);` + * `int close(int fd);`q * Closes the file descriptor fd. * `fork` * `pid_t fork(void);` diff --git a/inc/minishell.h b/inc/minishell.h index 7c812d8..86b4cac 100644 --- a/inc/minishell.h +++ b/inc/minishell.h @@ -156,7 +156,6 @@ # include # include # include -# include # include # include # include diff --git a/lib/libft b/lib/libft new file mode 160000 index 0000000..27f7d3e --- /dev/null +++ b/lib/libft @@ -0,0 +1 @@ +Subproject commit 27f7d3e9e02cccf7092f3101b939d381198a595b diff --git a/src/prompt.c b/src/prompt.c new file mode 100644 index 0000000..c67e98f --- /dev/null +++ b/src/prompt.c @@ -0,0 +1,88 @@ + +#include +#include +#include +#include +#include "libft.h" + + +// /** +// * @brief Prints the prompt for the Minishell. +// * +// * This function prints the prompt for the Minishell, which is the current working directory followed by a dollar sign. +// * +// * @param void +// * @return void +// */ + +typedef struct s_enviroment +{ + char *name; + char *value; + struct s_enviroment *next; +} t_enviroment; + +void add_enviroment(t_enviroment **enviroment, char *name, char *value) +{ + t_enviroment *new_enviroment = malloc(sizeof(t_enviroment)); + if (new_enviroment == NULL) + { + perror("malloc"); + return; + } + new_enviroment->name = name; + new_enviroment->value = value; + new_enviroment->next = *enviroment; + *enviroment = new_enviroment; +} + +void print_enviroment(t_enviroment *enviroment) +{ + while (enviroment != NULL) + { + printf("%s=%s\n", enviroment->name, enviroment->value); + enviroment = enviroment->next; + } +} + +char *get_enviroment(t_enviroment *enviroment, char *name) +{ + while (enviroment != NULL) + { + if (ft_strcmp(enviroment->name, name) == 0) + { + return enviroment->value; + } + enviroment = enviroment->next; + } + return NULL; +} +void print_prompt(void) +{ + char *cwd = getcwd(NULL, 0); + if (cwd == NULL) + { + perror("getcwd"); + return; + } + printf("%s$ ", cwd); + free(cwd); +} + +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]); + envp++; + } + + print_enviroment(enviroment); + return 0; +} \ No newline at end of file