81 lines
2.4 KiB
C
81 lines
2.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* pf_getflags.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tmaze <tmaze@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2019/02/07 14:14:38 by tmaze #+# #+# */
|
|
/* Updated: 2019/02/09 14:36:30 by tmaze ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "libftprintf.h"
|
|
|
|
void pf_initflags(t_flags *flags)
|
|
{
|
|
flags->convtype = none;
|
|
flags->minus = '\0';
|
|
flags->sign = '\0';
|
|
flags->hash = '\0';
|
|
flags->width = 0;
|
|
flags->precision = 0;
|
|
flags->size = '\0';
|
|
}
|
|
|
|
void pf_putflags(t_flags *flags)
|
|
{
|
|
ft_putendl("--- putflags ---");
|
|
ft_putstr("convtype->");
|
|
ft_putnbr(flags->convtype);
|
|
ft_putstr("/nminus->");
|
|
ft_putchar(flags->minus);
|
|
ft_putstr("/nsign->");
|
|
ft_putchar(flags->sign);
|
|
ft_putstr("/nhash->");
|
|
ft_putchar(flags->hash);
|
|
ft_putstr("/nwidth->");
|
|
ft_putnbr(flags->width);
|
|
ft_putstr("/nprecision->");
|
|
ft_putnbr(flags->precision);
|
|
ft_putstr("/nsize->");
|
|
ft_putchar(flags->size);
|
|
ft_putchar("/n");
|
|
}
|
|
|
|
size_t pf_getflags(const char *format, t_flags *flags)
|
|
{
|
|
size_t i;
|
|
|
|
pf_initflags(flags);
|
|
i = 0;
|
|
while (format[++i] && ft_strchr("%cspdiouxXf", format[i]) != NULL)
|
|
{
|
|
if (format[i] == '-')
|
|
flags->minus = '-';
|
|
if (format[i] == '#')
|
|
flags->hash = '#';
|
|
if (format[i] == ' ' || format[i] == '+')
|
|
flags->sign = format[i];
|
|
if (ft_isdigit(format[i])
|
|
|| (format[i] == '.' && ft_isdigit(format[i + 1])))
|
|
{
|
|
if (ft_isdigit(format[i]))
|
|
flags->width = ft_atoi(&format[i]);
|
|
else
|
|
flags->precision = ft_atoi(&format[i + 1]);
|
|
while (format[i + 1] && ft_isdigit(format[i + 1]))
|
|
i++;
|
|
continue ;
|
|
}
|
|
if (format[i] == 'h' || format[i] == 'l')
|
|
{
|
|
flags->size = format[i];
|
|
if (format[i + 1] && format[i + 1] == format[i])
|
|
flags->size = ft_toupper(format[++i]);
|
|
}
|
|
}
|
|
flags->convtype = format[i];
|
|
return (i);
|
|
}
|