From 635e9cfe95e8e671aadbfc4cb3ad1bd4b4e4509f Mon Sep 17 00:00:00 2001 From: Maix0 Date: Sat, 25 May 2024 16:36:35 +0200 Subject: [PATCH] Modified makefiles and add AST module --- Minishell.mk | 60 +++++++++++++++------------- allocator/Makefile | 10 ++--- ast/Makefile | 95 +++++++++++++++++++++++++++++++++++++++++++++ ast/gen.list | 0 ast/src.list | 1 + ast/src/build_ast.c | 0 includes/ast | 1 + libft/ft_bzero.c | 18 --------- libft/ft_calloc.c | 31 --------------- libft/ft_memset.c | 28 ------------- libft/ft_split.c | 93 -------------------------------------------- libft/ft_strcmp.c | 31 --------------- libft/ft_strdup.c | 26 ------------- libft/ft_strjoin.c | 39 ------------------- libft/ft_strlcpy.c | 31 --------------- libft/ft_strlen.c | 23 ----------- parser/Makefile | 8 ++-- sources/ft_echo.c | 5 ++- sources/ft_pwd.c | 19 +++++---- stdme/Makefile | 28 +++++++------ 20 files changed, 165 insertions(+), 382 deletions(-) create mode 100644 ast/Makefile create mode 100644 ast/gen.list create mode 100644 ast/src.list create mode 100644 ast/src/build_ast.c create mode 120000 includes/ast delete mode 100644 libft/ft_bzero.c delete mode 100644 libft/ft_calloc.c delete mode 100644 libft/ft_memset.c delete mode 100644 libft/ft_split.c delete mode 100644 libft/ft_strcmp.c delete mode 100644 libft/ft_strdup.c delete mode 100644 libft/ft_strjoin.c delete mode 100644 libft/ft_strlcpy.c delete mode 100644 libft/ft_strlen.c diff --git a/Minishell.mk b/Minishell.mk index 2ba96cca..93159ce4 100644 --- a/Minishell.mk +++ b/Minishell.mk @@ -6,10 +6,14 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/04/28 17:28:30 by maiboyer #+# #+# # -# Updated: 2024/05/18 14:36:04 by maiboyer ### ########.fr # +# Updated: 2024/05/25 16:35:04 by maiboyer ### ########.fr # # # # **************************************************************************** # +# Functions + +link_group = -Wl,--start-group $(1) -Wl,--end-group + # Variables OBJDIRNAME ?= @@ -18,32 +22,29 @@ OBJDIRNAME ?= CFLAGS = -Werror -Wextra -Wall -Wno-unused-command-line-argument -g3 -MMD -lreadline -I./includes -I./output/include -I./stdme/output/include -rdynamic -Wl,-E # CFLAGS += -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-return=runtime -fno-common -fsanitize-address-use-after-scope # Sources -LIB = ./libft/ft_bzero.c \ - ./libft/ft_calloc.c \ - ./libft/ft_memset.c \ - ./libft/ft_split.c \ - ./libft/ft_strcmp.c \ - ./libft/ft_strdup.c \ - ./libft/ft_strlcpy.c \ - ./libft/ft_strjoin.c \ - ./libft/ft_strlen.c +# LIB = ./libft/ft_bzero.c \ +# ./libft/ft_calloc.c \ +# ./libft/ft_memset.c \ +# ./libft/ft_split.c \ +# ./libft/ft_strcmp.c \ +# ./libft/ft_strdup.c \ +# ./libft/ft_strlcpy.c \ +# ./libft/ft_strjoin.c \ +# ./libft/ft_strlen.c -SRC_DIR = ./sources -GEN_DIR = ./output +SRC_DIR = sources +GEN_DIR = output SRC = $(addprefix $(SRC_DIR)/,$(shell cat ./src.list)) $(addprefix $(GEN_DIR)/,$(shell cat ./gen.list)) # Name NAME = minishell -LIBDIRNAME = libft -SRCDIRNAME = sources # Commands CC ?= clang RM = rm -rf # Objects -OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.c=.o)) -LIB_OBJ = $(addprefix $(OBJDIRNAME)/,$(LIB:.c=.o)) +OBJ = $(addprefix $(OBJDIRNAME)/sh/,$(SRC:.c=.o)) # Colors GREEN = \033[32m @@ -52,33 +53,36 @@ RED = \033[0;31m GOLD = \033[38;5;220m END = \033[0m -.PHONY: all bonus +.PHONY: all Bonus + +LIBS_NAMES = me gmr aq ast +LIBS_FILES = $(addprefix $(OBJDIRNAME)/, $(addsuffix .a, $(addprefix lib, $(LIBS_NAMES)))) +LIBS_FLAGS = $(addprefix -l, $(LIBS_NAMES)) all: - @$(MAKE) -C ./stdme/ LIB_NAME="$(shell realpath ./stdme)/" "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" CC=$(CC) libme.a - @$(MAKE) -C ./allocator/ LIB_NAME="$(shell realpath ./parser)/" -j "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libaq.a - @$(MAKE) -C ./parser/ LIB_NAME="$(shell realpath ./parser)/" -j "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libgmr.a + @$(MAKE) -C ./stdme/ "LIB_NAME=$(shell realpath ./stdme)/" "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libme.a + @$(MAKE) -C ./allocator/ "LIB_NAME=$(shell realpath ./allocator)/" "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libaq.a + @$(MAKE) -C ./ast/ "LIB_NAME=$(shell realpath ./ast)/" "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libast.a + @$(MAKE) -C ./parser/ "LIB_NAME=$(shell realpath ./parser)/" "BUILD_DIR=$(shell realpath ./$(OBJDIRNAME))" libgmr.a @$(MAKE) -f./Minishell.mk $(NAME) + # Bonus (make bonus) -bonus: $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libme.a $(OBJDIRNAME)/libgmr.a $(OBJDIRNAME)/libaq.a +bonus: $(OBJ) $(LIBS_FILES) @mkdir -p $(OBJDIRNAME) @mkdir -p $(OBJDIRNAME)/$(LIBDIRNAME) @mkdir -p $(OBJDIRNAME)/$(SRCDIRNAME) @echo -e '$(GREY) Be Carefull ur in $(END)$(GREEN)Debug Mode$(END)' @echo -e '$(GREY) Linking\t$(END)$(GREEN)$(NAME)$(END)' - @$(CC) $(CFLAGS) -D DEBUG=42 -o $(NAME) $(OBJ) -L$(OBJDIRNAME) -lgmr -lme -laq -lme + @$(CC) $(CFLAGS) -D DEBUG=42 -o $(NAME) $(OBJ) -L$(OBJDIRNAME) $(call link_group,$(LIBS_FLAGS)) # Dependences for all -$(NAME): $(OBJ) $(LIB_OBJ) $(OBJDIRNAME)/libgmr.a $(OBJDIRNAME)/libme.a $(OBJDIRNAME)/libaq.a - @mkdir -p $(OBJDIRNAME) - @mkdir -p $(OBJDIRNAME)/$(LIBDIRNAME) - @mkdir -p $(OBJDIRNAME)/$(SRCDIRNAME) +$(NAME): $(OBJ) $(LIBS_FILES) @echo -e '$(GREY) Linking\t$(END)$(GREEN)$(NAME)$(END)' - @$(CC) $(CFLAGS) -o $(NAME) $(OBJ) $(LIB_OBJ) -L$(OBJDIRNAME) -lgmr -lme -laq -lme + @$(CC) $(CFLAGS) -o $(NAME) $(OBJ) -L$(OBJDIRNAME) $(call link_group,$(LIBS_FLAGS)) # Creating the objects -$(OBJDIRNAME)/%.o: %.c +$(OBJDIRNAME)/sh/%.o: %.c @mkdir -p $(dir $@) @echo -e '$(GREY) Compiling\t$(END)$(GREEN)$<$(END)' @$(CC) $(CFLAGS) -o $@ -c $< diff --git a/allocator/Makefile b/allocator/Makefile index 7e731039..e8421a34 100644 --- a/allocator/Makefile +++ b/allocator/Makefile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # -# Updated: 2024/05/16 16:06:36 by maiboyer ### ########.fr # +# Updated: 2024/05/25 16:28:54 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -32,8 +32,8 @@ SUBJECT_URL = SRC_FILES = $(shell cat src.list) SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES))) -OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) -DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) +OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/aq/,$(SRC_FILES))) +DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/aq/,$(SRC_FILES))) LIBS = $(addprefix $(LIBS_DIR)/,$(LIBS_NAME)) INCLUDES = $(addprefix -I,$(foreach P,$(INCLUDE_DIR) $(LIBS) $(addsuffix /include,$(LIBS)) vendor $(addsuffix /vendor,$(LIBS)),$(realpath $(P)))) @@ -57,12 +57,12 @@ $(TARGET): $(OBJ) @echo -e '$(COL_GRAY) Linking\t$(COL_GREEN)$(TARGET)$(COL_RESET)' @ar rcs $(BUILD_DIR)/$(NAME) $(OBJ) -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c +$(BUILD_DIR)/aq/%.o: $(SRC_DIR)/%.c @mkdir -p $(dir $@) @echo -e '$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)' @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ -$(BUILD_DIR)/%.o: $(GENERIC_DIR)/%.c +$(BUILD_DIR)/aq/%.o: $(GENERIC_DIR)/%.c @mkdir -p $(dir $@) @echo -e '$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)' @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ diff --git a/ast/Makefile b/ast/Makefile new file mode 100644 index 00000000..ee46bb46 --- /dev/null +++ b/ast/Makefile @@ -0,0 +1,95 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: maiboyer +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # +# Updated: 2024/05/25 16:29:47 by maiboyer ### ########.fr # +# # +# **************************************************************************** # + +BUILD_DIR ?= ../build +SRC_DIR = src +INCLUDE_DIR = include output/include ../includes +LIBS_DIR = . +GENERIC_DIR = output/src +GENERIC_INCLUDE = output/include + + +BASE_PATH ?= $(shell pwd) +NAME = libast.a +LIB_NAME ?= +TARGET = $(BUILD_DIR)/$(NAME) +CC ?= clang +CFLAGS = -Wno-unused-command-line-argument -Wall -Werror -Wextra -g3 -L$(BUILD_DIR) -MMD -rdynamic -DBASE_PATH='"$(BASE_PATH)/"' +# CFLAGS += -fsanitize=address -fno-omit-frame-pointer -fsanitize-address-use-after-return=runtime -fno-common -fsanitize-address-use-after-scope +BONUS_FILES = +LIBS_NAME = +SUBJECT_URL = + +SRC_FILES = $(shell cat src.list) + +SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES))) +OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/ast/,$(SRC_FILES))) +DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/ast/,$(SRC_FILES))) + +LIBS = $(addprefix $(LIBS_DIR)/,$(LIBS_NAME)) +INCLUDES = $(addprefix -I,$(foreach P,$(INCLUDE_DIR) $(LIBS) $(addsuffix /include,$(LIBS)) vendor $(addsuffix /vendor,$(LIBS)),$(realpath $(P)))) +COL_GRAY = \033[90m +COL_WHITE = \033[37m +COL_GREEN = \033[32m +COL_BOLD = \033[1m +COL_RESET = \033[0m + +# TODO: REMOVE FOR RENDU !!!!! +CFLAGS += -DPRINT_BACKTRACE + + +.PHONY = all bonus clean re subject + +all: $(NAME) + +$(NAME): $(TARGET) + +$(TARGET): $(OBJ) + @echo -e '$(COL_GRAY) Linking\t$(COL_GREEN)$(TARGET)$(COL_RESET)' + @ar rcs $(BUILD_DIR)/$(NAME) $(OBJ) + +$(BUILD_DIR)/ast/%.o: $(SRC_DIR)/%.c + @mkdir -p $(dir $@) + @echo -e '$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)' + @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ + +$(BUILD_DIR)/ast/%.o: $(GENERIC_DIR)/%.c + @mkdir -p $(dir $@) + @echo -e '$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)' + @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ + +clean: + @- $(foreach LIB,$(LIBS), \ + make clean LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\ + ) + @- $(if $(LIB_NAME),,echo -e '$(COL_WHITE)Clearing Artefacts';rm -rf $(BUILD_DIR)) + +fclean: clean + @- $(foreach LIB,$(LIBS), \ + make fclean LIB_NAME=$(LIB)/ BUILD_DIR=$(shell realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\ + ) + @echo -e '$(COL_WHITE)Clearing Output $(COL_GRAY)$(LIB_NAME)$(NAME)' + @rm -f $(BUILD_DIR)$(NAME) + +re: fclean all + +subject: subject.txt + bat --plain ./subject.txt + +subject.txt: + @curl $(SUBJECT_URL) | pdftotext -layout -nopgbrk -q - subject.txt + +generate_filelist:: + @/usr/bin/env zsh -c "tree -iFf --noreport output | rg '^output/src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./gen.list + @/usr/bin/env zsh -c "tree -iFf --noreport src | rg '^src/(.*)\.c\$$' --replace '\$$1' | sort -u" > ./src.list + +-include $(DEPS) diff --git a/ast/gen.list b/ast/gen.list new file mode 100644 index 00000000..e69de29b diff --git a/ast/src.list b/ast/src.list new file mode 100644 index 00000000..761a1848 --- /dev/null +++ b/ast/src.list @@ -0,0 +1 @@ +build_ast diff --git a/ast/src/build_ast.c b/ast/src/build_ast.c new file mode 100644 index 00000000..e69de29b diff --git a/includes/ast b/includes/ast new file mode 120000 index 00000000..ad952174 --- /dev/null +++ b/includes/ast @@ -0,0 +1 @@ +../ast/include/ast \ No newline at end of file diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c deleted file mode 100644 index c65ffc33..00000000 --- a/libft/ft_bzero.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_bzero.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 16:43:13 by rparodi #+# #+# */ -/* Updated: 2024/03/31 22:29:48 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -void ft_bzero(void *s, t_usize n) -{ - ft_memset(s, 0, n); -} diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c deleted file mode 100644 index d0bacd7b..00000000 --- a/libft/ft_calloc.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_calloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 16:47:17 by rparodi #+# #+# */ -/* Updated: 2024/03/31 22:32:48 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -void *ft_calloc(t_usize nmemb, t_usize size) -{ - t_usize total; - t_str to_return; - - if (nmemb == 0 || size == 0) - return ((void *)malloc(1)); - total = nmemb * size; - if (total / nmemb != size && total / size != nmemb) - return (NULL); - to_return = (char *)malloc(total); - if (to_return == NULL) - to_return = NULL; - else - ft_bzero(to_return, total); - return (to_return); -} diff --git a/libft/ft_memset.c b/libft/ft_memset.c deleted file mode 100644 index 77c4792b..00000000 --- a/libft/ft_memset.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 16:50:29 by rparodi #+# #+# */ -/* Updated: 2024/03/31 22:32:32 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -void *ft_memset(void *s, t_i32 c, t_usize n) -{ - t_str str; - t_usize i; - - i = 0; - str = (t_str)s; - while (i < n) - { - str[i] = c; - i++; - } - return (str); -} diff --git a/libft/ft_split.c b/libft/ft_split.c deleted file mode 100644 index 3927fb48..00000000 --- a/libft/ft_split.c +++ /dev/null @@ -1,93 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_split.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */ -/* Updated: 2024/03/31 21:07:40 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -static t_i32 count_words(t_const_str str, t_i8 sep) -{ - t_i32 i; - t_i32 count; - - i = 0; - count = 0; - while (str[i]) - { - while (str[i] == sep && str[i]) - i++; - if (str[i] != sep && str[i]) - { - while (str[i] != sep && str[i]) - i++; - count++; - } - } - return (count); -} - -static t_str ft_strndup(t_const_str s, t_i32 j) -{ - t_i32 i; - t_str str; - - i = 0; - str = (t_str)malloc((j + 1)); - if (!str) - return (NULL); - while (s[i] && i < j) - { - str[i] = s[i]; - i++; - } - str[i] = '\0'; - return (str); -} - -static t_str *ext_w(t_str *words_array, t_const_str str, t_i8 sep, t_i32 size) -{ - t_i32 i; - t_i32 j; - - i = 0; - j = 0; - while (j < size) - { - while (str[i] == sep && str[i]) - i++; - str = str + i; - i = 0; - while (str[i] != sep && str[i]) - i++; - words_array[j++] = ft_strndup(str, i); - str = str + i; - i = 0; - } - words_array[j] = 0; - return (words_array); -} - -t_str *ft_split(t_const_str s, t_i8 c) -{ - t_i32 size; - t_str *words_array; - - size = count_words(s, c); - words_array = (t_str *)malloc(sizeof(char *) * (size + 1)); - if (!words_array) - return (NULL); - if (size == 0) - { - words_array[0] = NULL; - return (words_array); - } - words_array = ext_w(words_array, s, c, size); - return (words_array); -} diff --git a/libft/ft_strcmp.c b/libft/ft_strcmp.c deleted file mode 100644 index b0bd8147..00000000 --- a/libft/ft_strcmp.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */ -/* Updated: 2024/03/31 21:57:48 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -int ft_strcmp(const char *s1, const char *s2) -{ - size_t i; - int diff; - - i = 0; - while ((s1[i] || s2[i])) - { - if (s1[i] != s2[i] && s1 && s2) - { - diff = (unsigned char)s1[i] - (unsigned char)s2[i]; - return (diff); - } - i++; - } - return (0); -} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c deleted file mode 100644 index fae4f328..00000000 --- a/libft/ft_strdup.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strdup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 16:53:59 by rparodi #+# #+# */ -/* Updated: 2024/04/01 01:41:35 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -t_str ft_strdup(t_const_str s) -{ - t_usize len; - t_str to_return; - - len = ft_strlen(s) + 1; - to_return = (t_str)malloc(sizeof(t_i8) * len); - if (!to_return) - return (NULL); - ft_strlcpy(to_return, s, len); - return (to_return); -} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c deleted file mode 100644 index a94d57be..00000000 --- a/libft/ft_strjoin.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strjoin.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/09 13:55:15 by rparodi #+# #+# */ -/* Updated: 2024/04/13 20:16:50 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -char *ft_strjoin(char const *s1, char const *s2) -{ - size_t i; - size_t save_i; - char *str; - - i = 0; - str = (char *)malloc((ft_strlen(s1) + ft_strlen(s2)) + 1); - if (!str) - return (NULL); - while (s1[i] != '\0') - { - str[i] = s1[i]; - i++; - } - save_i = i; - i = 0; - while (s2[i] != '\0') - { - str[save_i + i] = s2[i]; - i++; - } - str[i + save_i] = '\0'; - return (str); -} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c deleted file mode 100644 index 7a30a290..00000000 --- a/libft/ft_strlcpy.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 16:55:25 by rparodi #+# #+# */ -/* Updated: 2024/04/01 01:38:28 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -t_usize ft_strlcpy(t_str dst, t_const_str src, t_usize size) -{ - t_usize i; - - i = 0; - while (src[i] && i + 1 < size) - { - dst[i] = src[i]; - i++; - } - if (size > 0) - { - dst[i] = '\0'; - i++; - } - return (ft_strlen(src)); -} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c deleted file mode 100644 index d8891e40..00000000 --- a/libft/ft_strlen.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlen.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rparodi +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/07 16:56:24 by rparodi #+# #+# */ -/* Updated: 2024/04/01 01:37:04 by rparodi ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "../includes/minishell.h" - -size_t ft_strlen(t_const_str s) -{ - t_usize i; - - i = 0; - while (s[i] != '\0') - i++; - return (i); -} diff --git a/parser/Makefile b/parser/Makefile index 40844684..66bc0b80 100644 --- a/parser/Makefile +++ b/parser/Makefile @@ -6,7 +6,7 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # -# Updated: 2024/05/18 14:36:37 by maiboyer ### ########.fr # +# Updated: 2024/05/25 16:29:29 by maiboyer ### ########.fr # # # # **************************************************************************** # @@ -24,8 +24,8 @@ include ./Filelist.mk SRC_FILES += ./src/combined ./src/scanner SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES))) -OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) -DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) +OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/gmr/,$(SRC_FILES))) +DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/gmr/,$(SRC_FILES))) INCLUDES = GREEN = \033[32m @@ -54,7 +54,7 @@ $(TARGET): $(OBJ) @echo -e '$(GREY) Linking\t$(END)$(GREEN)$(NAME)$(END)' @ar rcs $(BUILD_DIR)/$(NAME) $(OBJ) -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c +$(BUILD_DIR)/gmr/%.o: $(SRC_DIR)/%.c @mkdir -p $(dir $@) @echo -e '$(GREY) Compiling\t$(END)$(GREEN)$<$(END)' @$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ diff --git a/sources/ft_echo.c b/sources/ft_echo.c index d3daaf6d..a97fe83d 100644 --- a/sources/ft_echo.c +++ b/sources/ft_echo.c @@ -6,15 +6,16 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/31 21:48:04 by rparodi #+# #+# */ -/* Updated: 2024/03/31 21:51:41 by rparodi ### ########.fr */ +/* Updated: 2024/05/25 16:09:28 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ #include "../includes/minishell.h" +#include "me/str/str.h" void ft_echo(t_str txt, t_str flag) { printf("%s", txt); - if (ft_strcmp(flag, "-n") != 0) + if (!str_compare(flag, "-n")) printf("\n"); } diff --git a/sources/ft_pwd.c b/sources/ft_pwd.c index 8a602d60..a91555df 100644 --- a/sources/ft_pwd.c +++ b/sources/ft_pwd.c @@ -6,27 +6,30 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/31 22:14:33 by rparodi #+# #+# */ -/* Updated: 2024/03/31 22:27:33 by rparodi ### ########.fr */ +/* Updated: 2024/05/25 16:08:50 by maiboyer ### ########.fr */ /* */ /* ************************************************************************** */ -#include "../includes/minishell.h" +#include "me/mem/mem.h" +#include "minishell.h" -void ft_pwd(void) +void ft_pwd(void) { t_str str; - t_usize size; + t_usize size; size = 1024; - str = (t_str)ft_calloc((size + 1), sizeof(t_i8)); + str = (t_str)mem_alloc_array((size + 1), sizeof(t_i8)); if (str == NULL) ft_exit(NULL, 0); - while (getcwd(str, size) == NULL) { + while (getcwd(str, size) == NULL) + { if (str) free(str); size *= 2; - str = (t_str)ft_calloc(sizeof(t_i8), size); - if (str == NULL) { + str = (t_str)mem_alloc_array(sizeof(t_i8), size); + if (str == NULL) + { ft_exit(NULL, 0); } } diff --git a/stdme/Makefile b/stdme/Makefile index afbec309..f70060b9 100644 --- a/stdme/Makefile +++ b/stdme/Makefile @@ -6,10 +6,12 @@ # By: maiboyer +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/03 13:20:01 by maiboyer #+# #+# # -# Updated: 2024/05/14 18:41:46 by maiboyer ### ########.fr # +# Updated: 2024/05/25 16:28:21 by maiboyer ### ########.fr # # # # **************************************************************************** # + + BUILD_DIR ?= build SRC_DIR = src INCLUDE_DIR = include output/include ../allocator/include @@ -35,11 +37,11 @@ SRC_FILES = $(shell cat src.list) BONUS = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(BONUS_FILES))) SRC = $(addsuffix .c,$(addprefix $(SRC_DIR)/,$(SRC_FILES))) \ $(addsuffix .c,$(addprefix $(GENERIC_DIR)/,$(GENERIC_FILES))) -BONUS_OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(BONUS_FILES))) -OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(SRC_FILES) )) \ - $(addsuffix .o,$(addprefix $(BUILD_DIR)/,$(GENERIC_FILES))) -DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(SRC_FILES))) \ - $(addsuffix .d,$(addprefix $(BUILD_DIR)/,$(GENERIC_FILES))) +BONUS_OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/me/,$(BONUS_FILES))) +OBJ = $(addsuffix .o,$(addprefix $(BUILD_DIR)/me/,$(SRC_FILES) )) \ + $(addsuffix .o,$(addprefix $(BUILD_DIR)/me/,$(GENERIC_FILES))) +DEPS = $(addsuffix .d,$(addprefix $(BUILD_DIR)/me/,$(SRC_FILES))) \ + $(addsuffix .d,$(addprefix $(BUILD_DIR)/me/,$(GENERIC_FILES))) LIBS = $(addprefix $(LIBS_DIR)/,$(LIBS_NAME)) INCLUDES = $(addprefix -I,$(foreach P,$(INCLUDE_DIR) $(GENERIC_INCLUDE) $(LIBS) $(addsuffix /include,$(LIBS)) vendor $(addsuffix /vendor,$(LIBS)),$(realpath $(P)))) COL_GRAY = \033[90m @@ -63,12 +65,12 @@ $(TARGET): $(OBJ) @#$(CC) $(INCLUDES) $(OBJ) $(CFLAGS) -o $(NAME) @ar rcs $(BUILD_DIR)/$(NAME) $(OBJ) -$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c +$(BUILD_DIR)/me/%.o: $(SRC_DIR)/%.c @mkdir -p $(dir $@) @echo -e '$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)' @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ -$(BUILD_DIR)/%.o: $(GENERIC_DIR)/%.c +$(BUILD_DIR)/me/%.o: $(GENERIC_DIR)/%.c @mkdir -p $(dir $@) @echo -e '$(COL_GRAY) Building\t$(COL_GREEN)$<$(COL_RESET)' @$(CC) $(CFLAGS) $(WERROR) $(INCLUDES) -c $< -o $@ @@ -78,10 +80,8 @@ clean: make clean LIB_NAME=$(LIB)/ BUILD_DIR=$(realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\ ) @- $(if $(LIB_NAME),,\ - printf $(COL_WHITE)Clearing\ Artefacts\ ; \ - printf $(COL_GRAY)\%-25s$(COL_RESET)\ \($(BUILD_DIR)\); \ + echo -e '$(COL_WHITE)Clearing Artefacts\t$(COL_GREEN)$(BUILD_DIR)/$(COL_RESET)' \ rm -rf $(BUILD_DIR); \ - printf $(COL_GREEN)done$(COL_RESET)\\n; \ ) @echo >/dev/null @@ -89,10 +89,8 @@ fclean: clean @- $(foreach LIB,$(LIBS), \ make fclean LIB_NAME=$(LIB)/ BUILD_DIR=$(shell realpath $(BUILD_DIR)) -C $(LIB) --no-print-directory || true;\ ) - @printf $(COL_WHITE)Clearing\ Output\ $(COL_GRAY)%-28s$(COL_RESET)\ \ - \($(LIB_NAME)$(NAME)\) - @rm -f $(BUILD_DIR)$(NAME) - @printf $(COL_GREEN)done$(COL_RESET)\\n + @echo -e '$(COL_WHITE)Clearing Output\t$(COL_GREEN)$(BUILD_DIR)/$(NAME)$(COL_RESET)' + @rm -f $(BUILD_DIR)/$(NAME) re: fclean all