-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_arg_format.c
85 lines (79 loc) · 2.59 KB
/
get_arg_format.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
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_arg_format.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anel-bou <anel-bou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/06/12 10:38:10 by anel-bou #+# #+# */
/* Updated: 2019/10/23 20:17:09 by anel-bou ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#define A2I ft_atoi(f)
#define TAILLE lst->taille
void ignore_spc_n_zero(char *s)
{
if (ft_strchr(s, ' ') && ft_strchr(s, '+'))
ft_del_char(s, ' ');
if (ft_strchr(s, '-') && ft_strchr(s, '0'))
ft_del_char(s, '0');
}
int taille(char *f)
{
if (*f == 'h' && *(f + 1) == 'h')
return (1);
else if (*f == 'h' && *(f + 1) != 'h')
return (2);
else if (*f == 'l' && *(f + 1) != 'l')
return (3);
else if (*f == 'l' && *(f + 1) == 'l')
return (4);
else if (*f == 'L')
return (5);
else if (*f == 'z')
return (6);
else if (*f == 'j')
return (7);
else if (*f == 't')
return (8);
return (0);
}
int get_taille(char **f, t_arg *lst)
{
if (**f == 'l' || **f == 'h' || **f == 'L' || **f == 'z'
|| **f == 't' || **f == 'j')
{
TAILLE = taille(*f);
*f = ((TAILLE == 1 || TAILLE == 4) ? (*f + 2) : (*f + 1));
return (1);
}
return (0);
}
void get_arg_format(char *f, t_arg *lst)
{
int tmp;
set_t_arg(lst);
tmp = 0;
(*f == '0') ? lst->option[0] = '0' : 0;
if (*f >= '0' && *f <= '9')
tmp = (A2I < 0) ? -1 : A2I;
while (*f >= '0' && *f <= '9')
f++;
(*f == '$') ? (lst->dollar = tmp) : 0;
(*f != '$') ? (lst->larg_min = tmp) : 0;
f = ((*f == '$') ? (f + 1) : f);
tmp = ((lst->option[0]) ? 1 : 0);
while (*f == '-' || *f == '+' || *f == '#' || *f == '0' || *f == ' ')
(!ft_strchr((lst->option), *f)) ? lst->option[tmp++] = *f++ : 0;
ignore_spc_n_zero(lst->option);
(*f >= '0' && *f <= '9') ? lst->larg_min = A2I : 0;
while (*f >= '0' && *f <= '9')
f++;
if (*f == '.' && ++lst->point && *(++f) >= '0' && *f <= '9')
lst->precision = (A2I < 0) ? 6 : A2I;
while (*f >= '0' && *f <= '9')
f++;
(get_taille(&f, lst));
(ft_strchr("cspfdiouxXegbrk", *f)) ? lst->conv_tp = *f : 0;
}