20static t_type_fc get_type_of_fc(
const char *line,
const char *key[])
27 if (is_key_line(line, key[type]) ==
true)
34static void set_fc_color(
t_game *game,
int *color)
36 game->floor_color = color[ENUM_F];
37 game->ceiling_color = color[ENUM_C];
38 game->frame.ceiling_color = &game->ceiling_color;
39 game->frame.floor_color = &game->floor_color;
42static int check_error_rgb_value(
t_result result,
const char rgb_type)
44 if (result.value >= 0)
45 return (EXIT_SUCCESS);
46 if (result.value == -1)
47 ft_eprintf(
"%s%c: %s %s\n",
48 ERR_PROMPT, rgb_type, EMSG_RGB_MISS, result.err_msg);
49 if (result.value == -2)
51 ft_eprintf(
"%s%c: \"", ERR_PROMPT, rgb_type);
52 print_until_ch(STDERR_FILENO, result.err_msg,
',');
53 ft_eprintf(
"\" %s\n", EMSG_RGB_RANGE_OUT);
55 if (result.value == -3)
57 ft_eprintf(
"%s%c: \"", ERR_PROMPT, rgb_type);
58 print_until_ch(STDERR_FILENO, result.err_msg,
',');
59 ft_eprintf(
"\" %s\n", EMSG_RGB_NOT_NUM);
61 if (result.value == -4)
62 ft_eprintf(
"%s%c: %s %s\n",
63 ERR_PROMPT, rgb_type, EMSG_UP_TO_THREE_RGB, result.err_msg);
64 return (EXIT_FAILURE);
67int get_fc_color(
const char *first_word,
int *color)
69 const char *next_word;
73 next_word = find_next_word(first_word);
74 if (next_word == NULL)
76 ft_eprintf(
"%s%c: %s\n",
77 ERR_PROMPT, *first_word, EMSG_RGB_EMPTY);
78 return (EXIT_FAILURE);
80 str = strdup_trimmed_line(next_word);
82 return (EXIT_FAILURE);
83 result = get_rgb_color(str);
84 if (check_error_rgb_value(result, *first_word) != EXIT_SUCCESS)
87 return (EXIT_FAILURE);
89 *color = result.value;
91 return (EXIT_SUCCESS);
119int parse_fc(
const char *line,
t_parse *parse)
122 const char *key[2] = {
"F ",
"C "};
123 const int bit[2] = {BIT_F, BIT_C};
124 static int color[2] = {-1, -1};
126 parse->fc_info = (
t_info){.key = key, .bit = bit};
127 type = get_type_of_fc(line, parse->fc_info.key);
128 if (check_duplicate_info(parse->flag, bit[type], line) != EXIT_SUCCESS)
129 return (EXIT_FAILURE);
130 if (get_fc_color(line, &color[type]) != EXIT_SUCCESS)
131 return (EXIT_FAILURE);
132 parse->flag |= parse->fc_info.bit[type];
133 if (check_for_not_matching_bit(parse->flag, BIT_F | BIT_C) == 0x00)
135 set_fc_color(parse->game, color);
136 parse->flag |= BIT_INIT_FC;
138 return (EXIT_SUCCESS);