| 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 | #include "my.h" | ||
| 9 | #include "myformats.h" | ||
| 10 | |||
| 11 | 213 | formating_t *find_specifier(user_t *user, | |
| 12 | int *i, formating_t *formating) | ||
| 13 | { | ||
| 14 | 213 | char str[5] = {0}; | |
| 15 | 213 | formating_t *copy2 = formating; | |
| 16 | 213 | char *specifier[] = {"l", "ll", "h", "hh", "j", "z", "t", "L", NULL}; | |
| 17 | |||
| 18 | 213 | str[0] = user->str[*i]; | |
| 19 |
4/4✓ Branch 0 taken 208 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 205 times.
|
213 | if (user->str[*i + 1] == 'l' || user->str[*i + 1] == 'h') |
| 20 | 8 | str[1] = user->str[*i + 1]; | |
| 21 |
2/2✓ Branch 0 taken 1609 times.
✓ Branch 1 taken 192 times.
|
1801 | for (; specifier[copy2->id_sp] != NULL; (copy2->id_sp)++) { |
| 22 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 1588 times.
|
1609 | if (my_strcmp(str, specifier[copy2->id_sp]) == 0) { |
| 23 | 21 | my_strcat((copy2->final_format), str); | |
| 24 | 21 | return copy2; | |
| 25 | } | ||
| 26 | } | ||
| 27 | 192 | formating = copy2; | |
| 28 | 192 | formating->id_sp = -1; | |
| 29 | 192 | return formating; | |
| 30 | } | ||
| 31 | |||
| 32 | 2025 | static int check_star_prc(user_t *user, | |
| 33 | formating_t *formating, formating_t *copy2, int nb) | ||
| 34 | { | ||
| 35 | 2025 | char str[1000] = {0}; | |
| 36 | |||
| 37 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2024 times.
|
2025 | if (formating->index_user == '*') { |
| 38 | 1 | nb = va_arg(*(formating->liste), int); | |
| 39 | 1 | my_strcat(str, my_str_nbr(nb)); | |
| 40 | 1 | my_strcat((copy2->final_format), str); | |
| 41 | 1 | formating->id_nb = nb; | |
| 42 | 1 | return 1; | |
| 43 | } | ||
| 44 | 2024 | return 0; | |
| 45 | } | ||
| 46 | |||
| 47 | 101277 | formating_t *find_numbers(user_t *user, int *i, | |
| 48 | formating_t *formating) | ||
| 49 | { | ||
| 50 | 101277 | char str[1000] = {0}; | |
| 51 | 101277 | formating_t *copy2 = formating; | |
| 52 | 101277 | int nb = 0; | |
| 53 | |||
| 54 |
2/2✓ Branch 0 taken 2025 times.
✓ Branch 1 taken 101260 times.
|
103285 | for (; NUMBERS[copy2->id_nb] != '\0'; (copy2->id_nb)++) { |
| 55 | 2025 | formating->index_user = user->str[*i]; | |
| 56 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2024 times.
|
2025 | if (check_star_prc(user, formating, copy2, nb) == 1) |
| 57 | 1 | return copy2; | |
| 58 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2008 times.
|
2024 | if (user->str[*i] == NUMBERS[copy2->id_nb]) { |
| 59 | 16 | nb = my_getnbr(&user->str[*i]); | |
| 60 | 16 | my_strcat(str, my_str_nbr(nb)); | |
| 61 | 16 | my_strcat((copy2->final_format), str); | |
| 62 | 16 | formating->id_nb = nb; | |
| 63 | 16 | return copy2; | |
| 64 | } | ||
| 65 | } | ||
| 66 | 101260 | formating = copy2; | |
| 67 | 101260 | formating->id_nb = -1; | |
| 68 | 101260 | return formating; | |
| 69 | } | ||
| 70 | |||
| 71 | 101446 | formating_t *find_precision(user_t *user, | |
| 72 | int *i, formating_t *formating) | ||
| 73 | { | ||
| 74 | 101446 | char str[5] = {0}; | |
| 75 | 101446 | formating_t *copy2 = formating; | |
| 76 | |||
| 77 |
2/2✓ Branch 0 taken 213 times.
✓ Branch 1 taken 101431 times.
|
101644 | for (; PRECISION[copy2->id_prc] != '\0'; (copy2->id_prc)++) { |
| 78 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 198 times.
|
213 | if (user->str[*i] == PRECISION[copy2->id_prc]) { |
| 79 | 15 | str[0] = user->str[*i]; | |
| 80 | 15 | my_strcat((copy2->final_format), str); | |
| 81 | 15 | return copy2; | |
| 82 | } | ||
| 83 | } | ||
| 84 | 101431 | formating = copy2; | |
| 85 | 101431 | formating->id_prc = -1; | |
| 86 | 101431 | return formating; | |
| 87 | } | ||
| 88 | |||
| 89 | 1894 | static int check_star_wd(user_t *user, | |
| 90 | formating_t *formating, formating_t *copy2, int nb) | ||
| 91 | { | ||
| 92 | 1894 | char str[1000] = {0}; | |
| 93 | |||
| 94 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1893 times.
|
1894 | if (formating->index_user == '*') { |
| 95 | 1 | nb = va_arg(*(formating->liste), int); | |
| 96 | 1 | my_strcat(str, my_str_nbr(nb)); | |
| 97 | 1 | my_strcat((copy2->final_format), str); | |
| 98 | 1 | formating->id_wd = nb; | |
| 99 | 1 | return 1; | |
| 100 | } | ||
| 101 | 1893 | return 0; | |
| 102 | } | ||
| 103 | |||
| 104 | 98932 | formating_t *find_width(user_t *user, | |
| 105 | int *i, formating_t *formating) | ||
| 106 | { | ||
| 107 | 98932 | char str[1000] = {0}; | |
| 108 | 98932 | formating_t *copy2 = formating; | |
| 109 | 98932 | int nb = 0; | |
| 110 | |||
| 111 |
2/2✓ Branch 0 taken 1894 times.
✓ Branch 1 taken 98898 times.
|
100792 | for (; WIDTH[copy2->id_wd] != '\0'; (copy2->id_wd)++) { |
| 112 | 1894 | formating->index_user = user->str[*i]; | |
| 113 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1893 times.
|
1894 | if (check_star_wd(user, formating, copy2, nb) == 1) |
| 114 | 1 | return copy2; | |
| 115 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 1860 times.
|
1893 | if (user->str[*i] == WIDTH[copy2->id_wd]) { |
| 116 |
2/2✓ Branch 1 taken 5 times.
✓ Branch 2 taken 28 times.
|
33 | nb = ABS(my_getnbr(&(user->str[*i]))); |
| 117 | 33 | my_strcat(str, my_str_nbr(nb)); | |
| 118 | 33 | my_strcat((copy2->final_format), str); | |
| 119 | 33 | formating->id_wd = nb; | |
| 120 | 33 | return copy2; | |
| 121 | } | ||
| 122 | } | ||
| 123 | 98898 | formating = copy2; | |
| 124 | 98898 | formating->id_wd = -1; | |
| 125 | 98898 | return formating; | |
| 126 | } | ||
| 127 | |||
| 128 | 38 | static void check_nextesp(formating_t *copy2, formating_t *formating) | |
| 129 | { | ||
| 130 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 30 times.
|
38 | if (formating->next_chara == '+') |
| 131 | 8 | my_strcat(copy2->final_format, "+"); | |
| 132 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 37 times.
|
38 | if (formating->next_chara == '-') |
| 133 | 1 | my_strcat(copy2->final_format, "-"); | |
| 134 | 38 | } | |
| 135 | |||
| 136 | 94954 | formating_t *find_first(user_t *user, | |
| 137 | int *i, formating_t *formating) | ||
| 138 | { | ||
| 139 | 94954 | char str[5] = {0}; | |
| 140 | 94954 | formating_t *copy2 = formating; | |
| 141 | |||
| 142 |
2/2✓ Branch 0 taken 989 times.
✓ Branch 1 taken 94916 times.
|
95905 | for (; FORMATAGE[copy2->id_ft] != '\0'; (copy2->id_ft)++) { |
| 143 |
2/2✓ Branch 0 taken 38 times.
✓ Branch 1 taken 951 times.
|
989 | if (user->str[*i] == FORMATAGE[copy2->id_ft]) { |
| 144 | 38 | str[0] = user->str[*i]; | |
| 145 | 38 | formating->next_chara = (user->str[*i + 1]); | |
| 146 | 38 | my_strcat((copy2->final_format), str); | |
| 147 | 38 | check_nextesp(copy2, formating); | |
| 148 | 38 | return copy2; | |
| 149 | } | ||
| 150 | } | ||
| 151 | 94916 | formating = copy2; | |
| 152 | 94916 | formating->id_ft = -1; | |
| 153 | 94916 | return formating; | |
| 154 | } | ||
| 155 |