From acf5431d1458dc07ea37302d134d7125f15aebf0 Mon Sep 17 00:00:00 2001 From: Tanguy MAZE Date: Sat, 16 Mar 2019 17:50:27 +0100 Subject: [PATCH] hidden norm cleanup --- Makefile | 4 +- ft_atoi.c | 4 +- ft_atois.c | 6 +- ft_gets.c | 3 +- ft_printf_tools_wchar_t.c | 6 +- ft_strjoin.c | 6 +- ft_strlcat.c | 6 +- ft_strncmp.c | 6 +- ft_strnstr.c | 4 +- ft_strsplitwhitespace.c | 4 +- get_next_line.c | 10 +-- libft.h | 151 +++++++++++++++++++------------------- 12 files changed, 104 insertions(+), 106 deletions(-) diff --git a/Makefile b/Makefile index d9a6bbb..2cb28df 100644 --- a/Makefile +++ b/Makefile @@ -6,12 +6,12 @@ # By: tmaze +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2018/04/07 12:47:06 by tmaze #+# #+# # -# Updated: 2019/03/07 22:26:45 by tmaze ### ########.fr # +# Updated: 2019/03/16 16:26:40 by tmaze ### ########.fr # # # #******************************************************************************# CC = gcc -CCFLAGS = -Wall -Werror -Wextra -g +CCFLAGS = -Wall -Werror -Wextra CCSTD = NAME = libft.a diff --git a/ft_atoi.c b/ft_atoi.c index 9e08b71..7614ed7 100644 --- a/ft_atoi.c +++ b/ft_atoi.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/05 13:50:22 by tmaze #+# #+# */ -/* Updated: 2018/04/09 10:04:51 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:37:42 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ int ft_atoi(const char *str) int ret; nbnum = 0; - while (str[nbnum] == ' ' || str[nbnum] == '\t' || str[nbnum] == '\n'\ + while (str[nbnum] == ' ' || str[nbnum] == '\t' || str[nbnum] == '\n' || str[nbnum] == '\v' || str[nbnum] == '\f' || str[nbnum] == '\r') nbnum++; if (str[nbnum] == '+' || str[nbnum] == '-') diff --git a/ft_atois.c b/ft_atois.c index 95f198c..f0c20a0 100644 --- a/ft_atois.c +++ b/ft_atois.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/27 11:58:44 by tmaze #+# #+# */ -/* Updated: 2019/02/28 16:12:07 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:47:50 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,8 +29,8 @@ int ft_atois(const char *str, int *nb) num--; *nb = 0; mult = 1; - while (num >= 0 && ft_isdigit(str[num]) && - (ft_abs(max - *nb) >= 2000000000)) + while (num >= 0 && ft_isdigit(str[num]) + && (ft_abs(max - *nb) >= 2000000000)) { *nb += (str[num--] - '0') * mult; mult *= 10; diff --git a/ft_gets.c b/ft_gets.c index f522a57..cbc28b9 100644 --- a/ft_gets.c +++ b/ft_gets.c @@ -6,9 +6,8 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/08 13:44:31 by tmaze #+# #+# */ -/* Updated: 2019/03/08 14:11:38 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:33:26 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" - diff --git a/ft_printf_tools_wchar_t.c b/ft_printf_tools_wchar_t.c index e5f1c7b..d48cfc7 100644 --- a/ft_printf_tools_wchar_t.c +++ b/ft_printf_tools_wchar_t.c @@ -6,16 +6,12 @@ /* By: klebon +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/05/18 18:10:11 by klebon #+# #+# */ -/* Updated: 2019/03/07 22:25:11 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:53:50 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -/* -** I have to handle minus, width -*/ - void ft_align_wchar(char *str, t_conv *field) { int i; diff --git a/ft_strjoin.c b/ft_strjoin.c index 768d3f3..c497930 100644 --- a/ft_strjoin.c +++ b/ft_strjoin.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/07 16:30:47 by tmaze #+# #+# */ -/* Updated: 2019/03/07 19:05:27 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:39:59 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,8 @@ char *ft_strjoin(char const *s1, char const *s2) char *ret; ret = NULL; - if (s1 != NULL && s2 != NULL &&\ - (ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) != NULL) + if (s1 != NULL && s2 != NULL + && (ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) != NULL) { ft_strcpy(ret, s1); ft_strcat(ret, s2); diff --git a/ft_strlcat.c b/ft_strlcat.c index 3505d7e..d83c5fc 100644 --- a/ft_strlcat.c +++ b/ft_strlcat.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/08 14:32:30 by tmaze #+# #+# */ -/* Updated: 2018/04/08 15:15:34 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:45:42 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,6 @@ size_t ft_strlcat(char *dest, const char *src, size_t size) ft_strncpy(&dest[dest_len], src, size - dest_len); dest[size - 1] = '\0'; } - return (((size_t)dest_len < size) ? (size_t)(dest_len + ft_strlen(src)) :\ - size + (size_t)ft_strlen(src)); + return (((size_t)dest_len < size) ? (size_t)(dest_len + ft_strlen(src)) + : size + (size_t)ft_strlen(src)); } diff --git a/ft_strncmp.c b/ft_strncmp.c index feb1839..9417e2a 100644 --- a/ft_strncmp.c +++ b/ft_strncmp.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/05 13:04:21 by tmaze #+# #+# */ -/* Updated: 2018/04/08 14:05:37 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:50:07 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,8 +21,8 @@ int ft_strncmp(const char *s1, const char *s2, size_t n) diff = 0; if (n > 0) diff = (unsigned char)s1[0] - (unsigned char)s2[0]; - while ((unsigned int)i < n && diff == 0 && (unsigned char)s1[i - 1] &&\ - (unsigned char)s2[i - 1]) + while ((unsigned int)i < n && diff == 0 && (unsigned char)s1[i - 1] + && (unsigned char)s2[i - 1]) { diff = (unsigned char)s1[i] - (unsigned char)s2[i]; i++; diff --git a/ft_strnstr.c b/ft_strnstr.c index f598c51..4f2ab5f 100644 --- a/ft_strnstr.c +++ b/ft_strnstr.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/05 11:35:03 by tmaze #+# #+# */ -/* Updated: 2018/04/08 15:28:28 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:52:25 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,7 @@ char *ft_strnstr(const char *haystack, const char *needle, size_t len) while ((++i == 0 || tmp[i - 1]) && i < (int)len) if (tmp[i] == needle[0] && (j = 1)) { - while (tmp[i + j] == needle[j] && needle[j] && tmp[i + j]\ + while (tmp[i + j] == needle[j] && needle[j] && tmp[i + j] && (i + j) < (int)len) j++; if (needle[j] == '\0') diff --git a/ft_strsplitwhitespace.c b/ft_strsplitwhitespace.c index 4b63b77..6c6b4e3 100644 --- a/ft_strsplitwhitespace.c +++ b/ft_strsplitwhitespace.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/25 16:25:18 by tmaze #+# #+# */ -/* Updated: 2019/02/28 16:22:02 by tmaze ### ########.fr */ +/* Updated: 2019/03/09 15:13:49 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,7 +70,7 @@ char **ft_strsplitwhitespace(char *s) if (s != NULL) { nb_words = count_words_ws(s); - if ((tab = (char**)malloc(sizeof(char**) * (nb_words + 1))) == NULL) + if ((tab = (char**)malloc(sizeof(char*) * (nb_words + 1))) == NULL) return (NULL); tab[nb_words] = NULL; return (get_table_ws(s, tab)); diff --git a/get_next_line.c b/get_next_line.c index fda7155..7a6c6b5 100644 --- a/get_next_line.c +++ b/get_next_line.c @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/24 18:08:15 by tmaze #+# #+# */ -/* Updated: 2018/06/07 16:55:21 by tmaze ### ########.fr */ +/* Updated: 2019/03/16 15:53:27 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -61,16 +61,16 @@ static int read_gnl(const int fd, char **buff, char **line) if ((tmp = ft_strnew(BUFF_SIZE)) == NULL) return (-1); - while (ft_strrnchr(*buff, '\n', BUFF_SIZE) == NULL &&\ - (ret = read(fd, tmp, BUFF_SIZE)) > 0) + while (ft_strrnchr(*buff, '\n', BUFF_SIZE) == NULL + && (ret = read(fd, tmp, BUFF_SIZE)) > 0) if (supercat(buff, &tmp) == NULL) { ft_strdel(&tmp); return (-1); } ft_strdel(&tmp); - if (buff != NULL && *buff != NULL &&\ - ft_strrnchr(*buff, '\n', BUFF_SIZE) != NULL) + if (buff != NULL && *buff != NULL + && ft_strrnchr(*buff, '\n', BUFF_SIZE) != NULL) return (get_next_line(fd, line)); else return (check_buff(buff, line)); diff --git a/libft.h b/libft.h index a3b40c0..0316c45 100644 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: tmaze +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/04/08 00:12:36 by tmaze #+# #+# */ -/* Updated: 2019/03/08 13:27:16 by tmaze ### ########.fr */ +/* Updated: 2019/03/15 14:48:19 by tmaze ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,7 @@ # define FT_RESET "\x1b[0m" # define FT_BOLD "\x1b[1m" +# define FT_CLEAR "\x1b[2J" # define FT_COLOR_BLACK "\x1b[30m" # define FT_COLOR_RED "\x1b[31m" @@ -66,13 +67,13 @@ typedef struct s_list ** definition type t_file */ -typedef struct s_file +typedef struct s_file { - int fd; - char buff[BUFF_SIZE + 1]; -} t_file; + int fd; + char buff[BUFF_SIZE + 1]; +} t_file; -enum e_size +enum e_size { h, hh, @@ -83,7 +84,7 @@ enum e_size L }; -enum e_type +enum e_type { p, d, @@ -103,134 +104,136 @@ enum e_type f }; -typedef struct s_conv +typedef struct s_conv { - int fl_minus; - int fl_plus; - int fl_zero; - int fl_hashtag; - int fl_space; - int fl_witdth; - int fl_prec; - enum e_size fl_size; - enum e_type fl_type; - char *str; - int str_size; -} t_conv; + int fl_minus; + int fl_plus; + int fl_zero; + int fl_hashtag; + int fl_space; + int fl_witdth; + int fl_prec; + enum e_size fl_size; + enum e_type fl_type; + char *str; + int str_size; +} t_conv; /* ** Print functions */ -int ft_printf(const char *format, ...); -void ft_putchar(char c); -void ft_putnbr(int n); -void ft_putstr(char const *s); +int ft_printf(const char *format, ...); +void ft_putchar(char c); +void ft_putnbr(int n); +void ft_putstr(char const *s); /* ** ft_printf tools */ -void init_struct_conv(t_conv *field); -void ft_align_str_zero(char *str, t_conv *field); -void ft_align_str(char *str, t_conv *field); -void set_malloc_sizes(uintmax_t nb, t_conv *field); -void set_malloc_sizeu(uintmax_t nb, t_conv *field); -void set_malloc_sizeo(uintmax_t nb, t_conv *field); -void set_malloc_sizeu(uintmax_t nb, t_conv *field); -int set_malloc_sizef(long double nb, char *nbrstr, t_conv *field); -void init_handler_tab(char *(*f[14])(t_conv *, va_list)); -int ft_wstrlen(const wint_t *str); -uint64_t dmod(long double nb, long double mod); +void init_struct_conv(t_conv *field); +void ft_align_str_zero(char *str, t_conv *field); +void ft_align_str(char *str, t_conv *field); +void set_malloc_sizes(uintmax_t nb, t_conv *field); +void set_malloc_sizeu(uintmax_t nb, t_conv *field); +void set_malloc_sizeo(uintmax_t nb, t_conv *field); +void set_malloc_sizeu(uintmax_t nb, t_conv *field); +int set_malloc_sizef(long double nb, char *nbrstr + , t_conv *field); +void init_handler_tab(char *(*f[14])(t_conv *, va_list)); +int ft_wstrlen(const wint_t *str); +uint64_t dmod(long double nb, long double mod); /* ** Check Flags */ -void check_flags(const char **str, t_conv *field); -void check_width(const char **str, t_conv *field, va_list ap); -ssize_t check_precision(const char **str, t_conv *field, va_list ap); -void check_size(const char **str, t_conv *field); -ssize_t check_type_one(const char **str, t_conv *field); -ssize_t check_type_two(const char **str, t_conv *field); -ssize_t check_fields(const char **str, va_list ap, t_conv *field); +void check_flags(const char **str, t_conv *field); +void check_width(const char **str, t_conv *field, va_list ap); +ssize_t check_precision(const char **str, t_conv *field + , va_list ap); +void check_size(const char **str, t_conv *field); +ssize_t check_type_one(const char **str, t_conv *field); +ssize_t check_type_two(const char **str, t_conv *field); +ssize_t check_fields(const char **str, va_list ap, t_conv *field); /* ** Handle type i and d */ -char *handler_int(uintmax_t nb, t_conv *field); -char *select_int_handler(t_conv *field, va_list ap); -char *handle_output_i_d(t_conv *field, va_list ap); +char *handler_int(uintmax_t nb, t_conv *field); +char *select_int_handler(t_conv *field, va_list ap); +char *handle_output_i_d(t_conv *field, va_list ap); /* ** Handle type u */ -char *select_uns_int_handler(t_conv *field, va_list ap); -char *handle_output_u(t_conv *field, va_list ap); -char *handler_uns(uintmax_t nb, t_conv *field); +char *select_uns_int_handler(t_conv *field, va_list ap); +char *handle_output_u(t_conv *field, va_list ap); +char *handler_uns(uintmax_t nb, t_conv *field); /* ** Handle type x and X */ -char *handler_hexa(uintmax_t nb, t_conv *field); -char *select_hexa_handler(t_conv *field, va_list ap); -char *handle_output_hexa(t_conv *field, va_list ap); -void ft_align_hex_zero(char *str, t_conv *field); -void ft_align_hex(char *str, t_conv *field); -int set_precision_sizex(uintmax_t nb, t_conv *field); -void set_malloc_sizeh(uintmax_t nb, t_conv *field); +char *handler_hexa(uintmax_t nb, t_conv *field); +char *select_hexa_handler(t_conv *field, va_list ap); +char *handle_output_hexa(t_conv *field, va_list ap); +void ft_align_hex_zero(char *str, t_conv *field); +void ft_align_hex(char *str, t_conv *field); +int set_precision_sizex(uintmax_t nb, t_conv *field); +void set_malloc_sizeh(uintmax_t nb, t_conv *field); /* ** Handle type o */ -char *handler_oct(uintmax_t nb, t_conv *field); -char *select_oct_handler(t_conv *field, va_list ap); -char *handle_output_oct(t_conv *field, va_list ap); -void ft_align_oct_zero(char *str, t_conv *field); -void ft_align_oct(char *str, t_conv *field); -int set_precision_sizeo(uintmax_t nb, t_conv *field); +char *handler_oct(uintmax_t nb, t_conv *field); +char *select_oct_handler(t_conv *field, va_list ap); +char *handle_output_oct(t_conv *field, va_list ap); +void ft_align_oct_zero(char *str, t_conv *field); +void ft_align_oct(char *str, t_conv *field); +int set_precision_sizeo(uintmax_t nb, t_conv *field); /* ** Handle type c */ -char *handle_output_char(t_conv *field, va_list ap); +char *handle_output_char(t_conv *field, va_list ap); /* ** Handle type C */ -unsigned int ft_bin_size(unsigned int nb); -void ft_align_wchar(char *str, t_conv *field); -char *handler_2oct_char(wint_t c, t_conv *field); -char *handler_3oct_char(wint_t c, t_conv *field); -char *handler_4oct_char(wint_t c, t_conv *field); -char *handle_output_wchar(t_conv *field, va_list ap); +unsigned int ft_bin_size(unsigned int nb); +void ft_align_wchar(char *str, t_conv *field); +char *handler_2oct_char(wint_t c, t_conv *field); +char *handler_3oct_char(wint_t c, t_conv *field); +char *handler_4oct_char(wint_t c, t_conv *field); +char *handle_output_wchar(t_conv *field, va_list ap); /* ** Handle type s */ -char *handle_output_str(t_conv *field, va_list ap); -void ft_align_wstr(char *str, t_conv *field); -int set_precision_sizes(uintmax_t nb, t_conv *field); +char *handle_output_str(t_conv *field, va_list ap); +void ft_align_wstr(char *str, t_conv *field); +int set_precision_sizes(uintmax_t nb, t_conv *field); /* ** Handle type S */ -char *handle_output_wstr(t_conv *field, va_list ap); -int set_prec_size_wstr(const wint_t *str, t_conv *field); +char *handle_output_wstr(t_conv *field, va_list ap); +int set_prec_size_wstr(const wint_t *str, t_conv *field); /* ** Handle type f */ -char *handle_output_float(t_conv *field, va_list ap); +char *handle_output_float(t_conv *field, va_list ap); /* ** fonctions obligatoires