/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_get_res.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:28:47 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:28:47 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include static int8_t ft_checkdigit(const char *word, t_cub *clist) { size_t i; i = 0; while (ft_isdigit(word[i])) i++; if (i != ft_strlen(word)) { ft_sprintf(clist->errmsg, FT_ERR_RES_ALPHA); return (-1); } return (0); } static void ft_securize_scr(t_win *wl) { while (wl->x_size % 10) wl->x_size -= 1; while (wl->y_size % 10) wl->y_size -= 1; } static int8_t ft_check_res_args(char **words, t_cub *clist) { if (!(*words + 0) || !(*(words + 1)) || !(*(words + 2)) || (*(words + 3))) { ft_sprintf(clist->errmsg, FT_ERR_ARGS); return (-1); } return (0); } int8_t ft_get_res(char **words, t_cub *clist) { t_win *wlist; wlist = &clist->wlist; if (clist->currlvl > 0) return (0); if (ft_check_res_args(words, clist) < 0) return (-1); if ((ft_checkdigit(words[1], clist) < 0) || (ft_checkdigit(words[2], clist) < 0)) return (-1); wlist->x_size = ft_atoi(words[1]); wlist->y_size = ft_atoi(words[2]); if (wlist->x_size <= 50 || wlist->y_size <= 50) { ft_sprintf(clist->errmsg, FT_ERR_RES_SMALL); return (-1); } if (ft_get_screen_size(wlist) < 0) return (-1); ft_securize_scr(wlist); return (0); }