-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodifiers.c
More file actions
121 lines (111 loc) · 3.45 KB
/
Copy pathmodifiers.c
File metadata and controls
121 lines (111 loc) · 3.45 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* modifiers.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: stoupin <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/04/24 13:53:21 by stoupin #+# #+# */
/* Updated: 2017/04/24 14:05:52 by stoupin ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
long long int read_int(va_list *ap, int modifiers)
{
long long int number;
if ((modifiers & (MOD_LL | MOD_J)) != 0)
number = (long long int)va_arg(*ap, long long int);
else if ((modifiers & (MOD_L | MOD_Z)) != 0)
number = (long long int)va_arg(*ap, long int);
else if ((modifiers & MOD_HH) != 0)
number = (char)va_arg(*ap, int);
else if ((modifiers & MOD_H) != 0)
number = (short)va_arg(*ap, int);
else
number = (long long int)va_arg(*ap, int);
return (number);
}
unsigned long long int read_uint(va_list *ap, int modifiers)
{
long long int number;
if ((modifiers & (MOD_LL | MOD_J)) != 0)
number = (unsigned long long int)va_arg(*ap, unsigned long long int);
else if ((modifiers & (MOD_L | MOD_Z)) != 0)
number = (unsigned long long int)va_arg(*ap, unsigned long int);
else if ((modifiers & MOD_HH) != 0)
number = (unsigned char)va_arg(*ap, unsigned int);
else if ((modifiers & MOD_H) != 0)
number = (unsigned short)va_arg(*ap, unsigned int);
else
number = (unsigned long long int)va_arg(*ap, unsigned int);
return (number);
}
int parse_modifier(char c, char c_next, int *modifiers)
{
int is_ll;
int is_hh;
is_ll = (c == 'l' && c_next == 'l');
is_hh = (c == 'h' && c_next == 'h');
if (c == 'l')
*modifiers |= MOD_L * !is_ll + MOD_LL * is_ll;
else if (c == 'h')
*modifiers |= MOD_H * !is_hh + MOD_HH * is_hh;
else if (c == 'j')
*modifiers |= MOD_J;
else if (c == 'z')
*modifiers |= MOD_Z;
else
return (0);
return (1 + (is_ll || is_hh));
}
void parse_flags(const char *format, int *i, int *flags)
{
char c;
while (1)
{
c = format[*i];
if (c == '0')
*flags |= FLAG_ZERO;
else if (c == '-')
*flags |= FLAG_MINUS;
else if (c == '#')
*flags |= FLAG_SHARP;
else if (c == '+')
*flags |= FLAG_PLUS;
else if (c == ' ')
*flags |= FLAG_SPACE;
else
return ;
(*i)++;
}
return ;
}
void parse_width(const char *format, int *i, t_par *p,
va_list *ap)
{
p->width1 = 0;
p->width2 = -1;
while (ft_isdigit(format[*i]))
p->width1 = p->width1 * 10 + format[(*i)++] - '0';
if (format[*i] == '*')
{
p->width1 = (int)va_arg(*ap, int) + 0 * (*i)++;
if (p->width1 < 0)
p->width1 = -p->width1 + 0 * (p->flags |= FLAG_MINUS);
}
if (ft_isdigit(format[*i]))
{
p->width1 = 0;
while (ft_isdigit(format[*i]))
p->width1 = p->width1 * 10 + format[(*i)++] - '0';
}
if (format[*i] == '.')
{
p->width2 = 0 + 0 * (*i)++;
if (format[*i] == '*')
p->width2 = (int)va_arg(*ap, int) + 0 * (*i)++;
else
while (ft_isdigit(format[*i]))
p->width2 = p->width2 * 10 + format[(*i)++] - '0';
}
}