printf fixed for norm, need to migrate all this to real printf repo
This commit is contained in:
parent
f54e802fa7
commit
ed8b34bc5d
22 changed files with 228 additions and 115 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:22:54 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:26:50 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 17:26:13 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -18,20 +18,20 @@
|
||||||
# define ALL_CONVERSIONS "sSpdDioOuUxXcCb"
|
# define ALL_CONVERSIONS "sSpdDioOuUxXcCb"
|
||||||
|
|
||||||
typedef struct s_fmt t_fmt;
|
typedef struct s_fmt t_fmt;
|
||||||
|
typedef struct s_conv t_conv;
|
||||||
typedef char *(t_converter)(t_fmt *fmt, va_list ap);
|
typedef char *(t_converter)(t_fmt *fmt, va_list ap);
|
||||||
typedef void (t_sharp_func)(char *str, t_fmt *fmt);
|
typedef void (t_pad_func)(char *str, t_fmt *fmt);
|
||||||
|
|
||||||
typedef struct s_conv
|
struct s_conv
|
||||||
{
|
{
|
||||||
char id;
|
char id;
|
||||||
char allowed_flags[6];
|
char allowed_flags[6];
|
||||||
char base[20];
|
char base[20];
|
||||||
t_converter *converter;
|
t_converter *converter;
|
||||||
t_sharp_func *sharp_func;
|
t_pad_func *sharp_func;
|
||||||
} t_conv;
|
};
|
||||||
|
|
||||||
typedef struct s_fmt
|
struct s_fmt
|
||||||
{
|
{
|
||||||
char flags[6];
|
char flags[6];
|
||||||
int width;
|
int width;
|
||||||
|
|
@ -40,7 +40,7 @@ typedef struct s_fmt
|
||||||
char conversion;
|
char conversion;
|
||||||
int valid;
|
int valid;
|
||||||
t_conv conv;
|
t_conv conv;
|
||||||
} t_fmt;
|
};
|
||||||
|
|
||||||
extern t_conv g_convs[];
|
extern t_conv g_convs[];
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ void ft_fmt_error_flag_conv(char flag, char conv);
|
||||||
void ft_fmt_error_flag_flag(char flag1, char flag2);
|
void ft_fmt_error_flag_flag(char flag1, char flag2);
|
||||||
|
|
||||||
void ft_fmt_simplify(t_fmt *fmt);
|
void ft_fmt_simplify(t_fmt *fmt);
|
||||||
int ft_fmt_validate_conversion(t_fmt *fmt);
|
int ft_fmt_validate_conv(t_fmt *fmt);
|
||||||
void ft_fmt_validate_flags(t_fmt *fmt);
|
void ft_fmt_validate_flags(t_fmt *fmt);
|
||||||
void ft_fmt_validate_mod(t_fmt *fmt);
|
void ft_fmt_validate_mod(t_fmt *fmt);
|
||||||
|
|
||||||
|
|
@ -72,7 +72,6 @@ char *ft_char_conversion(t_fmt *fmt, va_list ap);
|
||||||
|
|
||||||
void ft_pad_sharp_o(char *str, t_fmt *fmt);
|
void ft_pad_sharp_o(char *str, t_fmt *fmt);
|
||||||
void ft_pad_sharp_xb(char *str, t_fmt *fmt);
|
void ft_pad_sharp_xb(char *str, t_fmt *fmt);
|
||||||
|
|
||||||
void ft_pad_left(char *str, t_fmt *fmt);
|
void ft_pad_left(char *str, t_fmt *fmt);
|
||||||
void ft_pad_right(char *str, t_fmt *fmt);
|
void ft_pad_right(char *str, t_fmt *fmt);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:49:04 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:55:26 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 15:46:27 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -94,14 +94,17 @@ char *ft_strcut(char *str, char *cut);
|
||||||
char **ft_split_whitespaces(char *str);
|
char **ft_split_whitespaces(char *str);
|
||||||
char *ft_convert_base(
|
char *ft_convert_base(
|
||||||
char *str, char *base_from, char *base_to, char *flags);
|
char *str, char *base_from, char *base_to, char *flags);
|
||||||
|
char *ft_strcatf(char *s1, const char *s2);
|
||||||
|
|
||||||
char *ft_itoa_base(int nbr, char *base, char *flags);
|
char *ft_itoa_base(int nbr, char *base, char *flags);
|
||||||
char *ft_lltoa_base(long long nbr, char *base, char *flags);
|
char *ft_lltoa_base(long long nbr, char *base, char *flags);
|
||||||
char *ft_ulltoa_base(unsigned long long nbr, char *base);
|
char *ft_ulltoa_base(unsigned long long nbr, char *base);
|
||||||
char *ft_uitoa_base(unsigned int nbr, char *base);
|
char *ft_uitoa_base(unsigned int nbr, char *base);
|
||||||
size_t ft_ilen(int n);
|
size_t ft_ilen(int n);
|
||||||
|
size_t ft_ilen_base(int n, int base);
|
||||||
size_t ft_uilen(unsigned int n);
|
size_t ft_uilen(unsigned int n);
|
||||||
size_t ft_lllen(long long n);
|
size_t ft_lllen(long long n);
|
||||||
|
size_t ft_lllen_base(long long n, int base);
|
||||||
|
|
||||||
void ft_sstrsort(char **list, int size, int (*cmp)());
|
void ft_sstrsort(char **list, int size, int (*cmp)());
|
||||||
void ft_sstrprint(char **list, char sep);
|
void ft_sstrprint(char **list, char sep);
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,15 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:31:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:48:59 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 16:56:28 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ftprintf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
char *ft_signed_conversion(t_fmt *fmt, va_list ap)
|
char *ft_signed_conversion(t_fmt *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
char base10[10];
|
char base10[11];
|
||||||
long long arg;
|
long long arg;
|
||||||
|
|
||||||
arg = va_arg(ap, int);
|
arg = va_arg(ap, int);
|
||||||
|
|
|
||||||
31
libft/src/ft_printf/ft_fmt_simplify.c
Normal file
31
libft/src/ft_printf/ft_fmt_simplify.c
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* lib_fmt_validate.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:33:43 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:53:54 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_fmt_simplify(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
char hashtag;
|
||||||
|
|
||||||
|
hashtag = '#';
|
||||||
|
if (fmt->conversion == 'p')
|
||||||
|
{
|
||||||
|
fmt->conversion = 'x';
|
||||||
|
if (!ft_strchr(fmt->flags, '#'))
|
||||||
|
ft_strncat(fmt->flags, &hashtag, 1);
|
||||||
|
}
|
||||||
|
if (ft_strchr("DOUCS", fmt->conversion))
|
||||||
|
{
|
||||||
|
fmt->conversion += 32;
|
||||||
|
ft_strcpy(fmt->modifier, "l");
|
||||||
|
}
|
||||||
|
}
|
||||||
24
libft/src/ft_printf/ft_fmt_validate_conv.c
Normal file
24
libft/src/ft_printf/ft_fmt_validate_conv.c
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_fmt_validate_conv.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 16:55:36 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:55:37 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
int ft_fmt_validate_conv(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
if (!ft_strchr(ALL_CONVERSIONS, fmt->conversion))
|
||||||
|
{
|
||||||
|
if (fmt->conversion != '%')
|
||||||
|
ft_fmt_error_conv(fmt->conversion);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
@ -1,67 +1,21 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* lib_fmt_validate.c :+: :+: :+: */
|
/* ft_fmt_validate_flags.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:43 by jhalford #+# #+# */
|
/* Created: 2016/11/07 16:53:07 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:51:29 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 17:25:47 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ft_printf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
void ft_fmt_simplify(t_fmt *fmt)
|
static void ft_fmt_validate_flag_flag(t_fmt *fmt)
|
||||||
{
|
|
||||||
char hashtag;
|
|
||||||
|
|
||||||
hashtag = '#';
|
|
||||||
if (fmt->conversion == 'p')
|
|
||||||
{
|
|
||||||
fmt->conversion = 'x';
|
|
||||||
if (!ft_strchr(fmt->flags, '#'))
|
|
||||||
ft_strncat(fmt->flags, &hashtag, 1);
|
|
||||||
}
|
|
||||||
if (ft_strchr("DOUCS", fmt->conversion))
|
|
||||||
{
|
|
||||||
fmt->conversion += 32;
|
|
||||||
ft_strcpy(fmt->modifier, "l");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_fmt_validate_conversion(t_fmt *fmt)
|
|
||||||
{
|
|
||||||
if (!ft_strchr(ALL_CONVERSIONS, fmt->conversion))
|
|
||||||
{
|
|
||||||
if (fmt->conversion != '%')
|
|
||||||
ft_fmt_error_conv(fmt->conversion);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ft_fmt_validate_flags(t_fmt *fmt)
|
|
||||||
{
|
{
|
||||||
char *flag_ptr;
|
char *flag_ptr;
|
||||||
char flag;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (fmt->conversion != g_convs[i].id)
|
|
||||||
i++;
|
|
||||||
flag_ptr = fmt->flags;
|
|
||||||
while (*flag_ptr)
|
|
||||||
{
|
|
||||||
flag = *flag_ptr;
|
|
||||||
if (!ft_strchr(g_convs[i].allowed_flags, flag))
|
|
||||||
{
|
|
||||||
ft_fmt_error_flag_conv(flag, fmt->conversion);
|
|
||||||
if (flag == '#')
|
|
||||||
*flag_ptr = '.';
|
|
||||||
}
|
|
||||||
flag_ptr++;
|
|
||||||
}
|
|
||||||
if (ft_strchr(fmt->flags, '+') && (flag_ptr = ft_strchr(fmt->flags, ' ')))
|
if (ft_strchr(fmt->flags, '+') && (flag_ptr = ft_strchr(fmt->flags, ' ')))
|
||||||
{
|
{
|
||||||
ft_fmt_error_flag_flag(' ', '+');
|
ft_fmt_error_flag_flag(' ', '+');
|
||||||
|
|
@ -76,9 +30,34 @@ void ft_fmt_validate_flags(t_fmt *fmt)
|
||||||
*flag_ptr = '.';
|
*flag_ptr = '.';
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_fmt_validate_mod(t_fmt *fmt)
|
static void ft_fmt_validate_flag_conv(t_fmt *fmt)
|
||||||
{
|
{
|
||||||
if (fmt->conversion == 's' || fmt->conversion == 'c')
|
char *flag_ptr;
|
||||||
if (fmt->modifier[0] && ft_strcmp(fmt->modifier, "l"))
|
char flag;
|
||||||
ft_fmt_error_mod_conv(fmt->modifier, fmt->conversion);
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
flag_ptr = fmt->flags;
|
||||||
|
while (*flag_ptr)
|
||||||
|
{
|
||||||
|
flag = *flag_ptr;
|
||||||
|
if (!ft_strchr(g_convs[i].allowed_flags, flag))
|
||||||
|
{
|
||||||
|
ft_fmt_error_flag_conv(flag, fmt->conversion);
|
||||||
|
if (flag == '#')
|
||||||
|
*flag_ptr = '.';
|
||||||
|
}
|
||||||
|
flag_ptr++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_fmt_validate_flags(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (fmt->conversion != g_convs[i].id)
|
||||||
|
i++;
|
||||||
|
ft_fmt_validate_flag_conv(fmt);
|
||||||
|
ft_fmt_validate_flag_flag(fmt);
|
||||||
}
|
}
|
||||||
20
libft/src/ft_printf/ft_fmt_validate_mod.c
Normal file
20
libft/src/ft_printf/ft_fmt_validate_mod.c
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_fmt_validate_conv.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 16:53:42 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 16:53:52 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
void ft_fmt_validate_mod(t_fmt *fmt)
|
||||||
|
{
|
||||||
|
if (fmt->conversion == 's' || fmt->conversion == 'c')
|
||||||
|
if (fmt->modifier[0] && ft_strcmp(fmt->modifier, "l"))
|
||||||
|
ft_fmt_error_mod_conv(fmt->modifier, fmt->conversion);
|
||||||
|
}
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:27 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:33:59 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 16:20:10 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ftprintf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
t_conv g_convs[] =
|
t_conv g_convs[] =
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:24 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:52:02 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 16:56:47 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ftprintf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
t_fmt *ft_printf_parse(char **format, va_list ap)
|
t_fmt *ft_printf_parse(char **format, va_list ap)
|
||||||
{
|
{
|
||||||
|
|
@ -26,7 +26,7 @@ t_fmt *ft_printf_parse(char **format, va_list ap)
|
||||||
ft_fmt_validate_mod(fmt);
|
ft_fmt_validate_mod(fmt);
|
||||||
ft_fmt_validate_flags(fmt);
|
ft_fmt_validate_flags(fmt);
|
||||||
ft_fmt_simplify(fmt);
|
ft_fmt_simplify(fmt);
|
||||||
fmt->valid = ft_fmt_validate_conversion(fmt) ? 0 : 1;
|
fmt->valid = ft_fmt_validate_conv(fmt) ? 0 : 1;
|
||||||
return (fmt);
|
return (fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:33:32 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 16:40:15 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ftprintf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
char *ft_transform(t_fmt *fmt, va_list ap)
|
char *ft_transform(t_fmt *fmt, va_list ap)
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +22,7 @@ char *ft_transform(t_fmt *fmt, va_list ap)
|
||||||
while (fmt->conversion != g_convs[i].id)
|
while (fmt->conversion != g_convs[i].id)
|
||||||
i++;
|
i++;
|
||||||
fmt->conv = g_convs[i];
|
fmt->conv = g_convs[i];
|
||||||
ret = (fmt->conv.converter)(fmt, ap);
|
ret = (*fmt->conv.converter)(fmt, ap);
|
||||||
if (fmt->width > (int)ft_strlen(ret))
|
if (fmt->width > (int)ft_strlen(ret))
|
||||||
{
|
{
|
||||||
buf = ret;
|
buf = ret;
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:35 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:33:35 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 17:22:26 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ftprintf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
t_fmt *ft_fmt_init(void)
|
t_fmt *ft_fmt_init(void)
|
||||||
{
|
{
|
||||||
|
|
@ -32,6 +32,9 @@ void ft_fmt_print(t_fmt *fmt)
|
||||||
ft_putstr("valid: ");
|
ft_putstr("valid: ");
|
||||||
ft_putnbr(fmt->valid);
|
ft_putnbr(fmt->valid);
|
||||||
ft_putendl("");
|
ft_putendl("");
|
||||||
|
ft_putstr("conv.: ");
|
||||||
|
ft_putchar(fmt->conversion);
|
||||||
|
ft_putendl("");
|
||||||
ft_putstr("flags: ");
|
ft_putstr("flags: ");
|
||||||
ft_putendl(fmt->flags);
|
ft_putendl(fmt->flags);
|
||||||
ft_putstr("width: ");
|
ft_putstr("width: ");
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:38 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:38 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:33:39 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 17:22:41 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ftprintf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
void ft_fmt_error_conv(char conv)
|
void ft_fmt_error_conv(char conv)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:48:19 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 16:58:00 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ftprintf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
void ft_pad_right(char *str, t_fmt *fmt)
|
void ft_pad_right(char *str, t_fmt *fmt)
|
||||||
{
|
{
|
||||||
|
|
@ -22,33 +22,21 @@ void ft_pad_right(char *str, t_fmt *fmt)
|
||||||
|
|
||||||
void ft_pad_left(char *str, t_fmt *fmt)
|
void ft_pad_left(char *str, t_fmt *fmt)
|
||||||
{
|
{
|
||||||
char buf[100];
|
|
||||||
char sign;
|
char sign;
|
||||||
|
|
||||||
sign = '\0';
|
sign = '\0';
|
||||||
ft_bzero(buf, 100);
|
|
||||||
if (str[0] == '-' || str[0] == '+' || str[0] == ' ')
|
if (str[0] == '-' || str[0] == '+' || str[0] == ' ')
|
||||||
{
|
{
|
||||||
sign = str[0];
|
sign = str[0];
|
||||||
str++;
|
str++;
|
||||||
}
|
}
|
||||||
if (ft_strchr(fmt->flags, '0'))
|
if (ft_strchr(fmt->flags, '0'))
|
||||||
{
|
|
||||||
while ((int)ft_strlen(str) < fmt->width - (sign ? 1 : 0))
|
while ((int)ft_strlen(str) < fmt->width - (sign ? 1 : 0))
|
||||||
{
|
ft_strcatf(str, "0");
|
||||||
ft_strcpy(buf, "0");
|
|
||||||
ft_strcat(buf, str);
|
|
||||||
ft_strcpy(str, buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sign)
|
if (sign)
|
||||||
str--;
|
str--;
|
||||||
if (ft_strchr(fmt->flags, '#'))
|
if (ft_strchr(fmt->flags, '#'))
|
||||||
(fmt->conv.sharp_func)(str, fmt);
|
(fmt->conv.sharp_func)(str, fmt);
|
||||||
while ((int)ft_strlen(str) < fmt->width)
|
while ((int)ft_strlen(str) < fmt->width)
|
||||||
{
|
ft_strcatf(str, " ");
|
||||||
ft_strcpy(buf, " ");
|
|
||||||
ft_strcat(buf, str);
|
|
||||||
ft_strcpy(str, buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,11 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:33:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:33:49 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 16:58:09 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "ftprintf.h"
|
#include "ft_printf.h"
|
||||||
|
|
||||||
void ft_pad_sharp_o(char *str, t_fmt *fmt)
|
void ft_pad_sharp_o(char *str, t_fmt *fmt)
|
||||||
{
|
{
|
||||||
|
|
@ -19,11 +19,7 @@ void ft_pad_sharp_o(char *str, t_fmt *fmt)
|
||||||
(void)fmt;
|
(void)fmt;
|
||||||
ft_bzero(buf, 100);
|
ft_bzero(buf, 100);
|
||||||
if (str[0] != '0')
|
if (str[0] != '0')
|
||||||
{
|
ft_strcatf(buf, "0");
|
||||||
ft_strcpy(buf, "0");
|
|
||||||
ft_strcat(buf, str);
|
|
||||||
ft_strcpy(str, buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_pad_sharp_xb(char *str, t_fmt *fmt)
|
void ft_pad_sharp_xb(char *str, t_fmt *fmt)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:53:53 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:53:53 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:54:28 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 14:44:35 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
23
libft/src/math/ft_ilen_base.c
Normal file
23
libft/src/math/ft_ilen_base.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ilen_base.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:53:53 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 14:45:28 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_ilen_base(int n, int base)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while (n /= base)
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:52:51 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:52:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:57:06 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 14:45:15 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ char *ft_itoa_base(int nbr, char *base, char *flags)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
base_size = ft_strlen(base);
|
base_size = ft_strlen(base);
|
||||||
str = ft_strnew(ft_ilen(nbr, base_size) + 1);
|
str = ft_strnew(ft_ilen_base(nbr, base_size) + 1);
|
||||||
neg = FT_NEG(nbr);
|
neg = FT_NEG(nbr);
|
||||||
if (nbr == 0)
|
if (nbr == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:52:35 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:52:35 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:55:15 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 14:45:40 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
23
libft/src/math/ft_lllen_base.c
Normal file
23
libft/src/math/ft_lllen_base.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lllen_base.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 13:52:35 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 14:46:15 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_lllen_base(long long n, int base)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
while (n /= base)
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/07 13:10:42 by jhalford #+# #+# */
|
/* Created: 2016/11/07 13:10:42 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/07 13:55:30 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 16:30:42 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ char *ft_lltoa_base(long long nbr, char *base, char *flags)
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
base_size = ft_strlen(base);
|
base_size = ft_strlen(base);
|
||||||
str = ft_strnew(ft_lllen(nbr, base_size) + 1);
|
str = ft_strnew(ft_lllen_base(nbr, base_size) + 1);
|
||||||
neg = FT_NEG(nbr);
|
neg = FT_NEG(nbr);
|
||||||
if (nbr == 0)
|
if (nbr == 0)
|
||||||
{
|
{
|
||||||
|
|
@ -47,5 +47,6 @@ char *ft_lltoa_base(long long nbr, char *base, char *flags)
|
||||||
}
|
}
|
||||||
str = ft_flags(str, &i, flags, neg);
|
str = ft_flags(str, &i, flags, neg);
|
||||||
str[i] = '\0';
|
str[i] = '\0';
|
||||||
return (ft_strrev(str));
|
ft_strrev(str);
|
||||||
|
return (str);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/04 11:45:16 by jhalford #+# #+# */
|
/* Created: 2016/11/04 11:45:16 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/11/04 11:45:51 by jhalford ### ########.fr */
|
/* Updated: 2016/11/07 15:43:41 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
23
libft/src/str/ft_strcatf.c
Normal file
23
libft/src/str/ft_strcatf.c
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcatf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2016/11/07 15:46:03 by jhalford #+# #+# */
|
||||||
|
/* Updated: 2016/11/07 15:46:11 by jhalford ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strcatf(char *s1, const char *s2)
|
||||||
|
{
|
||||||
|
char buf[ft_strlen(s2)];
|
||||||
|
|
||||||
|
ft_strcpy(buf, s1);
|
||||||
|
ft_strcpy(s1, s2);
|
||||||
|
ft_strcat(s1, buf);
|
||||||
|
return (s1);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue