Ejemplo n.º 1
0
int				get_next_line(int const fd, char **line)
{
	static char *stock[256];
	char		*ptr;
	char		*tmp;
	char		*buffer;
	int			ret;

	buffer = ft_strnew(BUFF_SIZE + 1);
	if ((check_stock(&stock[fd], &line, buffer)) == 1)
		return (1);
	while ((ret = read(fd, buffer, BUFF_SIZE)) > 0)
	{
		buffer[ret] = '\0';
		tmp = ft_strchr(buffer, '\n');
		if ((check_tmp(tmp, &line, &stock[fd], buffer)) == 1)
			return (1);
		ptr = stock[fd];
		stock[fd] = ft_strjoin(stock[fd], buffer);
		free(ptr);
	}
	if (ret < 0)
		return (ft_return(ret, stock[fd], &line));
	if ((ft_checkdown(&line, &stock[fd])) == 0)
		return (0);
	return (ft_return(ret, stock[fd], &line));
}
Ejemplo n.º 2
0
int					get_next_line(int fd, char **line)
{
	char			buff[BUFF_SIZE + 1];
	int				ret;
	static char		*save = NULL;
	char			*tmp;

	ret = 0;
	if (fd == -1 || BUFF_SIZE <= 0)
		return (ft_error(&save));
	if (save == NULL)
		save = ft_strnew(BUFF_SIZE + 1);
	while (save != NULL
			&& ft_strchr(save, '\n') == NULL
			&& ((ret = read(fd, buff, BUFF_SIZE)) > 0))
	{
		buff[ret] = '\0';
		tmp = save;
		save = ft_strjoin(tmp, buff);
		free(tmp);
	}
	if (ret == -1)
		return (-1);
	if (ret < BUFF_SIZE && ft_strchr(save, '\n') == NULL)
		return (ft_eof(line, &save));
	ft_return(line, &(save));
	return (1);
}
Ejemplo n.º 3
0
int			ft_atoi(const char *s)
{
	int		i;
	int		state;
	int		p;
	char	*str;

	ft_initthreevar(&i, &p, &state);
	str = ft_strdup(s);
	if (str)
	{
		while ((*str > 0x00) && (*str <= 0x20))
		{
			str++;
		}
		if (*str == '+' || *str == '-')
		{
			if (*str == '+')
				p = 1;
			state++;
			str++;
		}
		while (*str != '\0' && ft_isdigit(*str))
			i = i * 10 + *str++ - '0';
		i = ft_return(i, p, state);
	}
	return (i);
}
Ejemplo n.º 4
0
int			ft_read_term(t_arg_list **begin, int fd)
{
	int		ret;
	char	*buf;
	int		i;

	buf = ft_strnew(10);
	ft_print_list(*begin, fd);
	ret = read(fd, buf, 9);
	i = ft_interpret(buf, ret, begin, fd);
	free(buf);
	if (i == 1)
		ft_return(*begin);
	return (i);
}
Ejemplo n.º 5
0
void	term_event(unsigned int key, t_caps *caps)
{
	if (key == 27)
		ft_exit(caps, 1);
	else if (ft_check_size(caps) == -1)
		return ;
	else if (key == 4345627)
		move_down(caps);
	else if (key == 4280091)
		move_top(caps);
	else if (key == 32)
		ft_select(caps);
	else if (key == 127 || key == 2117294875)
		ft_delete(caps);
	else if (key == 10 || key == 5066523)
		ft_return(caps);
}
Ejemplo n.º 6
0
void		return_selected(t_select **begin_list)
{
	t_select	*tmp;
	int			i;
	int			j;

	tmp = *begin_list;
	j = 0;
	i = 0;
	tputs(tgetstr("cl", NULL), 0, ft_outc);
	while (tmp != *begin_list || j == 0)
	{
		j = 1;
		if (tmp->selected == 1)
		{
			i == 0 ? i = 1 : ft_putchar(' ');
			ft_printf("%s", tmp->name);
		}
		tmp = tmp->next;
	}
	ft_return(0);
}
Ejemplo n.º 7
0
void		del_elem(t_select **begin_list)
{
	t_select *tmp;
	t_select *tmp2;

	tmp = *begin_list;
	tmp2 = *begin_list;
	tmp = tmp->next;
	if (list_len(begin_list) == 1)
		ft_return(0);
	while (tmp->hover == 0)
	{
		tmp2 = tmp2->next;
		tmp = tmp->next;
	}
	tmp2->next = tmp->next;
	if (tmp == *begin_list)
		*begin_list = tmp->next;
	free(tmp);
	tmp = tmp2->next;
	tmp->hover = 1;
	init_term(0);
}