You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.9 KiB
75 lines
1.9 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_putchars.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2021/10/27 09:17:03 by narnaud #+# #+# */
|
|
/* Updated: 2021/11/17 09:57:53 by narnaud ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "ft_printf.h"
|
|
|
|
int ft_print_char(int ch, t_opts *opts)
|
|
{
|
|
char c;
|
|
int ret;
|
|
|
|
c = (char)ch;
|
|
ret = 1;
|
|
if (opts->minus)
|
|
{
|
|
ft_putchar_fd(c, 1);
|
|
while (opts->width-- > 1 && ++ret)
|
|
ft_putchar_fd(' ', 1);
|
|
}
|
|
else
|
|
{
|
|
while (opts->width-- > 1 && ++ret)
|
|
ft_putchar_fd(' ', 1);
|
|
ft_putchar_fd(c, 1);
|
|
}
|
|
return (ret);
|
|
}
|
|
|
|
int ft_print_str(char *str, t_opts *opts)
|
|
{
|
|
int i;
|
|
char *formated;
|
|
|
|
i = 0;
|
|
if (!str)
|
|
{
|
|
if (!opts->dot || opts->precision >= 6)
|
|
str = "(null)";
|
|
else
|
|
str = "";
|
|
}
|
|
formated = str_opts_transform(str, opts);
|
|
while (formated[i])
|
|
ft_putchar_fd(formated[i++], 1);
|
|
free(formated);
|
|
return (i);
|
|
}
|
|
|
|
int va_print_char(va_list va_ch, const char *str, t_opts *opts)
|
|
{
|
|
(void)*str;
|
|
return (ft_print_char(va_arg(va_ch, int), opts));
|
|
}
|
|
|
|
int va_print_str(va_list va_str, const char *str, t_opts *opts)
|
|
{
|
|
(void)*str;
|
|
return (ft_print_str(va_arg(va_str, char *), opts));
|
|
}
|
|
|
|
int va_print_perc(va_list va, const char *str, t_opts *opts)
|
|
{
|
|
(void)*str;
|
|
(void)va;
|
|
ft_print_char('%', opts);
|
|
return (1);
|
|
}
|
|
|