-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_number_octal.c
41 lines (38 loc) · 1.9 KB
/
format_number_octal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* format_number_octal.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: alischyn <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/23 16:49:35 by alischyn #+# #+# */
/* Updated: 2017/03/23 19:59:23 by alischyn ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void format_number_octal(t_fmt *fmt, va_list ap)
{
char *number;
char sign[3];
number = uintmax_to_any(pull_number_unsigned(fmt, ap), 8, false);
number = format_number_prep_zeros(fmt, number);
if (fmt->has_precision && fmt->precision == 0 && number_is_zero(number))
number[0] = '\0';
if (fmt->f_octo)
STRCPY(sign, "0");
else
sign[0] = '\0';
if ((!fmt->f_minus && !fmt->f_zero && fmt->has_width) ||
(!fmt->f_minus && fmt->f_zero && fmt->has_width && fmt->has_precision))
APPEND_CHAR_N(' ', fmt->width - STRLEN(number) - (sign[0] ? 1 : 0));
if (sign[0] != '\0' && !number_is_zero(number))
APPEND_STRING(sign);
if (fmt->f_octo && fmt->has_precision && fmt->precision == 0 &&
number_is_zero(number))
APPEND_CHAR('0');
if (!fmt->f_minus && fmt->f_zero && fmt->has_width && !fmt->has_precision)
APPEND_CHAR_N('0', fmt->width - STRLEN(number) - (sign[0] ? 1 : 0));
APPEND_STRING(number);
if (fmt->f_minus && fmt->has_width)
APPEND_CHAR_N(' ', fmt->width - STRLEN(number) - (sign[0] ? 1 : 0));
}