42-archive/42sh/src/line-editing/readline.c
2017-03-16 14:20:44 +01:00

31 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* readline.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/16 14:06:39 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int readline(int prompt, char **input)
{
int ret;
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret);
readline_init(prompt);
*input = ft_read_stdin();
if (STR)
ft_current_str(STR, POS);
ft_putchar('\n');
if (!prompt)
*input = ft_history_parsing();
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
return (-1);
return (0);
}