GCC Code Coverage Report


Directory: ./
File: lib/my/my_printf/find_format.c
Date: 2024-05-07 14:54:03
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 26081 formating_t *find_specifier(user_t *user,
16 int *i, formating_t *formating)
17 {
18 26081 char str[5] = {0};
19 26081 formating_t *copy2 = formating;
20 26081 char *specifier[] = {"l", "ll", "h", "hh", "j", "z", "t", "L", NULL};
21
22 26081 str[0] = user->str[*i];
23
4/4
✓ Branch 0 taken 26070 times.
✓ Branch 1 taken 11 times.
✓ Branch 2 taken 9 times.
✓ Branch 3 taken 26061 times.
26081 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 208415 times.
✓ Branch 1 taken 26033 times.
234448 for (; specifier[copy2->id_sp] != NULL; (copy2->id_sp)++) {
26
2/2
✓ Branch 1 taken 48 times.
✓ Branch 2 taken 208367 times.
208415 if (my_strcmp(str, specifier[copy2->id_sp]) == 0) {
27 48 my_strcat((copy2->final_format), str);
28 48 return copy2;
29 }
30 }
31 26033 formating = copy2;
32 26033 formating->id_sp = -1;
33 26033 return formating;
34 }
35
36 260629 static int check_star_prc(user_t *user,
37 formating_t *formating, formating_t *copy2, int nb)
38 {
39 260629 char str[1000] = {0};
40
41
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 260628 times.
260629 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 260628 return 0;
49 }
50
51 2482525 formating_t *find_numbers(user_t *user, int *i,
52 formating_t *formating)
53 {
54 2482525 char str[1000] = {0};
55 2482525 formating_t *copy2 = formating;
56 2482525 int nb = 0;
57
58
2/2
✓ Branch 0 taken 260629 times.
✓ Branch 1 taken 2482496 times.
2743125 for (; NUMBERS[copy2->id_nb] != '\0'; (copy2->id_nb)++) {
59 260629 formating->index_user = user->str[*i];
60
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 260628 times.
260629 if (check_star_prc(user, formating, copy2, nb) == 1)
61 1 return copy2;
62
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 260600 times.
260628 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 2482496 formating = copy2;
71 2482496 formating->id_nb = -1;
72 2482496 return formating;
73 }
74
75 2482694 formating_t *find_precision(user_t *user,
76 int *i, formating_t *formating)
77 {
78 2482694 char str[5] = {0};
79 2482694 formating_t *copy2 = formating;
80
81
2/2
✓ Branch 0 taken 26081 times.
✓ Branch 1 taken 2482667 times.
2508748 for (; PRECISION[copy2->id_prc] != '\0'; (copy2->id_prc)++) {
82
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 26054 times.
26081 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 2482667 formating = copy2;
89 2482667 formating->id_prc = -1;
90 2482667 return formating;
91 }
92
93 260574 static int check_star_wd(user_t *user,
94 formating_t *formating, formating_t *copy2, int nb)
95 {
96 260574 char str[1000] = {0};
97
98
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 260573 times.
260574 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 260573 return 0;
106 }
107
108 2495741 formating_t *find_width(user_t *user,
109 int *i, formating_t *formating)
110 {
111 2495741 char str[1000] = {0};
112 2495741 formating_t *copy2 = formating;
113 2495741 int nb = 0;
114
115
2/2
✓ Branch 0 taken 260574 times.
✓ Branch 1 taken 2495707 times.
2756281 for (; WIDTH[copy2->id_wd] != '\0'; (copy2->id_wd)++) {
116 260574 formating->index_user = user->str[*i];
117
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 260573 times.
260574 if (check_star_wd(user, formating, copy2, nb) == 1)
118 1 return copy2;
119
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 260540 times.
260573 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 2495707 formating = copy2;
128 2495707 formating->id_wd = -1;
129 2495707 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 2491440 formating_t *find_first(user_t *user,
141 int *i, formating_t *formating)
142 {
143 2491440 char str[5] = {0};
144 2491440 formating_t *copy2 = formating;
145
146
2/2
✓ Branch 0 taken 130326 times.
✓ Branch 1 taken 2491401 times.
2621727 for (; FORMATAGE[copy2->id_ft] != '\0'; (copy2->id_ft)++) {
147
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 130287 times.
130326 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 2491401 formating = copy2;
156 2491401 formating->id_ft = -1;
157 2491401 return formating;
158 }
159