Ejemplo n.º 1
0
void	ft_dlstadd_i(t_dlist **list, t_dlist *lst_new, unsigned int n)
{
	t_dlist			*nav;
	unsigned int	i;
	unsigned int	len;

	nav = *list;
	i = 1;
	len = ft_dlstlen(*list);
	if (n >= len)
		ft_dlstadd_end(list, lst_new);
	else if (n == 0)
		ft_dlstadd(list, lst_new);
	else
	{
		while (i < n)
		{
			nav = nav->next;
			i++;
		}
		lst_new->next = nav->next;
		lst_new->next->before = lst_new;
		lst_new->before = nav;
		nav->next = lst_new;
	}
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: y0ja/ft_ls
void	get_linked_lists(t_dlist **dirs_to_open, t_params *p, int ac, char **av)
{
	t_dlist		*params_files;

	params_files = NULL;
	*dirs_to_open = get_dirs_to_open(av, ac, &params_files,
		search_params(ac, av, p));
	if (p->colors)
		p->colors_tab = get_env_colors();
	files_first_ladies(params_files, p);
	if (*dirs_to_open && params_files)
		ft_putchar('\n');
	if (ft_dlstlen(*dirs_to_open) > 1)
		sort_params_dirs(dirs_to_open);
	if (params_files)
		ft_dlstdel(&params_files, NULL);
}
Ejemplo n.º 3
0
void	rl_putline(t_rl_ctx *ctx)
{
	t_dlst	*tmp;
	t_uint	len;
	t_uint	tpos;

	len = ctx->line ? ft_dlstlen(ctx->line) : 0;
	tpos = ctx->pos;
	tmp = ctx->line;
	while (tmp)
	{
		ft_putchar(*((char*)tmp->data));
		tmp = tmp->next;
	}
	while (++tpos < len)
		tputs(tgetstr("le", NULL), 0, rl_putchar);
}
Ejemplo n.º 4
0
void	ft_dlstrev(t_dlist **list)
{
	t_dlist	*nav;
	t_dlist *last;
	int		len;

	nav = *list;
	len = (ft_dlstlen(*list) / 2);
	last = ft_dlstlast(*list);
	while (len)
	{
		ft_swap_contents(&nav, &last);
		nav = nav->next;
		last = last->before;
		len--;
	}
}
Ejemplo n.º 5
0
void		insert_sort(char *da_file, t_dlist **files, t_mega *all)
{
	int			len;
	t_dlist		*nav;
	struct stat	sb;

	len = ft_dlstlen(*files);
	nav = ft_dlstlast(*files);
	da_file = ft_strjoin(all->p.file, da_file);
	if (stat(da_file, &sb) != -1
		&& !(S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode)))
	{
		return ;
	}
	while (len > 0)
	{
		if (ft_strcmp(nav->content, da_file) < 0)
			break ;
		nav = nav->before;
		len--;
	}
	ft_dlstadd_i(files, ft_dlstnew(da_file, (ft_strlen(da_file) + 1)), len);
}
Ejemplo n.º 6
0
void	rl_clear_screen(t_rl_ctx *ctx)
{
	t_dlst	*tmp;
	t_uint	len;
	t_uint	tpos;

	tputs(tgetstr("cl", NULL), 0, rl_putchar);
	rl_putheader(ctx);
	tmp = ctx->line;
	if (tmp)
	{
		while (tmp->prev)
			tmp = tmp->prev;
		while (tmp)
		{
			ft_putchar(*((char*)tmp->data));
			tmp = tmp->next;
		}
		len = ctx->line ? ft_dlstlen(ctx->line) : 0;
		tpos = ctx->pos;
		while (tpos++ < len)
			tputs(tgetstr("le", NULL), 0, rl_putchar);
	}
}
Ejemplo n.º 7
0
void		insert_sort(char *da_file, t_dlist **files, char *path)
{
	int				len;
	t_dlist			*nav;
	t_file			data;

	len = ft_dlstlen(*files);
	nav = ft_dlstlast(*files);
	data.filename = ft_strdup(da_file);
	if (path == NULL)
		data.path = data.filename;
	else
		data.path = path_file(path, da_file, 0);
	if (lstat(data.path, &data.sb) == -1)
		error(BAD_PATH, data.path);
	while (len > 0)
	{
		if (ft_strcmp(((t_file *)nav->content)->filename, da_file) < 0)
			break ;
		nav = nav->before;
		len--;
	}
	ft_dlstadd_i(files, ft_dlstnew(&data, sizeof(t_file)), len);
}