Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_printf | ||
4 | ** File description: | ||
5 | ** The file that contains functions for find all format | ||
6 | */ | ||
7 | /** | ||
8 | * @file find_format.c | ||
9 | * @brief The file that contains functions for find all format | ||
10 | * @author Nicolas TORO | ||
11 | */ | ||
12 | |||
13 | #include "myprintf.h" | ||
14 | |||
15 | 22319 | formating_t *find_specifier(user_t *user, | |
16 | int *i, formating_t *formating) | ||
17 | { | ||
18 | 22319 | char str[5] = {0}; | |
19 | 22319 | formating_t *copy2 = formating; | |
20 | 22319 | char *specifier[] = {"l", "ll", "h", "hh", "j", "z", "t", "L", NULL}; | |
21 | |||
22 | 22319 | str[0] = user->str[*i]; | |
23 |
4/4✓ Branch 0 taken 22308 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 22299 times.
|
22319 | if (user->str[*i + 1] == 'l' || user->str[*i + 1] == 'h') |
24 | 20 | str[1] = user->str[*i + 1]; | |
25 |
2/2✓ Branch 0 taken 178319 times.
✓ Branch 1 taken 22271 times.
|
200590 | for (; specifier[copy2->id_sp] != NULL; (copy2->id_sp)++) { |
26 |
2/2✓ Branch 1 taken 48 times.
✓ Branch 2 taken 178271 times.
|
178319 | if (my_strcmp(str, specifier[copy2->id_sp]) == 0) { |
27 | 48 | my_strcat((copy2->final_format), str); | |
28 | 48 | return copy2; | |
29 | } | ||
30 | } | ||
31 | 22271 | formating = copy2; | |
32 | 22271 | formating->id_sp = -1; | |
33 | 22271 | return formating; | |
34 | } | ||
35 | |||
36 | 223009 | static int check_star_prc(user_t *user, | |
37 | formating_t *formating, formating_t *copy2, int nb) | ||
38 | { | ||
39 | 223009 | char str[1000] = {0}; | |
40 | |||
41 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 223008 times.
|
223009 | if (formating->index_user == '*') { |
42 | 1 | nb = va_arg(*(formating->liste), int); | |
43 | 1 | my_strcat(str, my_str_nbr(nb)); | |
44 | 1 | my_strcat((copy2->final_format), str); | |
45 | 1 | formating->id_nb = nb; | |
46 | 1 | return 1; | |
47 | } | ||
48 | 223008 | return 0; | |
49 | } | ||
50 | |||
51 | 1981902 | formating_t *find_numbers(user_t *user, int *i, | |
52 | formating_t *formating) | ||
53 | { | ||
54 | 1981902 | char str[1000] = {0}; | |
55 | 1981902 | formating_t *copy2 = formating; | |
56 | 1981902 | int nb = 0; | |
57 | |||
58 |
2/2✓ Branch 0 taken 223009 times.
✓ Branch 1 taken 1981873 times.
|
2204882 | for (; NUMBERS[copy2->id_nb] != '\0'; (copy2->id_nb)++) { |
59 | 223009 | formating->index_user = user->str[*i]; | |
60 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 223008 times.
|
223009 | if (check_star_prc(user, formating, copy2, nb) == 1) |
61 | 1 | return copy2; | |
62 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 222980 times.
|
223008 | if (user->str[*i] == NUMBERS[copy2->id_nb]) { |
63 | 28 | nb = my_getnbr(&user->str[*i]); | |
64 | 28 | my_strcat(str, my_str_nbr(nb)); | |
65 | 28 | my_strcat((copy2->final_format), str); | |
66 | 28 | formating->id_nb = nb; | |
67 | 28 | return copy2; | |
68 | } | ||
69 | } | ||
70 | 1981873 | formating = copy2; | |
71 | 1981873 | formating->id_nb = -1; | |
72 | 1981873 | return formating; | |
73 | } | ||
74 | |||
75 | 1982071 | formating_t *find_precision(user_t *user, | |
76 | int *i, formating_t *formating) | ||
77 | { | ||
78 | 1982071 | char str[5] = {0}; | |
79 | 1982071 | formating_t *copy2 = formating; | |
80 | |||
81 |
2/2✓ Branch 0 taken 22319 times.
✓ Branch 1 taken 1982044 times.
|
2004363 | for (; PRECISION[copy2->id_prc] != '\0'; (copy2->id_prc)++) { |
82 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 22292 times.
|
22319 | if (user->str[*i] == PRECISION[copy2->id_prc]) { |
83 | 27 | str[0] = user->str[*i]; | |
84 | 27 | my_strcat((copy2->final_format), str); | |
85 | 27 | return copy2; | |
86 | } | ||
87 | } | ||
88 | 1982044 | formating = copy2; | |
89 | 1982044 | formating->id_prc = -1; | |
90 | 1982044 | return formating; | |
91 | } | ||
92 | |||
93 | 222954 | static int check_star_wd(user_t *user, | |
94 | formating_t *formating, formating_t *copy2, int nb) | ||
95 | { | ||
96 | 222954 | char str[1000] = {0}; | |
97 | |||
98 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 222953 times.
|
222954 | if (formating->index_user == '*') { |
99 | 1 | nb = va_arg(*(formating->liste), int); | |
100 | 1 | my_strcat(str, my_str_nbr(nb)); | |
101 | 1 | my_strcat((copy2->final_format), str); | |
102 | 1 | formating->id_wd = nb; | |
103 | 1 | return 1; | |
104 | } | ||
105 | 222953 | return 0; | |
106 | } | ||
107 | |||
108 | 1995006 | formating_t *find_width(user_t *user, | |
109 | int *i, formating_t *formating) | ||
110 | { | ||
111 | 1995006 | char str[1000] = {0}; | |
112 | 1995006 | formating_t *copy2 = formating; | |
113 | 1995006 | int nb = 0; | |
114 | |||
115 |
2/2✓ Branch 0 taken 222954 times.
✓ Branch 1 taken 1994972 times.
|
2217926 | for (; WIDTH[copy2->id_wd] != '\0'; (copy2->id_wd)++) { |
116 | 222954 | formating->index_user = user->str[*i]; | |
117 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 222953 times.
|
222954 | if (check_star_wd(user, formating, copy2, nb) == 1) |
118 | 1 | return copy2; | |
119 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 222920 times.
|
222953 | if (user->str[*i] == WIDTH[copy2->id_wd]) { |
120 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
|
33 | nb = ABS(my_getnbr(&(user->str[*i]))); |
121 | 33 | my_strcat(str, my_str_nbr(nb)); | |
122 | 33 | my_strcat((copy2->final_format), str); | |
123 | 33 | formating->id_wd = nb; | |
124 | 33 | return copy2; | |
125 | } | ||
126 | } | ||
127 | 1994972 | formating = copy2; | |
128 | 1994972 | formating->id_wd = -1; | |
129 | 1994972 | return formating; | |
130 | } | ||
131 | |||
132 | 39 | static void check_nextesp(formating_t *copy2, formating_t *formating) | |
133 | { | ||
134 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 31 times.
|
39 | if (formating->next_chara == '+') |
135 | 8 | my_strcat(copy2->final_format, "+"); | |
136 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 38 times.
|
39 | if (formating->next_chara == '-') |
137 | 1 | my_strcat(copy2->final_format, "-"); | |
138 | 39 | } | |
139 | |||
140 | 1990705 | formating_t *find_first(user_t *user, | |
141 | int *i, formating_t *formating) | ||
142 | { | ||
143 | 1990705 | char str[5] = {0}; | |
144 | 1990705 | formating_t *copy2 = formating; | |
145 | |||
146 |
2/2✓ Branch 0 taken 111516 times.
✓ Branch 1 taken 1990666 times.
|
2102182 | for (; FORMATAGE[copy2->id_ft] != '\0'; (copy2->id_ft)++) { |
147 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 111477 times.
|
111516 | if (user->str[*i] == FORMATAGE[copy2->id_ft]) { |
148 | 39 | str[0] = user->str[*i]; | |
149 | 39 | formating->next_chara = (user->str[*i + 1]); | |
150 | 39 | my_strcat((copy2->final_format), str); | |
151 | 39 | check_nextesp(copy2, formating); | |
152 | 39 | return copy2; | |
153 | } | ||
154 | } | ||
155 | 1990666 | formating = copy2; | |
156 | 1990666 | formating->id_ft = -1; | |
157 | 1990666 | return formating; | |
158 | } | ||
159 |