-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_int.c
More file actions
69 lines (65 loc) · 1.25 KB
/
handle_int.c
File metadata and controls
69 lines (65 loc) · 1.25 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "ft_printf.h"
static void handle_positive(t_info *info, int i)
{
if (!info->is_minus_flag)
{
if (info->is_prec)
fix_prec(info, 'd');
if (info->is_width)
handle_width(info, 'd');
if (info->is_prec)
handle_prec(info, 'd');
print(info, 'd');
}
else
{
if (info->is_prec)
fix_prec(info, 'd');
if (info->is_prec)
handle_prec(info, 'd');
print(info, 'd');
if (info->is_width)
handle_width(info, 'd');
}
}
static void handle_negative(t_info *info, int i)
{
info->width_val -= 1;
if (!info->is_minus_flag)
{
if (info->is_prec)
fix_prec(info, 'd');
if (info->is_zero_flag)
ft_putchar('-');
if (info->is_width)
handle_width(info, 'd');
if (!info->is_zero_flag)
ft_putchar('-');
if (info->is_prec)
handle_prec(info, 'd');
print(info, 'd');
return ;
}
if (info->is_prec)
fix_prec(info, 'd');
ft_putchar('-');
if (info->is_prec)
handle_prec(info, 'd');
print(info, 'd');
if (info->is_width)
handle_width(info, 'd');
}
void handle_integer(t_info *info, va_list arg)
{
int i;
i = va_arg(arg, int);
if (i == -2147483648)
info->s = ft_strdup("2147483648");
else
info->s = ft_itoa(ft_abs(i));
calculate_len(info);
if (i < 0)
handle_negative(info, i);
else
handle_positive(info, i);
}