| 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 | 228 | formating_t *find_specifier(user_t *user, | |
| 16 | int *i, formating_t *formating) | ||
| 17 | { | ||
| 18 | 228 | char str[5] = {0}; | |
| 19 | 228 | formating_t *copy2 = formating; | |
| 20 | 228 | char *specifier[] = {"l", "ll", "h", "hh", "j", "z", "t", "L", NULL}; | |
| 21 | |||
| 22 | 228 | str[0] = user->str[*i]; | |
| 23 |
4/4✓ Branch 0 taken 223 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 220 times.
|
228 | if (user->str[*i + 1] == 'l' || user->str[*i + 1] == 'h') |
| 24 | 8 | str[1] = user->str[*i + 1]; | |
| 25 |
2/2✓ Branch 0 taken 1729 times.
✓ Branch 1 taken 207 times.
|
1936 | for (; specifier[copy2->id_sp] != NULL; (copy2->id_sp)++) { |
| 26 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 2 taken 1708 times.
|
1729 | if (my_strcmp(str, specifier[copy2->id_sp]) == 0) { |
| 27 | 21 | my_strcat((copy2->final_format), str); | |
| 28 | 21 | return copy2; | |
| 29 | } | ||
| 30 | } | ||
| 31 | 207 | formating = copy2; | |
| 32 | 207 | formating->id_sp = -1; | |
| 33 | 207 | return formating; | |
| 34 | } | ||
| 35 | |||
| 36 | 2099 | static int check_star_prc(user_t *user, | |
| 37 | formating_t *formating, formating_t *copy2, int nb) | ||
| 38 | { | ||
| 39 | 2099 | char str[1000] = {0}; | |
| 40 | |||
| 41 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2098 times.
|
2099 | 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 | 2098 | return 0; | |
| 49 | } | ||
| 50 | |||
| 51 | 101123 | formating_t *find_numbers(user_t *user, int *i, | |
| 52 | formating_t *formating) | ||
| 53 | { | ||
| 54 | 101123 | char str[1000] = {0}; | |
| 55 | 101123 | formating_t *copy2 = formating; | |
| 56 | 101123 | int nb = 0; | |
| 57 | |||
| 58 |
2/2✓ Branch 0 taken 2099 times.
✓ Branch 1 taken 101094 times.
|
103193 | for (; NUMBERS[copy2->id_nb] != '\0'; (copy2->id_nb)++) { |
| 59 | 2099 | formating->index_user = user->str[*i]; | |
| 60 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2098 times.
|
2099 | if (check_star_prc(user, formating, copy2, nb) == 1) |
| 61 | 1 | return copy2; | |
| 62 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 2070 times.
|
2098 | 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 | 101094 | formating = copy2; | |
| 71 | 101094 | formating->id_nb = -1; | |
| 72 | 101094 | return formating; | |
| 73 | } | ||
| 74 | |||
| 75 | 101292 | formating_t *find_precision(user_t *user, | |
| 76 | int *i, formating_t *formating) | ||
| 77 | { | ||
| 78 | 101292 | char str[5] = {0}; | |
| 79 | 101292 | formating_t *copy2 = formating; | |
| 80 | |||
| 81 |
2/2✓ Branch 0 taken 228 times.
✓ Branch 1 taken 101265 times.
|
101493 | for (; PRECISION[copy2->id_prc] != '\0'; (copy2->id_prc)++) { |
| 82 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 201 times.
|
228 | 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 | 101265 | formating = copy2; | |
| 89 | 101265 | formating->id_prc = -1; | |
| 90 | 101265 | return formating; | |
| 91 | } | ||
| 92 | |||
| 93 | 2044 | static int check_star_wd(user_t *user, | |
| 94 | formating_t *formating, formating_t *copy2, int nb) | ||
| 95 | { | ||
| 96 | 2044 | char str[1000] = {0}; | |
| 97 | |||
| 98 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2043 times.
|
2044 | 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 | 2043 | return 0; | |
| 106 | } | ||
| 107 | |||
| 108 | 113715 | formating_t *find_width(user_t *user, | |
| 109 | int *i, formating_t *formating) | ||
| 110 | { | ||
| 111 | 113715 | char str[1000] = {0}; | |
| 112 | 113715 | formating_t *copy2 = formating; | |
| 113 | 113715 | int nb = 0; | |
| 114 | |||
| 115 |
2/2✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 113681 times.
|
115725 | for (; WIDTH[copy2->id_wd] != '\0'; (copy2->id_wd)++) { |
| 116 | 2044 | formating->index_user = user->str[*i]; | |
| 117 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2043 times.
|
2044 | if (check_star_wd(user, formating, copy2, nb) == 1) |
| 118 | 1 | return copy2; | |
| 119 |
2/2✓ Branch 0 taken 33 times.
✓ Branch 1 taken 2010 times.
|
2043 | 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 | 113681 | formating = copy2; | |
| 128 | 113681 | formating->id_wd = -1; | |
| 129 | 113681 | 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 | 109414 | formating_t *find_first(user_t *user, | |
| 141 | int *i, formating_t *formating) | ||
| 142 | { | ||
| 143 | 109414 | char str[5] = {0}; | |
| 144 | 109414 | formating_t *copy2 = formating; | |
| 145 | |||
| 146 |
2/2✓ Branch 0 taken 1061 times.
✓ Branch 1 taken 109375 times.
|
110436 | for (; FORMATAGE[copy2->id_ft] != '\0'; (copy2->id_ft)++) { |
| 147 |
2/2✓ Branch 0 taken 39 times.
✓ Branch 1 taken 1022 times.
|
1061 | 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 | 109375 | formating = copy2; | |
| 156 | 109375 | formating->id_ft = -1; | |
| 157 | 109375 | return formating; | |
| 158 | } | ||
| 159 |