int printf_o(int fd, t_print_param *pp, uintmax_t o) { int total; int arg_size; total = 0; arg_size = ft_baselen(o, 8); arg_size = ((pp->flags & PRINT_FLAG_DIEZ) ? 1 : 0) + (arg_size < pp->precision ? pp->precision : arg_size); if ((pp->flags & PRINT_FLAG_LESS) == 0) while (total < pp->field_width - arg_size) total += ft_putchar(fd, pp->flags & PRINT_FLAG_ZERO ? '0' \ : ' '); if (pp->flags & PRINT_FLAG_DIEZ) { total += ft_putchar(fd, '0'); pp->precision = pp->precision == 0 ? pp->precision : pp->precision - 1; } while (pp->precision-- > (int)ft_baselen(o, 2)) total += ft_putchar(fd, '0'); total += pp->precision + 1 == 0 && o == 0 ? 0 : ft_putbaseb(fd, o, 8, 0); while (total < pp->field_width) total += ft_putchar(fd, ' '); return (total); }
int ft_printxo_flag0(t_list *lst, int base, unsigned long long nb) { if (lst->diese) { lst->result += diese_flag(lst); lst->result += ft_print_zeros(lst->size - (base == 8 ? 1 : 2), ft_baselen(nb, 0, base)); ft_put_base(nb, base, lst); } else { lst->result += ft_print_zeros(lst->size, ft_baselen(nb, 0, base)); ft_put_base(nb, base, lst); } return (0); }
int ft_printxo2(t_list *lst, int base, unsigned long long nb, int spaces) { if (lst->diese && nb) { lst->result += (lst->precision > ft_baselen(nb, 0, base) ? ft_print_space(lst->size - lst->precision - base) : ft_print_space(lst->size - ft_baselen(nb, 0, base) - spaces)); lst->result += diese_flag(lst); lst->result += ft_print_zeros(lst->precision - ((base == 8) ? 1 : 0), ft_baselen(nb, 0, base)); ft_put_base(nb, base, lst); return (0); } lst->result += ((lst->precision > ft_baselen(nb, 0, base)) ? ft_print_space(lst->size - lst->precision) : ft_print_space(lst->size - ft_baselen(nb, 0, base))); lst->result += ft_print_zeros(lst->precision, ft_baselen(nb, 0, base)); if (lst->precision == 0 && lst->modified_precision && !lst->diese) { if ((lst->type != 'o' && lst->type != 'O') || lst->size != 0) lst->result += ft_print_char(' '); return (0); } ft_put_base(nb, base, lst); return (0); }
int ft_printxo(t_list *lst, int base, unsigned long long nb, int spaces) { if (lst->minus) { if (lst->diese) { lst->result += diese_flag(lst); lst->result += ft_print_zeros(lst->precision, ft_baselen(nb, 0, base)); ft_put_base(nb, base, lst); lst->result += (lst->precision > ft_baselen(nb, 0, base) ? ft_print_space(lst->size - lst->precision - base) : ft_print_space(lst->size - ft_baselen(nb, 0, base) - spaces)); return (0); } lst->result += ft_print_zeros(lst->precision, ft_baselen(nb, 0, base)); ft_put_base(nb, base, lst); lst->result += (lst->precision > ft_baselen(nb, 0, base) ? ft_print_space(lst->size - lst->precision) : ft_print_space(lst->size - ft_baselen(nb, 0, base))); return (0); } else ft_printxo2(lst, base, nb, spaces); return (0); }
int printf_p(int fd, t_print_param *pp, unsigned long int p) { int total; int arg_size; total = 0; arg_size = ft_strlen("0x") + ft_baselen(p, 16); if ((pp->flags & PRINT_FLAG_LESS) == 0) while (total < pp->field_width - arg_size) total += ft_putchar(fd, ' '); total += ft_putnstr(fd, "0x", -1) + ft_putbaseb(fd, p, 16, 0); while (total < pp->field_width) total += ft_putchar(fd, ' '); return (total); }
int printf_u(int fd, t_print_param *pp, uintmax_t u) { int total; int arg_size; total = 0; arg_size = ft_baselen(u, 10); if ((pp->flags & PRINT_FLAG_LESS) == 0) while (total < pp->field_width - arg_size) total += ft_putchar(fd, pp->flags & PRINT_FLAG_ZERO ? '0' : ' '); total += ft_putbaseb(fd, u, 10, 0); while (total < pp->field_width) total += ft_putchar(fd, ' '); return (total); }