From: Lukas Jiriste Date: Fri, 15 Sep 2023 15:58:45 +0000 (+0200) Subject: Repaired Makefile to properly build the resulting library from libft.a. X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=b92207426791ecfc6def6db85fda323eb72dadb1;p=42%2Fft_printf.git Repaired Makefile to properly build the resulting library from libft.a. Also patched leak that was happening in formatting. --- diff --git a/Makefile b/Makefile index dcb449f..4c8d68d 100644 --- a/Makefile +++ b/Makefile @@ -8,13 +8,14 @@ INCLUDE = $(addprefix -I, . ./Libft) SRCDIR = . # SOURCES = $(addprefix $(SRCDIR)/, ft_putchar.c ft_putstr.c ft_strcmp.c ft_strlen.c ft_swap.c) SOURCES = $(shell find $(SRCDIR) -maxdepth 1 -name "*.c") -OBJECTS = $(SOURCES:.c=.o) libft.a +OBJECTS = $(SOURCES:.c=.o) NAME = libftprintf.a all : $(NAME) -$(NAME) : $(OBJECTS) +$(NAME) : $(OBJECTS) libft.a + mv libft.a $(NAME) $(AR) rcs $(NAME) $(OBJECTS) libft.a : diff --git a/conversion.c b/conversion.c index 9423cb3..d476bbd 100644 --- a/conversion.c +++ b/conversion.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/05 11:30:56 by ljiriste #+# #+# */ -/* Updated: 2023/09/11 12:41:51 by ljiriste ### ########.fr */ +/* Updated: 2023/09/15 15:32:41 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -98,7 +98,7 @@ int handle_conversion(const char **format, va_list *args) return (1); } temp = base_str_constr(conv.type, args); - to_print = formatting(temp, conv); + to_print = formatting(&temp, conv); free(temp); if (!valid_toprint(to_print)) return (-1); diff --git a/formatting.c b/formatting.c index 1b66f0b..1356937 100644 --- a/formatting.c +++ b/formatting.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/05 11:28:21 by ljiriste #+# #+# */ -/* Updated: 2023/09/11 12:42:41 by ljiriste ### ########.fr */ +/* Updated: 2023/09/15 15:33:50 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,19 +84,19 @@ static void init_printed(t_to_print *tp) return ; } -t_to_print formatting(char *str, t_conv conv) +t_to_print formatting(char **str, t_conv conv) { t_to_print res; - if ((conv.type == 'p' && ft_strncmp(str, "0", 2) == 0)) + if ((conv.type == 'p' && ft_strncmp(*str, "0", 2) == 0)) { - free (str); - str = ft_strdup("(nil)"); + free (*str); + *str = ft_strdup("(nil)"); } - else if (conv.type == 's' && str == NULL) - str = ft_strdup("(null)"); + else if (conv.type == 's' && *str == NULL) + *str = ft_strdup("(null)"); init_printed(&res); - create_main(str, &res, conv); + create_main(*str, &res, conv); create_alt(&res, conv); create_padding(&res, conv); return (res); diff --git a/ft_printf.h b/ft_printf.h index 931ae1a..bcfe53e 100644 --- a/ft_printf.h +++ b/ft_printf.h @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/09/05 12:00:16 by ljiriste #+# #+# */ -/* Updated: 2023/09/05 12:27:18 by ljiriste ### ########.fr */ +/* Updated: 2023/09/15 15:34:21 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,7 +44,7 @@ typedef struct s_to_print int ft_printf(const char *format, ...); int handle_conversion(const char **format, va_list *args); -t_to_print formatting(char *str, t_conv conv); +t_to_print formatting(char **str, t_conv conv); t_conv parse_format(const char **format, va_list *args); void create_padding(t_to_print *tp, t_conv conv);