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