GCC Code Coverage Report


Directory: ./
File: lib/my/my_printf/find_format.c
Date: 2024-06-05 00:34:38
Exec Total Coverage
Lines: 96 96 100.0%
Functions: 8 8 100.0%
Branches: 37 38 97.4%

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 278 formating_t *find_specifier(user_t *user,
16 int *i, formating_t *formating)
17 {
18 278 char str[5] = {0};
19 278 formating_t *copy2 = formating;
20 278 char *specifier[] = {"l", "ll", "h", "hh", "j", "z", "t", "L", NULL};
21
22 278 str[0] = user->str[*i];
23
4/4
✓ Branch 0 taken 267 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 258 times.
278 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 1991 times.
✓ Branch 1 taken 230 times.
2221 for (; specifier[copy2->id_sp] != NULL; (copy2->id_sp)++) {
26
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 1943 times.
1991 if (my_strcmp(str, specifier[copy2->id_sp]) == 0) {
27 48 my_strcat((copy2->final_format), str);
28 48 return copy2;
29 }
30 }
31 230 formating = copy2;
32 230 formating->id_sp = -1;
33 230 return formating;
34 }
35
36 2599 static int check_star_prc(user_t *user,
37 formating_t *formating, formating_t *copy2, int nb)
38 {
39 2599 char str[1000] = {0};
40
41
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2598 times.
2599 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 2598 return 0;
49 }
50
51 106513 formating_t *find_numbers(user_t *user, int *i,
52 formating_t *formating)
53 {
54 106513 char str[1000] = {0};
55 106513 formating_t *copy2 = formating;
56 106513 int nb = 0;
57
58
2/2
✓ Branch 0 taken 2599 times.
✓ Branch 1 taken 106484 times.
109083 for (; NUMBERS[copy2->id_nb] != '\0'; (copy2->id_nb)++) {
59 2599 formating->index_user = user->str[*i];
60
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2598 times.
2599 if (check_star_prc(user, formating, copy2, nb) == 1)
61 1 return copy2;
62
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2570 times.
2598 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 106484 formating = copy2;
71 106484 formating->id_nb = -1;
72 106484 return formating;
73 }
74
75 106682 formating_t *find_precision(user_t *user,
76 int *i, formating_t *formating)
77 {
78 106682 char str[5] = {0};
79 106682 formating_t *copy2 = formating;
80
81
2/2
✓ Branch 0 taken 278 times.
✓ Branch 1 taken 106655 times.
106933 for (; PRECISION[copy2->id_prc] != '\0'; (copy2->id_prc)++) {
82
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 251 times.
278 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 106655 formating = copy2;
89 106655 formating->id_prc = -1;
90 106655 return formating;
91 }
92
93 2544 static int check_star_wd(user_t *user,
94 formating_t *formating, formating_t *copy2, int nb)
95 {
96 2544 char str[1000] = {0};
97
98
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2543 times.
2544 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 2543 return 0;
106 }
107
108 119665 formating_t *find_width(user_t *user,
109 int *i, formating_t *formating)
110 {
111 119665 char str[1000] = {0};
112 119665 formating_t *copy2 = formating;
113 119665 int nb = 0;
114
115
2/2
✓ Branch 0 taken 2544 times.
✓ Branch 1 taken 119631 times.
122175 for (; WIDTH[copy2->id_wd] != '\0'; (copy2->id_wd)++) {
116 2544 formating->index_user = user->str[*i];
117
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2543 times.
2544 if (check_star_wd(user, formating, copy2, nb) == 1)
118 1 return copy2;
119
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 2510 times.
2543 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 119631 formating = copy2;
128 119631 formating->id_wd = -1;
129 119631 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 115364 formating_t *find_first(user_t *user,
141 int *i, formating_t *formating)
142 {
143 115364 char str[5] = {0};
144 115364 formating_t *copy2 = formating;
145
146
2/2
✓ Branch 0 taken 1311 times.
✓ Branch 1 taken 115325 times.
116636 for (; FORMATAGE[copy2->id_ft] != '\0'; (copy2->id_ft)++) {
147
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 1272 times.
1311 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 115325 formating = copy2;
156 115325 formating->id_ft = -1;
157 115325 return formating;
158 }
159