61 lines
1.8 KiB
C
61 lines
1.8 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* arghandle.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2023/03/18 23:37:32 by tischmid #+# #+# */
|
|
/* Updated: 2023/03/18 23:37:33 by tischmid ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
int get_dim(char *type, int default_max)
|
|
{
|
|
char output[10];
|
|
char cmd[11];
|
|
int max;
|
|
FILE *fp;
|
|
|
|
ft_strcpy(cmd, "tput ");
|
|
ft_strcat(cmd, type);
|
|
fp = popen(cmd, "r");
|
|
if (fp == NULL)
|
|
max = default_max;
|
|
else
|
|
while (fgets(output, sizeof(output), fp) != NULL)
|
|
max = ft_atoi(output);
|
|
pclose(fp);
|
|
return (max);
|
|
}
|
|
|
|
int wrong_dimension(char *dim, int max, int actual)
|
|
{
|
|
ft_putstr("\033[31mOutput will not fit into terminal (term");
|
|
ft_putstr(dim);
|
|
ft_putstr(" ");
|
|
ft_putnbr(max);
|
|
ft_putstr(" provided ");
|
|
ft_putstr(dim);
|
|
ft_putstr(" ");
|
|
ft_putnbr(actual);
|
|
ft_putstr(")\033[m\n");
|
|
return (2);
|
|
}
|
|
|
|
void usage(char *argv0)
|
|
{
|
|
ft_putstr("\033[32mUsage: ");
|
|
ft_putstr(argv0);
|
|
ft_putstr(" [width] [height]\033[m\n");
|
|
}
|
|
|
|
void wrong_argc(int expected, int argc)
|
|
{
|
|
ft_putstr("\033[31mWrong number of arguments (expected ");
|
|
ft_putnbr(expected);
|
|
ft_putstr(" got ");
|
|
ft_putnbr(argc);
|
|
ft_putstr(")\033[m\n");
|
|
}
|