Example #1
0
File: ft_ls.c Project: smurfy92/42
void	process(t_lstdir *lst)
{
	ft_ls_l(lst);
	while (lst->next)
	{
		printf("test : %s\n",(lst->buf)->d_name);
		ft_ls_l(lst->next);
		lst = lst->next;
	}
}
Example #2
0
void	ft_l(t_steve *list, t_opts *opt)
{
	int		total;
	t_steve	*tmp;
	t_size	*space;

	total = 0;
	space = NULL;
	if (ft_ls_l(list) == 0)
	{
		tmp = list;
		while (tmp != NULL)
		{
			total = total + tmp->block;
			tmp = tmp->next;
		}
		free(tmp);
		ft_putstr("total ");
		ft_putnbr(total);
		write(1, "\n", 1);
		ft_init_space(list, &space);
		ft_add_ls_l(list, opt, space);
	}
	while (list != NULL)
		list = list->next;
}
Example #3
0
void	ft_parse_options(int argc, char **argv)
{
	int		i;
	size_t	j;
	char	tab[256];

	i = 1;
	if (argc == 1)
		ft_list_files(argc, argv);
	while (i < argc)
	{	
		if (argv[i][0] != '-' || argv[i][1] == '-')
		{
			if (argv[i][1] == '-')
				ft_illegal_options(argv[i][j]);
			if (argv[i][1] == '\0')
				ft_putendl("ls: -: No such file or directory");
			return ;
		}
		j = 1;
		while (argv[i][j])
		{
			tab[(size_t)(unsigned char)argv[i][j]] = 1;
			if (ft_isoption(argv[i][j]) == 0)
			{
				ft_illegal_options(argv[i][j]);
				return ;
			}
			j++;
		}
		i++;
		if (tab[(size_t)(unsigned char)'l'] == 1)
				ft_ls_l(argc, argv);
	}
}
Example #4
0
void	ft_add_gr(t_steve *list, t_opts *opt)
{
	int		rec;
	t_steve	*tmp;

	rec = 0;
	while (list != NULL)
	{
		tmp = NULL;
		if (opt->l == 0)
			ft_ls_l(list);
		if (list->access[0] == 'd' && ft_strcmp(list->file, ".") != 0
			&& ft_strcmp(list->file, "..") != 0)
		{
			ft_putchar('\n');
			ft_putstr(list->path);
			ft_putendl(":");
			ft_find(list->path, &tmp, opt, rec);
		}
		list = list->next;
	}
}
Example #5
0
static int			ft_get_stats(t_file *tmp, t_dir *dir, t_opt *opt)
{
	char		*path;

	if (dir->name[ft_strlen(dir->name) - 1] == '/')
		path = ft_strjoin(dir->name, tmp->name);
	else
	{
		path = ft_strnew(ft_strlen(dir->name) + ft_strlen(tmp->name) + 2);
		path = ft_strcpy(path, dir->name);
		path = ft_strcat(path, "/");
		path = ft_strcat(path, tmp->name);
	}
	if (path == NULL)
		return (-1);
	if (lstat(path, &tmp->inf) == 0)
		ft_ls_l(tmp, dir, path, opt);
	else
		opt->ret = ft_perror(path, NULL);
	if (path)
		free(path);
	return (opt->ret);
}