diff --git a/Makefile b/Makefile index 282b31c..d9a6bbb 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: tmaze +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2018/04/07 12:47:06 by tmaze #+# #+# # -# Updated: 2019/03/07 16:19:33 by tmaze ### ########.fr # +# Updated: 2019/03/07 22:26:45 by tmaze ### ########.fr # # # #******************************************************************************# @@ -19,7 +19,7 @@ NAME = libft.a SRCS = ft_memset.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c ft_strdup.c ft_strcpy.c ft_strncpy.c ft_strcat.c ft_strncat.c ft_strlcat.c ft_strchr.c ft_strrchr.c ft_strstr.c ft_strnstr.c ft_strcmp.c ft_strncmp.c ft_atoi.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c ft_tolower.c \ ft_memalloc.c ft_memdel.c ft_strnew.c ft_strdel.c ft_strclr.c ft_striter.c ft_striteri.c ft_strmap.c ft_strmapi.c ft_strequ.c ft_strnequ.c ft_strsub.c ft_strjoin.c ft_strtrim.c ft_strsplit.c ft_itoa.c ft_putchar.c ft_putstr.c ft_putendl.c ft_putnbr.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c\ ft_lstnew.c ft_lstdelone.c ft_lstdel.c ft_lstadd.c ft_lstiter.c ft_lstmap.c \ -ft_isupper.c ft_islower.c ft_str_is_alpha.c ft_str_is_lowercase.c ft_str_is_numeric.c ft_str_is_printable.c ft_str_is_uppercase.c ft_strcapitalize.c ft_strlcpy.c ft_strlowcase.c ft_strupcase.c ft_lstsize.c ft_lstgetat.c ft_lstgetlast.c ft_sort_params.c ft_print_words_tables.c ft_lstaddend.c ft_strndup.c ft_abs.c ft_strnchr.c ft_strrnchr.c get_next_line.c ft_del_words_tables.c ft_putstrn.c ft_nbrlen.c ft_putstrpad.c ft_putnbrpad.c ft_lstsort.c ft_lstaddsort.c ft_round.c ft_realpath.c ft_iswhitespace.c ft_issign.c ft_hasdigit.c ft_strsplitwhitespace.c ft_atois.c ft_getline.c +ft_isupper.c ft_islower.c ft_str_is_alpha.c ft_str_is_lowercase.c ft_str_is_numeric.c ft_str_is_printable.c ft_str_is_uppercase.c ft_strcapitalize.c ft_strlcpy.c ft_strlowcase.c ft_strupcase.c ft_lstsize.c ft_lstgetat.c ft_lstgetlast.c ft_sort_params.c ft_print_words_tables.c ft_lstaddend.c ft_strndup.c ft_abs.c ft_strnchr.c ft_strrnchr.c get_next_line.c ft_del_words_tables.c ft_putstrn.c ft_nbrlen.c ft_putstrpad.c ft_putnbrpad.c ft_lstsort.c ft_lstaddsort.c ft_round.c ft_realpath.c ft_iswhitespace.c ft_issign.c ft_hasdigit.c ft_strsplitwhitespace.c ft_atois.c ft_getline.c ft_printf.c ft_printf_check_fields.c ft_printf_check_type.c ft_printf_tools.c ft_printf_tools_char.c ft_printf_tools_float.c ft_printf_tools_float.c ft_printf_tools_hexa.c ft_printf_tools_int.c ft_printf_tools_lenght.c ft_printf_tools_malloc_size.c ft_printf_tools_oct.c ft_printf_tools_prec_size.c ft_printf_tools_str.c ft_printf_tools_unsigned_int.c ft_printf_tools_wchar_t.c ft_printf_tools_wstr.c OBJDIR = objs OBJS = $(SRCS:.c=.o) diff --git a/ft_getline.c b/ft_getline.c index a1ca7d9..05db5b8 100644 --- a/ft_getline.c +++ b/ft_getline.c @@ -6,28 +6,43 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/07 15:12:59 by tmaze #+# #+# */ -/* Updated: 2019/03/07 19:02:51 by tmaze ### ########.fr */ +/* Updated: 2019/03/07 22:06:57 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -static char *supercat(char **s1, char *s2[BUFF_SIZE + 1]) +static char *supercat(char **s1, char *buff) { char *tmp; - printf("lengths supercat %zu\n", ft_strlen(*s2)); - if ((tmp = ft_strjoin(*s1, *s2)) == NULL) + if ((tmp = ft_strjoin(*s1, buff)) == NULL) return (NULL); ft_strdel(s1); - ft_strclr(*s2); + ft_strclr(buff); *s1 = tmp; return (*s1); } +static int update_line(char **line, char *buff) +{ + if (*line == NULL) + { + if ((*line = ft_strdup(buff)) == NULL) + return (-1); + } + else if (*line != NULL) + if (supercat(line, buff) == NULL) + { + ft_strdel(line); + return (-1); + } + return (0); +} + int ft_getline(char **line) { - static char buff[BUFF_SIZE + 1] = "\0"; + static char buff[BUFF_SIZE + 1]; char *ind; int ret; @@ -35,39 +50,18 @@ int ft_getline(char **line) return (-1); *line = NULL; ind = NULL; - if (buff[0] == '\0') - ft_bzero(buff, BUFF_SIZE + 1); - while ((ret = read(0, buff, BUFF_SIZE)) == BUFF_SIZE && (ind = ft_strchr(buff, '\n')) == NULL) + ft_bzero(buff, BUFF_SIZE + 1); + while ((ret = read(0, buff, BUFF_SIZE)) == BUFF_SIZE + && (ind = ft_strchr(buff, '\n')) == NULL) { - if (*line == NULL) - { - if ((*line = ft_strdup(buff)) == NULL) - return (-1); - } - else if (*line != NULL) - if (supercat(line, &buff) == NULL) - { - ft_strdel(line); - return (-1); - } + if (update_line(line, buff) == -1) + return (-1); ft_bzero(&buff, BUFF_SIZE + 1); } if (ind != NULL || (ind == NULL && (ind = ft_strchr(buff, '\n')) != NULL)) *ind = '\0'; - if (*line == NULL) - { - if ((*line = ft_strdup(buff)) == NULL) + if (update_line(line, buff) == -1) return (-1); - } - else if (*line != NULL) - { - printf("lengths %zu %zu\n", ft_strlen(*line), ft_strlen(buff)); - if (supercat(line, &buff) == NULL) - { - ft_strdel(line); - return (-1); - } - } if (ind == NULL) ft_bzero(&buff, BUFF_SIZE + 1); if (ind != NULL && ind < &(buff[BUFF_SIZE])) diff --git a/ft_printf.c b/ft_printf.c index b589f14..6da2349 100644 --- a/ft_printf.c +++ b/ft_printf.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/28 22:27:58 by klebon #+# #+# */ -/* Updated: 2019/02/19 18:11:54 by tmaze ### ########.fr */ +/* Updated: 2019/03/07 22:16:43 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" void init_handler_tab(char *(*t[16])(t_conv *, va_list)) { diff --git a/ft_printf_check_fields.c b/ft_printf_check_fields.c index bab02e4..934dfae 100644 --- a/ft_printf_check_fields.c +++ b/ft_printf_check_fields.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/29 12:33:40 by klebon #+# #+# */ -/* Updated: 2019/02/17 18:58:27 by tmaze ### ########.fr */ +/* Updated: 2019/03/07 22:16:54 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" void check_flags(const char **str, t_conv *field) { diff --git a/ft_printf_check_type.c b/ft_printf_check_type.c index 419eeae..8b53e2f 100644 --- a/ft_printf_check_type.c +++ b/ft_printf_check_type.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/02 21:09:18 by klebon #+# #+# */ -/* Updated: 2019/02/14 16:30:45 by tmaze ### ########.fr */ +/* Updated: 2019/03/07 22:18:05 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" ssize_t check_type_one(const char **str, t_conv *field) { diff --git a/ft_printf_tools.c b/ft_printf_tools.c index 77b3200..07cbc68 100644 --- a/ft_printf_tools.c +++ b/ft_printf_tools.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/02 21:49:45 by klebon #+# #+# */ -/* Updated: 2019/03/01 12:11:36 by tmaze ### ########.fr */ +/* Updated: 2019/03/07 22:18:16 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" void init_struct_conv(t_conv *field) { diff --git a/ft_printf_tools_char.c b/ft_printf_tools_char.c index dd3124a..f6d93e2 100644 --- a/ft_printf_tools_char.c +++ b/ft_printf_tools_char.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/19 08:51:48 by klebon #+# #+# */ -/* Updated: 2018/10/30 12:35:10 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:22:07 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" char *handle_output_char(t_conv *field, va_list ap) { @@ -22,7 +22,7 @@ char *handle_output_char(t_conv *field, va_list ap) else c = (unsigned char)va_arg(ap, int); field->str_size = (field->fl_witdth > 1) ? field->fl_witdth : 1; - if (!(output = ft_strnewb(field->str_size))) + if (!(output = ft_strnew(field->str_size))) return (NULL); output[0] = c; ft_align_wchar(output, field); diff --git a/ft_printf_tools_float.c b/ft_printf_tools_float.c index 9f6ed69..d943957 100644 --- a/ft_printf_tools_float.c +++ b/ft_printf_tools_float.c @@ -6,11 +6,11 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/13 12:52:34 by tmaze #+# #+# */ -/* Updated: 2019/03/03 17:36:31 by tmaze ### ########.fr */ +/* Updated: 2019/03/07 22:23:31 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" void roundup(char *str, long double n, int i, int prec) { @@ -115,7 +115,7 @@ char *handle_output_float(t_conv *field, va_list ap) nbrstr = getnbrstr(nb, field); size = set_malloc_sizef(nb, nbrstr, field); pad = field->str_size - size; - if ((field->str = ft_strnewb(field->str_size)) != NULL) + if ((field->str = ft_strnew(field->str_size)) != NULL) set_strf(field, nbrstr, nb, pad); ft_strdel(&nbrstr); return (field->str); diff --git a/ft_printf_tools_hexa.c b/ft_printf_tools_hexa.c index d7ee5c6..a2e6857 100644 --- a/ft_printf_tools_hexa.c +++ b/ft_printf_tools_hexa.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/13 19:58:30 by klebon #+# #+# */ -/* Updated: 2018/10/01 15:37:27 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:23:44 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" char *handler_hexa(uintmax_t nb, t_conv *field) { @@ -20,7 +20,7 @@ char *handler_hexa(uintmax_t nb, t_conv *field) size = set_precision_sizex(nb, field); set_malloc_sizeh(nb, field); - if (!(str = ft_strnewb(field->str_size))) + if (!(str = ft_strnew(field->str_size))) return (NULL); n = nb; while (n) diff --git a/ft_printf_tools_int.c b/ft_printf_tools_int.c index b01486c..bdaa061 100644 --- a/ft_printf_tools_int.c +++ b/ft_printf_tools_int.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/10 14:02:42 by klebon #+# #+# */ -/* Updated: 2018/10/30 11:51:59 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:23:55 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" char *handler_int(uintmax_t nb, t_conv *field) { @@ -20,7 +20,7 @@ char *handler_int(uintmax_t nb, t_conv *field) size = set_precision_sizes(nb, field); set_malloc_sizes(nb, field); - if (!(str = ft_strnewb(field->str_size))) + if (!(str = ft_strnew(field->str_size))) return (NULL); n = ((intmax_t)nb >= 0) ? (uintmax_t)nb : -(uintmax_t)nb; while (n) diff --git a/ft_printf_tools_lenght.c b/ft_printf_tools_lenght.c index 167654f..d1c5a1d 100644 --- a/ft_printf_tools_lenght.c +++ b/ft_printf_tools_lenght.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/10/01 15:40:34 by klebon #+# #+# */ -/* Updated: 2018/10/01 15:41:28 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:19:06 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" unsigned int ft_bin_size(unsigned int nb) { diff --git a/ft_printf_tools_malloc_size.c b/ft_printf_tools_malloc_size.c index e6c5c3a..17256fc 100644 --- a/ft_printf_tools_malloc_size.c +++ b/ft_printf_tools_malloc_size.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/10/01 13:43:37 by klebon #+# #+# */ -/* Updated: 2019/02/21 12:36:37 by tmaze ### ########.fr */ +/* Updated: 2019/03/07 22:20:26 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" void set_malloc_sizes(uintmax_t nb, t_conv *field) { diff --git a/ft_printf_tools_oct.c b/ft_printf_tools_oct.c index ab4afc7..c3e6215 100644 --- a/ft_printf_tools_oct.c +++ b/ft_printf_tools_oct.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/13 20:13:28 by klebon #+# #+# */ -/* Updated: 2018/10/01 15:38:13 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:24:23 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" char *handler_oct(uintmax_t nb, t_conv *field) { @@ -20,7 +20,7 @@ char *handler_oct(uintmax_t nb, t_conv *field) size = set_precision_sizeo(nb, field); set_malloc_sizeo(nb, field); - if (!(str = ft_strnewb(field->str_size))) + if (!(str = ft_strnew(field->str_size))) return (NULL); n = nb; while (n) diff --git a/ft_printf_tools_prec_size.c b/ft_printf_tools_prec_size.c index 18d9c02..b9d2cc0 100644 --- a/ft_printf_tools_prec_size.c +++ b/ft_printf_tools_prec_size.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/10/01 15:36:42 by klebon #+# #+# */ -/* Updated: 2018/10/01 15:39:43 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:20:49 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" int set_precision_sizex(uintmax_t nb, t_conv *field) { diff --git a/ft_printf_tools_str.c b/ft_printf_tools_str.c index cd1293d..8b39deb 100644 --- a/ft_printf_tools_str.c +++ b/ft_printf_tools_str.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/19 09:05:22 by klebon #+# #+# */ -/* Updated: 2019/03/03 09:12:19 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:27:38 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" void ft_align_wstr(char *str, t_conv *field) { @@ -53,12 +53,12 @@ char *handle_output_str(t_conv *field, va_list ap) if (field->fl_prec != -1) len = (len > field->fl_prec) ? field->fl_prec : len; field->str_size = (field->fl_witdth > len) ? field->fl_witdth : len; - if (!(output = ft_strnewb(field->str_size))) + if (!(output = ft_strnew(field->str_size))) return (NULL); if (field->fl_prec == -1) - ft_strcpy_s(output, str); + ft_strcpy(output, str); else - ft_strncpy_s(output, str, len); + ft_strncpy(output, str, len); ft_align_wstr(output, field); return (output); } diff --git a/ft_printf_tools_unsigned_int.c b/ft_printf_tools_unsigned_int.c index 355f8f3..e46bcae 100644 --- a/ft_printf_tools_unsigned_int.c +++ b/ft_printf_tools_unsigned_int.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/13 19:43:31 by klebon #+# #+# */ -/* Updated: 2018/05/25 18:56:39 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:25:00 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" void set_malloc_sizeu(uintmax_t nb, t_conv *field) { @@ -53,7 +53,7 @@ char *handler_uns(uintmax_t nb, t_conv *field) size = set_precision_sizeu(nb, field); set_malloc_sizeu(nb, field); - if (!(str = ft_strnewb(field->str_size))) + if (!(str = ft_strnew(field->str_size))) return (NULL); n = nb; while (n) diff --git a/ft_printf_tools_wchar_t.c b/ft_printf_tools_wchar_t.c index f6d85ef..e5f1c7b 100644 --- a/ft_printf_tools_wchar_t.c +++ b/ft_printf_tools_wchar_t.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/18 18:10:11 by klebon #+# #+# */ -/* Updated: 2018/10/01 15:40:54 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:25:11 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" /* ** I have to handle minus, width @@ -48,7 +48,7 @@ char *handler_2oct_char(wint_t c, t_conv *field) char *output; field->str_size = (field->fl_witdth > 2) ? field->fl_witdth : 2; - if (!(output = ft_strnewb(field->str_size))) + if (!(output = ft_strnew(field->str_size))) return (NULL); output[0] = (c >> 6) + 0xC0; output[1] = (c & 0x3F) + 0x80; @@ -61,7 +61,7 @@ char *handler_3oct_char(wint_t c, t_conv *field) char *output; field->str_size = (field->fl_witdth > 3) ? field->fl_witdth : 3; - if (!(output = ft_strnewb(field->str_size))) + if (!(output = ft_strnew(field->str_size))) return (NULL); output[0] = (c >> 12) + 0xE0; output[1] = ((c >> 6) & 0x3F) + 0x80; @@ -75,7 +75,7 @@ char *handler_4oct_char(wint_t c, t_conv *field) char *output; field->str_size = (field->fl_witdth > 4) ? field->fl_witdth : 4; - if (!(output = ft_strnewb(field->str_size))) + if (!(output = ft_strnew(field->str_size))) return (NULL); output[0] = (c >> 18) + 0xF0; output[1] = ((c >> 12) & 0x3F) + 0x80; @@ -96,7 +96,7 @@ char *handle_output_wchar(t_conv *field, va_list ap) else if (c <= 0x7F || (MB_CUR_MAX == 1 && c <= 0xFF)) { field->str_size = (field->fl_witdth > 1) ? field->fl_witdth : 1; - if (!(output = ft_strnewb(field->str_size))) + if (!(output = ft_strnew(field->str_size))) return (NULL); output[0] = (char)c; ft_align_wchar(output, field); diff --git a/ft_printf_tools_wstr.c b/ft_printf_tools_wstr.c index c74f216..762dc88 100644 --- a/ft_printf_tools_wstr.c +++ b/ft_printf_tools_wstr.c @@ -6,11 +6,11 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/23 19:48:06 by klebon #+# #+# */ -/* Updated: 2018/10/01 15:41:10 by klebon ### ########.fr */ +/* Updated: 2019/03/07 22:25:19 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ -#include "libftprintf.h" +#include "libft.h" void handler_2oct_wstr(wint_t c, char *output, int *i) { @@ -81,7 +81,7 @@ char *handle_output_wstr(t_conv *field, va_list ap) field->fl_prec = field->str_size; if (field->fl_witdth > field->str_size) field->str_size += (field->fl_witdth - field->str_size); - if (!(output = ft_strnewb(field->str_size))) + if (!(output = ft_strnew(field->str_size))) return (NULL); convert_wstr_to_str(str, output, field); ft_align_wstr(output, field);