/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchars.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); }