Esempio n. 1
0
static int		ft_algo_bis(t_ps *a, t_ps *b, t_env *env)
{
	int i;

	i = 0;
	if (a && a->next && a->rp > a->next->rp)
		i += ft_sa(env);
	else if (b == NULL)
	{
		if (env->b_pb_first == 0)
			env->b_pb_first = a->rp;
		i += ft_pb(env);
	}
	else if (a->rp > b->rp)
		i += ft_pb(env);
	else if (a->rp < b->rp && a->rp != env->stop && ft_lstlen(env->a_first) > 3)
	{
		if (env->stop == 0)
			env->stop = a->rp;
		i += ft_ra(env);
	}
	else
		i += ft_mix_ab(env);
	return (i);
}
Esempio n. 2
0
int		ft_lstlen(t_list *lst)
{
	if (lst != NULL)
		return (ft_lstlen(lst->next) + 1);
	else
		return (0);
}
Esempio n. 3
0
File: ft_sort.c Progetto: jfaub/42
static void		ft_sort2(t_ls *list, t_ls *new_list, t_ls *save, int r)
{
	int		i;
	t_ls	*el1;
	t_ls	*max;

	el1 = list;
	max = ft_max_list(list, r);
	i = 1;
	while (i < ft_lstlen(el1))
	{
		save = max;
		while (list != NULL)
		{
			if (r * (ft_strcmp(list->name, save->name)) < 0
			&& r * (ft_strcmp(list->name, new_list->name)) > 0)
				save = list;
			list = list->next;
		}
		new_list->next = ft_ls_lstnew(save->name, save->time);
		new_list = new_list->next;
		list = el1;
		i++;
	}
}
Esempio n. 4
0
int ft_r_or_rr(t_ps *first, int cmp, int rp)
{
	int i;
	int len;

	i = 0;
	len = ft_lstlen(first);
	if (cmp)
	{
		while (first->next != NULL && cmp < first->rp)
		{
			first = first->next;
			i++;
		}
	}
	else
	{
		while (first->next != NULL && first->rp != rp)
		{
			first = first->next;
			i++;
		}
	}
	if (i > len / 2)
		return (2);
	else
		return (1);
}
Esempio n. 5
0
t_list	*ft_lstreverse(t_list *lst)
{
	t_list	*list;
	t_list	*tmp;
	t_list	*elem;
	size_t	i;
	size_t	j;

	list = NULL;
	if (lst == NULL)
		return (NULL);
	tmp = lst;
	i = ft_lstlen(lst);
	while (i > 0)
	{
		j = 1;
		while (j++ < i)
			lst = lst->next;
		elem = ft_lstnew(lst->content, lst->content_size);
		if (elem == NULL)
			return (NULL);
		ft_lstaddback(&list, elem);
		i--;
		lst = tmp;
	}
	return (list);
}
Esempio n. 6
0
t_map	*map_parse(t_list *list)
{
	t_map	*map;
	char	**tab;
	int		x;
	int		y;

	map = (t_map*)malloc(sizeof(t_map));
	if (list && map && !(y = 0))
	{
		map->y = ft_lstlen(list);
		map->wall = (int**)malloc(sizeof(int*) * map->y);
		while (list && (x = -1))
		{
			tab = ft_strsplit(list->content, ' ');
			free(list->content);
			map->x = ft_tablen(tab);
			map->wall[y] = (int*)malloc(sizeof(int) * map->x);
			while (++x < map->x)
				map->wall[y][x] = atoi_free(tab[x]);
			list = list->next;
			y++;
		}
	}
	return (map);
}
Esempio n. 7
0
void			ft_alt_down(void)
{
	t_sh		*sh;
	t_prompt	*prompt;
	t_window	window;

	sh = ft_sh();
	prompt = sh->prompt;
	window = sh->window;
	prompt->y = ((prompt->x + 3) / sh->window.col) + 1;
	prompt->max_li = ft_lstlen(prompt->l_char) / window.col;
	window.li = ft_lstlen(prompt->l_char) - (((window.col) *
		(ft_lstlen(prompt->l_char) / window.col)));
	window.li += 2;
	if (prompt->y == (ft_lstlen(prompt->l_char)) / (window.col) + 1)
		return ;
	else
		ft_is_moving(prompt, window);
}
Esempio n. 8
0
int		get_mindims(t_list *tetris)
{
	int		i;
	int		ret;

	i = ft_lstlen(tetris) * 4;
	ret = 0;
	while (ret * ret < i)
		ret++;
	return (ret);
}
Esempio n. 9
0
int			build_data(t_list *lst, t_hill *in)
{
	if ((in->len = ft_lstlen(lst)) < 1)
		return (1);
	if ((in->rooms = ft_memalloc(10 * in->len * sizeof(*in->rooms))) == NULL)
		return (1);
	while (lst != NULL)
	{
		attribute_slot(in, (t_room*)lst->content);
		lst = lst->next;
	}
	return (0);
}
Esempio n. 10
0
t_arr	*ft_lst2arr(const t_lst *lst)
{
	t_arr		*arr;
	t_lst const	*l;
	size_t		i;

	arr = ft_arrnew(ft_lstlen(lst));
	if (arr)
	{
		i = 0;
		l = lst;
		while (l)
		{
			arr[i].content = ft_memdup(l->content, l->content_size);
			arr[i].size = l->content_size;
			l = l->next;
		}
	}
	return (arr);
}
Esempio n. 11
0
char	*rl_list_to_tab(t_lst **line)
{
	char	*ret;
	t_uint	i;
	t_lst	*tmp;

	ret = (char*)ft_xmalloc(ft_lstlen(*line) + 1);
	i = 0;
	while (*line)
	{
		tmp = *line;
		ret[i++] = *((char*)(*line)->data);
		(*line) = (*line)->next;
		free(tmp->data);
		free(tmp);
	}
	ret[i] = 0;
	*line = NULL;
	return (ret);
}
Esempio n. 12
0
t_tetri	initstruc(t_list *tetris, int soldim)
{
	t_tetri	ret;
	int		i;

	i = 1;
	ret.nb = ft_lstlen(tetris);
	ret.tetris = tetris;
	ret.sol = (char*)malloc(((soldim + 1) * soldim + 1) * sizeof(char));
	while (i < (soldim + 1) * soldim + 1)
	{
		if (i % (soldim + 1))
			ret.sol[i - 1] = '.';
		else
			ret.sol[i - 1] = '\n';
		i++;
	}
	ret.sol[i] = '\0';
	return (ret);
}
Esempio n. 13
0
static void	ls_first_time(t_lsprop *prop, t_list **il, int print_title)
{
	t_list	*tmp;
	t_file	*file;

	tmp = *il;
	prop->first_time = 0;
	if (ft_lstlen(tmp) == 1)
	{
		file = (t_file *)(tmp->content);
		if (file->type != 'd')
			print_elem(prop, file);
		else
			ls_folder(prop, tmp, print_title);
	}
	else
	{
		while (tmp != NULL)
		{
			file = (t_file *)(tmp->content);
			if (file->type != 'd')
				print_elem(prop, file);// on l'affiche avec les infos affichage deja enregistrees
			tmp = tmp->next;
		}
		tmp = *il;
		reset_print_prop(prop->pp);
		while (tmp != NULL)
		{
			file = (t_file *)(tmp->content);
			if (file->type == 'd')
			{
				ft_putchar('\n');
				ls_folder(prop, tmp, SHOW_TITLE);
				if (OPT_RC)
					ls_recursive(prop, tmp);
			}
			tmp = tmp->next;
		}
	}
}
Esempio n. 14
0
void						ft_handler(int n)
{
	t_env					*env;
	int						len;

	if (n == SIGWINCH)
	{
		env = ft_sglt();
		if (tgetent(NULL, env->env) == ERROR)
			ft_perror();
		env->screen->x = tgetnum("co");
		env->screen->y = tgetnum("li");
		len = ft_lstlen();
		env->scroll = (len > env->screen->y) ? len - env->screen->y : 0;
		ft_plst();
	}
	if (n == SIGQUIT || n == SIGINT)
	{
		ft_unsetenv();
		exit(EXIT_FAILURE);
	}
}
Esempio n. 15
0
char			*ft_lststr_merge(t_list *lst, const char *separator)
{
	size_t	length;
	size_t	nb_node;
	char	*to_return;

	if (lst == NULL)
		return (NULL);
	if (separator == NULL)
		separator = "";
	nb_node = ft_lstlen(lst);
	length = ttl_length(lst);
	length += (nb_node - 1) * ft_strlen(separator);
	to_return = (char*)malloc(length);
	to_return[0] = '\0';
	while (lst != NULL)
	{
		ft_strcat(to_return, separator);
		ft_strcat(to_return, (char*)lst->content);
		lst = lst->next;
	}
	return (to_return);
}
Esempio n. 16
0
static void		ft_is_moving(t_prompt *prompt, t_window window)
{
	int i;

	prompt->index = prompt->x;
	prompt->index += window.col;
	if (prompt->index > ft_lstlen(prompt->l_char))
		return ;
	else
	{
		i = 0;
		tputs(tgoto((tgetstr("do", NULL)), 0, 0), 0, tputs_putchar);
		prompt->count = window.col - prompt->x;
		prompt->x += prompt->count;
		prompt->count = prompt->index - (window.col * prompt->y) + 4;
	}
	while (i < prompt->count)
	{
		tputs(tgoto((tgetstr("nd", NULL)), 0, 0), 0, tputs_putchar);
		i++;
	}
	prompt->count = 0;
	prompt->x = prompt->index;
}