hidden norm cleanup

This commit is contained in:
Tanguy MAZE 2019-03-16 17:50:27 +01:00
parent d49f964045
commit acf5431d14
12 changed files with 104 additions and 106 deletions

View File

@ -6,12 +6,12 @@
# By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ # # By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2018/04/07 12:47:06 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 CC = gcc
CCFLAGS = -Wall -Werror -Wextra -g CCFLAGS = -Wall -Werror -Wextra
CCSTD = CCSTD =
NAME = libft.a NAME = libft.a

View File

@ -6,7 +6,7 @@
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */ /* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/05 13:50:22 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; int ret;
nbnum = 0; 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') || str[nbnum] == '\v' || str[nbnum] == '\f' || str[nbnum] == '\r')
nbnum++; nbnum++;
if (str[nbnum] == '+' || str[nbnum] == '-') if (str[nbnum] == '+' || str[nbnum] == '-')

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/27 11:58:44 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--; num--;
*nb = 0; *nb = 0;
mult = 1; mult = 1;
while (num >= 0 && ft_isdigit(str[num]) && while (num >= 0 && ft_isdigit(str[num])
(ft_abs(max - *nb) >= 2000000000)) && (ft_abs(max - *nb) >= 2000000000))
{ {
*nb += (str[num--] - '0') * mult; *nb += (str[num--] - '0') * mult;
mult *= 10; mult *= 10;

View File

@ -6,9 +6,8 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/08 13:44:31 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" #include "libft.h"

View File

@ -6,16 +6,12 @@
/* By: klebon <klebon@student.42.fr> +#+ +:+ +#+ */ /* By: klebon <klebon@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/18 18:10:11 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" #include "libft.h"
/*
** I have to handle minus, width
*/
void ft_align_wchar(char *str, t_conv *field) void ft_align_wchar(char *str, t_conv *field)
{ {
int i; int i;

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/07 16:30:47 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; char *ret;
ret = NULL; ret = NULL;
if (s1 != NULL && s2 != NULL &&\ if (s1 != NULL && s2 != NULL
(ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) != NULL) && (ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) != NULL)
{ {
ft_strcpy(ret, s1); ft_strcpy(ret, s1);
ft_strcat(ret, s2); ft_strcat(ret, s2);

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/08 14:32:30 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); ft_strncpy(&dest[dest_len], src, size - dest_len);
dest[size - 1] = '\0'; dest[size - 1] = '\0';
} }
return (((size_t)dest_len < size) ? (size_t)(dest_len + ft_strlen(src)) :\ return (((size_t)dest_len < size) ? (size_t)(dest_len + ft_strlen(src))
size + (size_t)ft_strlen(src)); : size + (size_t)ft_strlen(src));
} }

View File

@ -6,7 +6,7 @@
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */ /* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/05 13:04:21 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; diff = 0;
if (n > 0) if (n > 0)
diff = (unsigned char)s1[0] - (unsigned char)s2[0]; diff = (unsigned char)s1[0] - (unsigned char)s2[0];
while ((unsigned int)i < n && diff == 0 && (unsigned char)s1[i - 1] &&\ while ((unsigned int)i < n && diff == 0 && (unsigned char)s1[i - 1]
(unsigned char)s2[i - 1]) && (unsigned char)s2[i - 1])
{ {
diff = (unsigned char)s1[i] - (unsigned char)s2[i]; diff = (unsigned char)s1[i] - (unsigned char)s2[i];
i++; i++;

View File

@ -6,7 +6,7 @@
/* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */ /* By: tmaze <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/05 11:35:03 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) while ((++i == 0 || tmp[i - 1]) && i < (int)len)
if (tmp[i] == needle[0] && (j = 1)) 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) && (i + j) < (int)len)
j++; j++;
if (needle[j] == '\0') if (needle[j] == '\0')

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/25 16:25:18 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) if (s != NULL)
{ {
nb_words = count_words_ws(s); 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); return (NULL);
tab[nb_words] = NULL; tab[nb_words] = NULL;
return (get_table_ws(s, tab)); return (get_table_ws(s, tab));

View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/24 18:08:15 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) if ((tmp = ft_strnew(BUFF_SIZE)) == NULL)
return (-1); return (-1);
while (ft_strrnchr(*buff, '\n', BUFF_SIZE) == NULL &&\ while (ft_strrnchr(*buff, '\n', BUFF_SIZE) == NULL
(ret = read(fd, tmp, BUFF_SIZE)) > 0) && (ret = read(fd, tmp, BUFF_SIZE)) > 0)
if (supercat(buff, &tmp) == NULL) if (supercat(buff, &tmp) == NULL)
{ {
ft_strdel(&tmp); ft_strdel(&tmp);
return (-1); return (-1);
} }
ft_strdel(&tmp); ft_strdel(&tmp);
if (buff != NULL && *buff != NULL &&\ if (buff != NULL && *buff != NULL
ft_strrnchr(*buff, '\n', BUFF_SIZE) != NULL) && ft_strrnchr(*buff, '\n', BUFF_SIZE) != NULL)
return (get_next_line(fd, line)); return (get_next_line(fd, line));
else else
return (check_buff(buff, line)); return (check_buff(buff, line));

151
libft.h
View File

@ -6,7 +6,7 @@
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */ /* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2018/04/08 00:12:36 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_RESET "\x1b[0m"
# define FT_BOLD "\x1b[1m" # define FT_BOLD "\x1b[1m"
# define FT_CLEAR "\x1b[2J"
# define FT_COLOR_BLACK "\x1b[30m" # define FT_COLOR_BLACK "\x1b[30m"
# define FT_COLOR_RED "\x1b[31m" # define FT_COLOR_RED "\x1b[31m"
@ -66,13 +67,13 @@ typedef struct s_list
** definition type t_file ** definition type t_file
*/ */
typedef struct s_file typedef struct s_file
{ {
int fd; int fd;
char buff[BUFF_SIZE + 1]; char buff[BUFF_SIZE + 1];
} t_file; } t_file;
enum e_size enum e_size
{ {
h, h,
hh, hh,
@ -83,7 +84,7 @@ enum e_size
L L
}; };
enum e_type enum e_type
{ {
p, p,
d, d,
@ -103,134 +104,136 @@ enum e_type
f f
}; };
typedef struct s_conv typedef struct s_conv
{ {
int fl_minus; int fl_minus;
int fl_plus; int fl_plus;
int fl_zero; int fl_zero;
int fl_hashtag; int fl_hashtag;
int fl_space; int fl_space;
int fl_witdth; int fl_witdth;
int fl_prec; int fl_prec;
enum e_size fl_size; enum e_size fl_size;
enum e_type fl_type; enum e_type fl_type;
char *str; char *str;
int str_size; int str_size;
} t_conv; } t_conv;
/* /*
** Print functions ** Print functions
*/ */
int ft_printf(const char *format, ...); int ft_printf(const char *format, ...);
void ft_putchar(char c); void ft_putchar(char c);
void ft_putnbr(int n); void ft_putnbr(int n);
void ft_putstr(char const *s); void ft_putstr(char const *s);
/* /*
** ft_printf tools ** ft_printf tools
*/ */
void init_struct_conv(t_conv *field); void init_struct_conv(t_conv *field);
void ft_align_str_zero(char *str, t_conv *field); void ft_align_str_zero(char *str, t_conv *field);
void ft_align_str(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_sizes(uintmax_t nb, t_conv *field);
void set_malloc_sizeu(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_sizeo(uintmax_t nb, t_conv *field);
void set_malloc_sizeu(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); int set_malloc_sizef(long double nb, char *nbrstr
void init_handler_tab(char *(*f[14])(t_conv *, va_list)); , t_conv *field);
int ft_wstrlen(const wint_t *str); void init_handler_tab(char *(*f[14])(t_conv *, va_list));
uint64_t dmod(long double nb, long double mod); int ft_wstrlen(const wint_t *str);
uint64_t dmod(long double nb, long double mod);
/* /*
** Check Flags ** Check Flags
*/ */
void check_flags(const char **str, t_conv *field); void check_flags(const char **str, t_conv *field);
void check_width(const char **str, t_conv *field, va_list ap); 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); ssize_t check_precision(const char **str, t_conv *field
void check_size(const char **str, t_conv *field); , va_list ap);
ssize_t check_type_one(const char **str, t_conv *field); void check_size(const char **str, t_conv *field);
ssize_t check_type_two(const char **str, t_conv *field); ssize_t check_type_one(const char **str, t_conv *field);
ssize_t check_fields(const char **str, va_list ap, 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 ** Handle type i and d
*/ */
char *handler_int(uintmax_t nb, t_conv *field); char *handler_int(uintmax_t nb, t_conv *field);
char *select_int_handler(t_conv *field, va_list ap); char *select_int_handler(t_conv *field, va_list ap);
char *handle_output_i_d(t_conv *field, va_list ap); char *handle_output_i_d(t_conv *field, va_list ap);
/* /*
** Handle type u ** Handle type u
*/ */
char *select_uns_int_handler(t_conv *field, va_list ap); char *select_uns_int_handler(t_conv *field, va_list ap);
char *handle_output_u(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 *handler_uns(uintmax_t nb, t_conv *field);
/* /*
** Handle type x and X ** Handle type x and X
*/ */
char *handler_hexa(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 *select_hexa_handler(t_conv *field, va_list ap);
char *handle_output_hexa(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_zero(char *str, t_conv *field);
void ft_align_hex(char *str, t_conv *field); void ft_align_hex(char *str, t_conv *field);
int set_precision_sizex(uintmax_t nb, t_conv *field); int set_precision_sizex(uintmax_t nb, t_conv *field);
void set_malloc_sizeh(uintmax_t nb, t_conv *field); void set_malloc_sizeh(uintmax_t nb, t_conv *field);
/* /*
** Handle type o ** Handle type o
*/ */
char *handler_oct(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 *select_oct_handler(t_conv *field, va_list ap);
char *handle_output_oct(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_zero(char *str, t_conv *field);
void ft_align_oct(char *str, t_conv *field); void ft_align_oct(char *str, t_conv *field);
int set_precision_sizeo(uintmax_t nb, t_conv *field); int set_precision_sizeo(uintmax_t nb, t_conv *field);
/* /*
** Handle type c ** 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 ** Handle type C
*/ */
unsigned int ft_bin_size(unsigned int nb); unsigned int ft_bin_size(unsigned int nb);
void ft_align_wchar(char *str, t_conv *field); void ft_align_wchar(char *str, t_conv *field);
char *handler_2oct_char(wint_t c, 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_3oct_char(wint_t c, t_conv *field);
char *handler_4oct_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); char *handle_output_wchar(t_conv *field, va_list ap);
/* /*
** Handle type s ** Handle type s
*/ */
char *handle_output_str(t_conv *field, va_list ap); char *handle_output_str(t_conv *field, va_list ap);
void ft_align_wstr(char *str, t_conv *field); void ft_align_wstr(char *str, t_conv *field);
int set_precision_sizes(uintmax_t nb, t_conv *field); int set_precision_sizes(uintmax_t nb, t_conv *field);
/* /*
** Handle type S ** Handle type S
*/ */
char *handle_output_wstr(t_conv *field, va_list ap); char *handle_output_wstr(t_conv *field, va_list ap);
int set_prec_size_wstr(const wint_t *str, t_conv *field); int set_prec_size_wstr(const wint_t *str, t_conv *field);
/* /*
** Handle type f ** 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 ** fonctions obligatoires