/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_printf.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jguelen +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/06 09:22:02 by jguelen #+# #+# */ /* Updated: 2025/02/04 09:48:18 by jguelen ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef FT_PRINTF_H # define FT_PRINTF_H # include "libft/libft.h" # include # include # define PRINTF_SPECLIST "cspdiuxX%" # define PRINTF_FLAGS "#+ -0" # define HEXA_UP "0123456789ABCDEF" # define HEXA_LOW "0123456789abcdef" # define HEXA_RADIX_LOW "0x" # define HEXA_RADIX_UP "0X" # define HEX_LEN 16 typedef enum e_printf_spec { PRINTF_NOSPEC = 0, PRINTF_CHARSPEC = 1, PRINTF_STRINGSPEC = 2, PRINTF_POINTERSPEC = 3, PRINTF_INTSPEC = 4, PRINTF_UINTSPEC = 5, PRINTF_HEXA_LOWSPEC = 6, PRINTF_HEXA_UPSPEC = 7, PRINTF_PERCENTSPEC = 8 } t_printf_spec; typedef enum e_printf_flags { PRINTF_NOFLAG = 0, PRINTF_PLUSFLAG = 1, PRINTF_MINUSFLAG = 2, PRINTF_SPACEFLAG = 4, PRINTF_ZEROFLAG = 8, PRINTF_HASHTAGFLAG = 16, PRINTF_DOTFLAG = 32, } t_printf_flags; typedef union u_printf_var { char c; char *s; void *p; int i; unsigned int u; } t_printf_var; /*precision and minwith are to store integers but use long to deal with errors.*/ typedef struct s_printf_format { t_printf_flags flags; t_printf_spec specifier; t_printf_var var; long minwidth; long precision; char prefix[3]; int prefix_len; int total_len; } t_printf_format; int ft_dprintf(int fd, const char *s, ...); int ft_printf(const char *s, ...); int ft_print_printf_format(int fd, t_printf_format *format); /*ft_printf_parsing*/ int ft_printf_parsing(int fd, char *s, t_printf_format *format, va_list *arg_list); /*ft_printf_atoi*/ long ft_printf_atoi(char *str, char **current); /*ft_printf_utils*/ int ft_int_len(int n, int base_len); int ft_uint_len(unsigned int n, int base_len); int ft_ull_len(unsigned long long n, int base_len); /*Takes precision into account when relevant.*/ int var_len(t_printf_format *format); /*ft_printf_utils2*/ void get_prefix_format(t_printf_format *format); /**/ int ft_printf_str(int fd, const char *str, int maxchar); int ft_pad_char(int fd, t_printf_format *format, char *c); int ft_printf_badspec(int fd, t_printf_format *format); int ft_printf_char(int fd, t_printf_format *format); int ft_printf_string(int fd, t_printf_format *format); int ft_printf_ptr(int fd, t_printf_format *format); int ft_printf_int(int fd, t_printf_format *format); int ft_printf_uint(int fd, t_printf_format *format); int ft_printf_hexa(int fd, t_printf_format *format); int ft_printf_percent(int fd, t_printf_format *format); int ft_put_ull_base_fd(unsigned long long n, char *base, int base_size, int fd); int ft_isnumeric_conv(t_printf_format *format); #endif