norm for ft_printf
This commit is contained in:
parent
856413ee7c
commit
3156450a32
8 changed files with 18 additions and 36 deletions
|
|
@ -15,8 +15,6 @@ t_fmt *ft_printf_parse(char **format, va_list ap)
|
||||||
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_conversion(fmt) ? 0 : 1;
|
||||||
|
|
||||||
/* ft_fmt_print(fmt); */
|
|
||||||
return (fmt);
|
return (fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -25,7 +23,6 @@ void ft_printf_parse_flags(t_fmt *fmt, char **format)
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
str = *format;
|
str = *format;
|
||||||
while (str[i])
|
while (str[i])
|
||||||
|
|
@ -40,8 +37,6 @@ void ft_printf_parse_flags(t_fmt *fmt, char **format)
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
*format += i;
|
*format += i;
|
||||||
/* printf("\nparse_flags: %s\n", *format); */
|
|
||||||
/* fflush(stdout); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap)
|
void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap)
|
||||||
|
|
@ -65,9 +60,6 @@ void ft_printf_parse_width(t_fmt *fmt, char **format, va_list ap)
|
||||||
fmt->width = ft_atoi(buf);
|
fmt->width = ft_atoi(buf);
|
||||||
}
|
}
|
||||||
*format += i;
|
*format += i;
|
||||||
/* printf("found width: %i\n", fmt->width); */
|
|
||||||
/* printf("\nparse_nums: %s\n", *format); */
|
|
||||||
/* fflush(stdout); */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap)
|
void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap)
|
||||||
|
|
@ -93,7 +85,6 @@ void ft_printf_parse_precision(t_fmt *fmt, char **format, va_list ap)
|
||||||
fmt->precision = ft_atoi(buf);
|
fmt->precision = ft_atoi(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* printf("found preci: %i\n", fmt->precision); */
|
|
||||||
*format += i;
|
*format += i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,6 +109,4 @@ void ft_printf_parse_modifiers(t_fmt *fmt, char **format)
|
||||||
else
|
else
|
||||||
ft_strcpy(fmt->modifier, "");
|
ft_strcpy(fmt->modifier, "");
|
||||||
*format += ft_strlen(fmt->modifier);
|
*format += ft_strlen(fmt->modifier);
|
||||||
/* printf("\nparse_mods: %s\n", *format); */
|
|
||||||
/* fflush(stdout); */
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,6 @@ char *ft_transform(t_fmt *fmt, va_list ap)
|
||||||
ret = (char *)malloc(sizeof(char) * (fmt->width + 5));
|
ret = (char *)malloc(sizeof(char) * (fmt->width + 5));
|
||||||
ft_strcpy(ret, buf);
|
ft_strcpy(ret, buf);
|
||||||
}
|
}
|
||||||
/* printf("before padding: '%s'\n", ret); */
|
|
||||||
/* fflush(stdout); */
|
|
||||||
if (ft_strchr(fmt->flags, '-'))
|
if (ft_strchr(fmt->flags, '-'))
|
||||||
ft_pad_right(ret, fmt);
|
ft_pad_right(ret, fmt);
|
||||||
else
|
else
|
||||||
|
|
@ -6,11 +6,6 @@ t_fmt *ft_fmt_init(void)
|
||||||
|
|
||||||
fmt = (t_fmt *)malloc(sizeof(t_fmt) + 1);
|
fmt = (t_fmt *)malloc(sizeof(t_fmt) + 1);
|
||||||
ft_bzero(fmt->flags, 6);
|
ft_bzero(fmt->flags, 6);
|
||||||
/* fmt->flags.hash = 0; */
|
|
||||||
/* fmt->flags.zero = 0; */
|
|
||||||
/* fmt->flags.minus = 0; */
|
|
||||||
/* fmt->flags.space = 0; */
|
|
||||||
/* fmt->flags.plus = 0; */
|
|
||||||
ft_bzero(fmt->modifier, 3);
|
ft_bzero(fmt->modifier, 3);
|
||||||
fmt->conversion = '\0';
|
fmt->conversion = '\0';
|
||||||
fmt->width = 0;
|
fmt->width = 0;
|
||||||
|
|
@ -21,13 +16,19 @@ t_fmt *ft_fmt_init(void)
|
||||||
|
|
||||||
void ft_fmt_print(t_fmt *fmt)
|
void ft_fmt_print(t_fmt *fmt)
|
||||||
{
|
{
|
||||||
printf("\n---\n");
|
ft_putendl("\n---");
|
||||||
printf("valid: %i\n", fmt->valid);
|
ft_putstr("valid: ");
|
||||||
printf("flags: %s\n", fmt->flags);
|
ft_putnbr(fmt->valid);
|
||||||
printf("width: %i\n", fmt->width);
|
ft_putendl("");
|
||||||
printf("prec.: %i\n", fmt->precision);
|
ft_putstr("flags: ");
|
||||||
printf("modif: %s\n", fmt->modifier);
|
ft_putendl(fmt->flags);
|
||||||
printf("conv.: %c\n", fmt->conversion);
|
ft_putstr("width: ");
|
||||||
printf("---\n");
|
ft_putnbr(fmt->width);
|
||||||
fflush(stdout);
|
ft_putendl("");
|
||||||
|
ft_putstr("prec.: ");
|
||||||
|
ft_putnbr(fmt->precision);
|
||||||
|
ft_putendl("");
|
||||||
|
ft_putstr("modifier: ");
|
||||||
|
ft_putendl(fmt->modifier);
|
||||||
|
ft_putendl("---");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
void ft_pad_right(char *str, t_fmt *fmt)
|
void ft_pad_right(char *str, t_fmt *fmt)
|
||||||
{
|
{
|
||||||
if (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_strcat(str, " ");
|
ft_strcat(str, " ");
|
||||||
|
|
@ -31,7 +31,7 @@ void ft_pad_left(char *str, t_fmt *fmt)
|
||||||
}
|
}
|
||||||
if (sign)
|
if (sign)
|
||||||
str--;
|
str--;
|
||||||
if (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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@ char *ft_uitoa_base(unsigned int nbr, char *base)
|
||||||
int base_size;
|
int base_size;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
/* printf("converting %llu to base %s\n", nbr, base); */
|
|
||||||
/* fflush(stdout); */
|
|
||||||
i = 0;
|
i = 0;
|
||||||
base_size = ft_strlen(base);
|
base_size = ft_strlen(base);
|
||||||
str = ft_strnew(ft_size(nbr, base_size) + 1);
|
str = ft_strnew(ft_size(nbr, base_size) + 1);
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,6 @@ char *ft_ulltoa_base(unsigned long long nbr, char *base)
|
||||||
int base_size;
|
int base_size;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
/* printf("converting %llu to base %s\n", nbr, base); */
|
|
||||||
/* fflush(stdout); */
|
|
||||||
i = 0;
|
i = 0;
|
||||||
base_size = ft_strlen(base);
|
base_size = ft_strlen(base);
|
||||||
str = ft_strnew(ft_size(nbr, base_size) + 1);
|
str = ft_strnew(ft_size(nbr, base_size) + 1);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "libft.h"
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void ft_debug(void)
|
void ft_debug(void)
|
||||||
{
|
{
|
||||||
|
|
@ -19,5 +18,4 @@ void ft_debug(void)
|
||||||
|
|
||||||
n++;
|
n++;
|
||||||
ft_printf("----------\n check %02i\n----------\n", n);
|
ft_printf("----------\n check %02i\n----------\n", n);
|
||||||
fflush(stdout);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ int ft_xattr_print(char *path)
|
||||||
if (valuelen == -1)
|
if (valuelen == -1)
|
||||||
ft_printf("couldn't get value\n");
|
ft_printf("couldn't get value\n");
|
||||||
else
|
else
|
||||||
printf("%s:\n%s\n", list + i, value);
|
ft_printf("%s:\n%s\n", list + i, value);
|
||||||
i += ft_strlen(list) + 1;
|
i += ft_strlen(list) + 1;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue