Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | ** EPITECH PROJECT, 2023 | ||
3 | ** my_printf | ||
4 | ** File description: | ||
5 | ** The functions for format an int | ||
6 | */ | ||
7 | |||
8 | #include <stddef.h> | ||
9 | #include "my.h" | ||
10 | #include "myformats.h" | ||
11 | |||
12 | 4 | static void do_next(char *str_finale, formating_t *formating, double nb) | |
13 | { | ||
14 | 4 | void (*format[])(char *, formating_t *, size_t) = | |
15 | {&format_moins_int, &format_plus_int, &format_esp_int, | ||
16 | &format_hash_int, &format_zero_int}; | ||
17 | |||
18 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | for (int j = 0; j < 5; j++) { |
19 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3 times.
|
7 | if (formating->next_chara == FORMATAGE[j]) { |
20 | 4 | formating->next_chara = 1; | |
21 | 4 | format[j](str_finale, formating, nb); | |
22 | 4 | return; | |
23 | } | ||
24 | } | ||
25 | } | ||
26 | |||
27 | 4 | static void en_plus(char *str_finale, formating_t *formating) | |
28 | { | ||
29 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
|
6 | for (int i = my_strlen(str_finale); i < formating->id_wd; i++) |
30 | 2 | my_strcat(str_finale, " "); | |
31 | 4 | } | |
32 | |||
33 | 5 | void format_plus_int(char *str_finale, | |
34 | formating_t *formating, size_t nb) | ||
35 | { | ||
36 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | if ((formating->flag != 'b') |
37 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | && (formating->flag != 'x') && (formating->flag != 'X') |
38 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | && (formating->flag != 'o') && (formating->flag != 'u')){ |
39 | 5 | my_revstr(str_finale); | |
40 | 5 | my_strcat(str_finale, "+"); | |
41 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 1 times.
|
5 | if (formating->id_wd != -1 && formating->next_chara != '-') |
42 | 4 | en_plus(str_finale, formating); | |
43 | 5 | my_revstr(str_finale); | |
44 | } | ||
45 |
3/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
|
5 | if (formating->next_chara == '+' || formating->next_chara == '-') |
46 | 1 | do_next(str_finale, formating, nb); | |
47 | 5 | } | |
48 | |||
49 | 3 | void format_moins_int(char *str_finale, | |
50 | formating_t *formating, size_t nb) | ||
51 | { | ||
52 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
|
3 | if (formating->next_chara == '+') |
53 | 1 | formating->id_wd -= 1; | |
54 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if ((my_strlen(str_finale) < formating->id_wd |
55 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | && formating->next_chara == '+') |
56 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | || my_strlen(str_finale) < formating->id_wd) { |
57 |
2/2✓ Branch 1 taken 13 times.
✓ Branch 2 taken 3 times.
|
16 | for (int i = my_strlen(str_finale); i < formating->id_wd; i++) { |
58 | 13 | my_strcat(str_finale, " "); | |
59 | } | ||
60 | } | ||
61 |
3/4✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
3 | if (formating->next_chara == '+' || formating->next_chara == '-') |
62 | 1 | do_next(str_finale, formating, nb); | |
63 | 3 | } | |
64 | |||
65 | 9 | void format_esp_int(char *str_finale, formating_t *formating, size_t nb) | |
66 | { | ||
67 |
3/4✓ Branch 0 taken 8 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
|
9 | if (formating->next_chara == '+' || formating->next_chara == '-') |
68 | 1 | do_next(str_finale, formating, nb); | |
69 | 9 | my_revstr(str_finale); | |
70 |
2/2✓ Branch 1 taken 7 times.
✓ Branch 2 taken 9 times.
|
16 | for (int i = my_strlen(str_finale); i < formating->id_wd; i++) |
71 | 7 | my_strcat(str_finale, " "); | |
72 | 9 | my_revstr(str_finale); | |
73 | 9 | } | |
74 | |||
75 | 2 | void format_zero_int(char *str_finale, | |
76 | formating_t *formating, size_t nb) | ||
77 | { | ||
78 | 2 | long long int i = my_strlen(str_finale); | |
79 | |||
80 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (formating->next_chara != '-') { |
81 | 2 | my_revstr(str_finale); | |
82 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 6 times.
|
11 | for (i; (i < formating->id_wd && formating->next_chara != '+') |
83 |
5/6✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
|
16 | || (i < formating->id_wd - 1 && formating->next_chara == '+'); i++) |
84 | 8 | my_strcat(str_finale, "0"); | |
85 | 2 | my_revstr(str_finale); | |
86 | } | ||
87 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2 | if (formating->next_chara == '+' || formating->next_chara == '-') |
88 | 1 | do_next(str_finale, formating, nb); | |
89 | 2 | } | |
90 | |||
91 | 7 | void format_hash_int(char *str_finale, | |
92 | formating_t *formating, size_t nb) | ||
93 | { | ||
94 | 7 | format_esp_int(str_finale, formating, nb); | |
95 | 7 | return; | |
96 | } | ||
97 |