Example #1
0
t_file		*new_fstat(t_max_l *len, char *path_name, t_flag *flg, int dir)
{
	t_file			*new_node;
	t_stat			st;

	if ((new_node = (t_file *)ft_memalloc(sizeof(t_file))) == NULL)
		ft_error_system();
	if ((lstat(path_name, &st)) != 0)
	{
		ft_putstr_fd("ft_ls: ", 2);
		perror(storage_name(path_name));
		free(new_node);
		return (NULL);
	}
	new_node->st = st;
	if ((new_node->name = storage_name(path_name)) == NULL)
		ft_error_system();
	if ((new_node->path = ft_strdup(path_name)) == NULL)
		ft_error_system();
	if (dir == TRUE)
		ft_strdel(&path_name);
	if (flg->aff == 'l')
		storage_max_len(len, &st, flg);
	new_node->next = NULL;
	return (new_node);
}
Example #2
0
void	update_score(t_map *m, char c)
{
	char	*convert_score;
	int		i;

	if ((convert_score = ft_itoa(m->score)) == NULL)
		ft_error_system();
	i = 0;
	if (c == '.')
		m->score += 5;
	tputs(tgoto(tgetstr("cm", NULL), (m->nb_char + 13),
	calcul_pos(m->nb_line, 1)), 1, myputc);
	ft_strcolor_fd(convert_score, H_RED, 2, 1);
	ft_strdel(&(convert_score));
}
Example #3
0
char	*cmd_line_to_str(t_cmd_line *cl)
{
	t_cmd_line_char	*current;
	char			*ret;
	int				i;

	if (!(ret = ft_strnew(cl->len)))
		ft_error_system();
	current = cl->chars;
	i = 0;
	while (current)
	{
		ret[i++] = current->c;
		current = current->next;
	}
	return (ret);
}
Example #4
0
static char	*storage_path(char *path, char *name)
{
	size_t	end;
	char	*path_file;
	char	*tmp;

	end = (ft_strlen(path) - 1);
	if (path[end] == '/')
		path_file = ft_strjoin(path, name);
	else
	{
		tmp = ft_strjoin(path, "/");
		path_file = ft_strjoin(tmp, name);
		ft_strdel(&tmp);
	}
	if (path_file == NULL)
		ft_error_system();
	return (path_file);
}
Example #5
0
File: main.c Project: Ibouch/42_ls
int			main(int ac, char **av)
{
	t_env	*e;

	if ((e = (t_env *)ft_memalloc(sizeof(t_env))) == NULL)
		ft_error_system();
	params_parsing(ac, av, e);
	if (e->err == NULL && (e->dir == NULL && e->file == NULL))
	{
		if (e->flg->d == TRUE)
			file_lstadd(e, ".", FALSE);
		else
			dir_lstadd(&e->dir, e->flg, ".");
	}
	print_file_lst(e);
	print_dir_lst(e);
	del_env(&e);
	return (e->global_err);
}