Ejemplo n.º 1
0
int		get_next_line(int const fd, char **line)
{
	static t_list	*files;
	t_list			*node;
	t_file			*file;
	int				ret;

	file = NULL;
	node = files;
	while (node)
		if (((t_file *)(node->content))->fd == fd)
			break ;
		else
			node = node->next;
	if (!node)
		if ((node = ft_create_file(&files, fd)) == NULL)
			return (-1);
	file = (t_file *)(node->content);
	if ((ret = ft_getline(file, line)) <= 0)
	{
		if (file->buff)
			ft_memdel((void **)&(file->buff));
		ft_lst_delif(&files, node);
		return (ret);
	}
	return (1);
}
Ejemplo n.º 2
0
int		ft_getline(t_file *file, char **line)
{
	char	*end;
	char	*temp;
	char	tmp[BUFF_SIZE + 1];
	int		in;

	if ((in = read(file->fd, tmp, BUFF_SIZE)) == -1)
		return (-1);
	tmp[in] = '\0';
	if (file->buff)
	{
	   file->buff = ft_strjoinfree(file->buff, tmp, 1);
		end = ft_strchr(file->buff, '\n');
	}
	else
		return (ft_last(file, line));
	if (end == NULL)
		return ((in == 0) ? ft_last(file, line) : ft_getline(file, line));
	*end = '\0';
	*line = ft_strdup(file->buff);
	*end = '\n';
	temp = file->buff;
	file->buff = ft_strdup(end + 1);
	ft_memdel((void **)&temp);
	return (1);
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: floklein/42
t_map	*ft_read(char *s, char ***map, int flag)
{
	int		fd;
	int		line;
	t_map	*map_info;

	fd = (flag == 0) ? 0 : open(s, O_RDONLY);
	if (fd == -1)
		return (NULL);
	if ((map_info = ft_get_map_info(fd)) == NULL || !map_info->height)
		return (NULL);
	if (!(*map = (char**)malloc(sizeof(char*) * (1 + map_info->height))))
		return (NULL);
	if (((*map)[0] = ft_get_first_line(fd, map_info)) == NULL)
		return (NULL);
	map_info->width = ft_strlen((*map)[0]) - 1;
	line = 0;
	while (++line < map_info->height)
	{
		if (((*map)[line] = ft_getline(fd, map_info)) == NULL)
			return (NULL);
		(*map)[line][map_info->width + 1] = '\0';
	}
	(*map)[line] = NULL;
	if (flag && close(fd) == -1)
		return (NULL);
	return (map_info);
}
Ejemplo n.º 4
0
static int		ft_getfile(int const fd, char **line, char **file)
{
	int				ret;

	if (!*file)
		*file = ft_strnew(2);
	if (ft_strchr(*file, '\n') != NULL)
	{
		*line = *file;
		*file = ft_strdup((ft_strchr(*file, '\n') + 1));
		*line = ft_getline(*line);
		return (1);
	}
	else
	{
		ret = ft_readfile(fd, file);
		if (ret == 0 || ret == -1)
			return (ret);
		*line = *file;
		*file = ft_strdup((ft_strchr(*file, '\n')) + 1);
		*line = ft_getline(*line);
		return (1);
	}
}
Ejemplo n.º 5
0
int		main(int ac, char **av)
{
	char	*pseudo;

	pseudo = "\"";
	if (ac == 1)
	{
		ft_putstr("Usage: ./custom_zshrc <path_to_zshrc>\n");
		return (1);
	}
	ft_putstr("What's your pseudo ?\n");
	pseudo = ft_strcat(pseudo, ft_getline());
	pseudo = ft_strcat(pseudo, "\"");
	ft_insert_at(av[1], pseudo, 36);
	return (0);
}
Ejemplo n.º 6
0
void	ft_read(t_grid *grid)
{
	char	*str;
	size_t	j;

	j = 1;
	while (ft_getline(&str, grid->fd) && !g_errno)
	{
		if (j >= grid->height)
		{
			ft_errno(13);
			free(str);
			return ;
		}
		map_line(grid, str, j);
		free(str);
		j++;
	}
	free(str);
	if (j < grid->height)
		ft_errno(13);
}