示例#1
0
int			get_next_line(int const fd, char **line)
{
	static char		*s;
	int				ret;
	char			buf[BUFF_SIZE + 1];
	int				n;

	ret = 1;
	while (ret > 0 && ft_isin(s) == 0)
	{
		if ((ret = read(fd, buf, BUFF_SIZE)) == -1)
			return (-1);
		buf[ret] = '\0';
		s = ft_readline(s, buf);
	}
	n = ft_isin(s);
	if (ret == 0 && n == 0)
	{
		*line = s;
		return (0);
	}
	if (n > 0)
	{
		s = ft_tobesave(s, n - 1, line);
		return (1);
	}
	return (-1);
}
示例#2
0
文件: main.c 项目: sbenning42/42
int			main(int ac, char **av, char **ep)
{
	char	*line;
	char	*prompt;
	t_lxem	*lex;

	prompt = (ac < 2 ? "" : av[1]);
	g_ftenviron = ep;
	while (42)
	{
		line = ft_readline(prompt, (RL_GECHO | RL_GHISTORY | RL_GSAVE | RL_GLOAD), ft_getenv(ep, "TERM"));
		if (line)
		{
			if (!ft_strcmp(line, "exit"))
			{
				ft_memdel((void **)&line);
				break ;
			}
			if ((lex = ft_lexer(line)))
				lx_del(&lex);
			ft_memdel((void **)&line);
		}
	}
	ft_atexit(EXIT_SUCCESS, av[0], "main: Success");
	return (0);
}