piscine-rush00-ultra/arghandle.c

67 lines
1.9 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* arghandle.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/18 23:37:32 by tischmid #+# #+# */
/* Updated: 2023/03/19 03:30:53 by tischmid ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include "include/ft_lib.h"
const int g_default_max_width = 200;
const int g_default_max_height = 200;
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");
}