Exemple #1
0
int		main(int ac, char **av)
{
	t_params	p;
	t_dlist		*dirs_to_open;
	t_dlist		*nav;
	t_dlist		*dir_files;
	t_colors	*colors;

	dir_files = NULL;
	init_struct(&p);
	get_linked_lists(&dirs_to_open, &p, ac, av);
	nav = dirs_to_open;
	while (nav)
	{
		if (nav->before != NULL || nav->next != NULL)
			ft_print_twostr(nav->content, ":\n");
		get_da_list(&dir_files, &p, nav->content);
		if_forest_params(&dir_files, nav, &p, 1);
		ft_dlstdel(&dir_files, del_struct);
		if (nav->next)
			ft_putchar('\n');
		nav = nav->next;
	}
	ft_dlstdel(&nav, NULL);
	if (p.colors)
		free(p.colors_tab);
	return (0);
}
Exemple #2
0
char        	*cd_cleanpath(char *path)
{
	t_dlist		*lst;
	t_dlist		*clean;
	char      	cpath[2048];
	char      	*pref;

	if (!ft_strcmp("-", path))
	{
		if (!(path = ft_getenv("OLDPWD")))
			cd_exit("OLDPWD needed in the environment");
		return (ft_strdup(path));
	}
	else if (*path != '/')
	{
		if (!(pref = ft_getenv("PWD")))
		cd_exit("PWD needed in the environment");
		ft_sprintf(cpath, "%s/%s/", pref, path);
	}
	else
		ft_sprintf(cpath, "%s/", path);
	if (!(lst = makelst(cpath)))
		return (NULL);
	if (!(clean = ft_dlstmap(lst, cleanlst)))
		return (NULL);
	ft_dlstdel(&lst, NULL);
	clean = cleanlstparent(clean);
	return (convertlst(&clean));
}
Exemple #3
0
int			hist_copy(t_hist *hist, t_hist *hist_cp)
{
	hist->cursor = hist->list;
	while (hist->cursor)
	{
		hist_cp->cursor = ft_dlstnew(hist->cursor->content,\
									hist->cursor->content_size);
		if (!hist_cp->cursor)
		{
			ft_dlstdel(&hist_cp->list, NULL);
			return (-1);
		}
		ft_dlstaddn(&hist_cp->list, hist_cp->cursor);
		hist->cursor = hist->cursor->n;
	}
	if (!(hist_cp->cursor = ft_dlstnew(NULL, 0)))
	{
		ft_dlstdel(&hist_cp->list, NULL);
		return (-1);
	}
	ft_dlstaddn(&hist_cp->list, hist_cp->cursor);
	return (0);
}
Exemple #4
0
void		putmyenv(t_dlist *newlst, t_opt *opt, t_env *env)
{
	if (opt->rec && newlst)
	{
		env->start = 0;
		env->flag = 1;
		print_rep(newlst, opt, env);
	}
	if (newlst)
	{
		ft_dlstdel(&newlst->head, del2);
		free(newlst);
	}
}
Exemple #5
0
int		hist_save(t_hist *hist)
{
	int	fd;

	if (!(fd = open(".42sh_history", O_WRONLY | O_CREAT, 0755)))
		return (-1);
	hist->cursor = hist->list;
	while (hist->cursor)
	{
		ft_fprintf(fd, "%s\n", (char *)hist->cursor->content);
		hist->cursor = hist->cursor->n;
	}
	ft_dlstdel(&hist->list, NULL);
	close(fd);
	return (0);
}
Exemple #6
0
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);
}
Exemple #7
0
char		*convertlst(t_dlist **alst)
{
	char	path[2048];
	t_dlist	*drive;

	ft_bzero((void *)path, 2048);
	drive = *alst;
	while (drive)
	{
		if (drive->content)
		{
			ft_strcat(path, "/");
			ft_strncat(path, (char *)drive->content, drive->content_size);
		}
		drive = drive->n;
	}
	ft_dlstdel(alst, NULL);
	return (ft_strdup(path));
}
Exemple #8
0
static char			*clean(char *path, char *cpath)
{
	t_dlist			*lst;
	t_dlist			*clean;

	if (!(lst = makelst(cpath)))
	{
		ft_error("Memory allocation failed");
		return (NULL);
	}
	if (!(clean = ft_dlstmap(lst, cleanlst)))
	{
		ft_error("Memory allocation failed");
		return (NULL);
	}
	ft_dlstdel(&lst, NULL);
	clean = cleanlstparent(clean);
	return (convertlst(&clean));
	(void)path;
}
Exemple #9
0
void			sh_clear(t_sh *sh)
{
	ft_dlstdel(&sh->hist.list, NULL);											//Cleaning dlist of char *
	ft_dicdel(&sh->bin, NULL);													//Cleaning dic of char *
}
Exemple #10
0
void			sh_clear(t_sh *sh)
{
	ft_dlstdel(&sh->hist.list, NULL);
	ft_dicdel(&sh->bin, NULL);
}