Beispiel #1
0
static void				fdf_get_screen_size(int argc, int *args,
		char **argv, t_fdf_window *wptr)
{
	int					size[2];

	size[0] = FDF_SCREEN_WIDTH;
	size[1] = FDF_SCREEN_HEIGHT;
	if (*args + 2 < argc
			&& !ft_strcmp(argv[*args], "--Screen")
			&& ft_strisdigit(argv[*args + 1])
			&& ft_strisdigit(argv[*args + 2]))
	{
		ft_putendl("Importing size arguments");
		size[0] = ft_atoi(argv[*args + 1]);
		size[1] = ft_atoi(argv[*args + 2]);
		*args += 3;
	}
	else if (*args + 2 < argc && !ft_strcmp(argv[*args], "--Screen"))
		ft_putendl("Error: incorrect size arguments. Using defaults");
	else
		ft_putendl("No size arguments. Using defaults");
	wptr->size_x = (FDF_SCREEN_MAX >= size[0]
			&& size[0] > 0 ? size[0] : FDF_SCREEN_WIDTH);
	wptr->size_y = (FDF_SCREEN_MAX >= size[1]
			&& size[1] > 0 ? size[1] : FDF_SCREEN_HEIGHT);
}
Beispiel #2
0
int			init_option(int nb, char **ar, t_option *op, int *len)
{
	init_op(op);
	while (--nb > 0)
		if (!ft_strisdigit(ar[nb]))
		{
			if (!ft_strcmp(ar[nb], "-c") || !ft_strcmp(ar[nb], "-C"))
				op->color++;
			else if (!ft_strcmp(ar[nb], "-v") || !ft_strcmp(ar[nb], "-V"))
				op->etape++;
			else if (!ft_strcmp(ar[nb], "-f") || !ft_strcmp(ar[nb], "-F"))
				op->finalpile++;
			else if (!ft_strcmp(ar[nb], "-o") || !ft_strcmp(ar[nb], "-O"))
				op->nbop++;
			else
				return (0);
		}
		else
		{
			if (!verif_nbr(ar[nb])
				|| ft_atol(ar[nb]) > 2147483647
					|| ft_atol(ar[nb]) < -2147483648 || ft_strlen(ar[nb]) > 13)
				return (0);
			else
				(*len)++;
		}
	return (1);
}
Beispiel #3
0
int		analyse_cone(t_cone **cone, t_lstline **list, int *line)
{
	int		nb_obj;
	char	**str;
	int		i;

	if (*cone != NULL || !ft_strisdigit(&(*list)->line[9]))
		return (1);
	nb_obj = ft_atoi(&(*list)->line[9]);
	i = -1;
	*cone = (t_cone *)ft_memalloc(sizeof(t_cone) * (nb_obj + 1));
	while (++i < nb_obj)
	{
		next_line(list, line);
		if (ft_strncmp((*list)->line, "\t\t\t", 3) != 0)
			return (1);
		str = ft_strsplit(&(*list)->line[3], '/');
		if (!analyse_cone_help((*list)->line, str, &(*cone)[i]))
			return (1);
		(*cone)[i].ray_size = ft_absd(ft_atoid(str[1]));
		(*cone)[i].height = ft_absd(ft_atoid(str[2]));
		ft_memdel2((void ***)&str);
	}
	(*cone)[nb_obj].end = -1;
	next_line(list, line);
	return (0);
}
Beispiel #4
0
int		analyse_spot(t_spot **spot, t_lstline **list, int *line)
{
	int		nb_obj;
	char	**str;
	int		i;

	if (*spot != NULL || !ft_strisdigit(&(*list)->line[9]))
		return (1);
	nb_obj = ft_atoi(&(*list)->line[9]);
	i = -1;
	*spot = (t_spot *)ft_memalloc(sizeof(t_spot) * (nb_obj + 1));
	while (++i < nb_obj)
	{
		next_line(list, line);
		if (ft_strncmp((*list)->line, "\t\t\t", 3) != 0)
			return (1);
		str = ft_strsplit(&(*list)->line[3], '/');
		if (!analyse_slash((*list)->line, 2) || ft_memlen((void **)str) != 2 ||
		!analyse_3d_value_d(str[0], &(*spot)[i].x, &(*spot)[i].y,
		&(*spot)[i].z) || !ft_strisdouble(str[1]))
			return (1);
		(*spot)[i].lux = ft_absd(ft_atoid(str[1]));
		ft_memdel2((void ***)&str);
	}
	(*spot)[nb_obj].end = -1;
	next_line(list, line);
	return (0);
}
Beispiel #5
0
int		ft_read_entry(t_game *game)
{
	char	*entry;
	int		end;
	int		result;

	end = 0;
	while (end == 0)
	{
		ft_putstr("Column? ");
		if ((get_next_line(0, &entry) > 0) && ft_strisdigit(entry))
		{
			result = ft_atoi(entry);
			if (result <= game->col && result >= 1)
			{
				if (game->grid[0][result - 1] == 0)
					end = 1;
				else
					ft_putstr("Col is already full\n");
			}
			else
				ft_putstr("Bad column\n");
		}
		else
			ft_putstr("Please enter a number\n");
	}
	return (result);
}
Beispiel #6
0
int		get_ants(t_env *e)
{
	if (get_comments(e) == 0)
	{
		if (ft_strisdigit(e->line) != 0)
		{
			e->n_ants = ft_atof(e->line);
			if (e->n_ants < MIN_INT || e->n_ants > MAX_INT)
				return (-1);
			if (e->n_ants <= 0)
				return (-1);
		}
		else
			return (-1);
		e->n_read++;
	}
	else if (get_comments(e) == -1)
		return (1);
	return (0);
}
Beispiel #7
0
void				ft_test_exit(char **cmd, t_shell *sh)
{
	int				i;

	i = 0;
	if (ft_strcmp(cmd[0], "exit") == 0)
	{
		if (!cmd[1] || (cmd[1] && !cmd[2]))
		{
			if (cmd[1] && ft_strisdigit(cmd[1]))
				i = ft_atoi(cmd[1]);
			if (cmd[0])
				ft_strdel2(&cmd);
			if (sh->cmd)
				ft_strdel2(&sh->cmd);
			if (sh->env)
				ft_strdel2(&sh->env);
			exit(i);
		}
		else if (cmd[1] && cmd[2])
			ft_putendl("exit: too many arguments");
	}
}