예제 #1
0
int				ft_get_data(t_hall **hall)
{
	char	*note;
	char	*line;
	int		ret;

	ret = 0;
	note = NULL;
	line = NULL;
	while ((ret = ft_gnl(0, &line)) > 0 && ft_strchr(line, '-') == 0)
	{
		if ((ret = get_hall(hall, &line, &note)) < 0)
			return (ret);
		ft_putstr_double(line, '\n');
		ft_clean_str(&line);
	}
	if (ret < 1)
	{
		if (ret == 0)
			ret = -2;
		return (ret);
	}
	if (note)
		ft_clean_str(&note);
	if ((ret = get_connect(hall, &line)) < 0)
		return (ret);
	return (0);
}
예제 #2
0
static int		get_hall(t_hall **hall, char **line, char **note)
{
	int		ret;

	if ((*line)[0] == '#')
		*note = ft_strdup(*line);
	else if ((*line)[0] == 'L')
	{
		ft_clean_str(line);
		return (-3);
	}
	else if ((*line)[0] == '\0')
	{
		ft_clean_str(line);
		return (-3);
	}
	else
	{
		if ((ret = ft_crt_lst_hall(hall, line, note)) < 0)
		{
			ft_clean_str(line);
			return (ret);
		}
		if (*note)
			ft_clean_str(note);
	}
	return (0);
}
예제 #3
0
void			ft_clean_all(t_hall **hall, t_ants **ants)
{
    t_hall		*tmp;
    t_hall		*tmp2;
    t_map		*map;

    tmp = *hall;
    tmp2 = NULL;
    map = NULL;
    clean_ants(ants);
    while (tmp)
    {
        tmp->id = tmp->x = tmp->y = tmp->stat = tmp->nbr_ants = 0;
        tmp->nbr_move = 0;
        map = tmp->map;
        clean_map(&map);
        tmp->map = NULL;
        tmp->myats = NULL;
        ft_clean_str(&tmp->name);
        if (tmp->note)
            ft_clean_str(&tmp->note);
        tmp2 = tmp->next;
        free(tmp);
        tmp = tmp2;
    }
}
예제 #4
0
파일: ft_atoi.c 프로젝트: noxsnono/42sh
int			ft_atoi(const char *str)
{
	int	result;
	int	i;
	int	negative;

	i = ft_clean_str(str);
	result = 0;
	negative = 1;
	if ((str[i] == '-') || (str[i] == '+'))
	{
		if (str[i] == '-')
			negative = -1;
		i++;
	}
	if (str[i] >= '0' && str[i] <= '9')
	{
		while ((str[i] != '\0') && (str[i] >= '0') && (str[i] <= '9'))
		{
			result = result * 10 + str[i] - '0';
			i++;
		}
		return (result * negative);
	}
	return (0);
}
예제 #5
0
static void		clean_ants(t_ants **ants)
{
    t_ants		*tmp;
    t_ants		*tmp2;

    tmp2 = NULL;
    tmp = *ants;
    while (tmp)
    {
        ft_clean_str(&tmp->name);
        tmp->room = 0;
        tmp->nbr_ants = 0;
        tmp2 = tmp->next;
        free(tmp);
        tmp = tmp2;
    }
}