read works with escape sequences

This commit is contained in:
Jack Halford 2017-02-06 14:05:44 +01:00
parent f63737a90c
commit 1649b6a294
6 changed files with 13 additions and 12 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
/* Updated: 2017/01/27 19:00:10 by jhalford ### ########.fr */
/* Updated: 2017/02/06 13:56:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,9 @@ int bt_read_terminit(t_read *data)
(void)data;
term = bt_read_term(1);
term.c_lflag &= ~(ECHO | ICANON);
term.c_lflag &= ~(ICANON);
if (data->opts & READ_OPT_LS)
term.c_lflag &= ~(ECHO);
if (data->opts & READ_OPT_LT)
{
term.c_cc[VTIME] = data->timeout * 10;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
/* Updated: 2017/01/27 19:40:12 by jhalford ### ########.fr */
/* Updated: 2017/02/06 14:02:17 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,14 +28,15 @@ t_readopt g_readtab[] =
{0, 0, 0},
};
int bt_read_loop(t_read *data)
{
int i;
int esc;
char buf[2];
i = 0;
esc = 0;
i = 0;
if (data->prompt)
ft_printf(data->prompt);
while (42)
@ -43,12 +44,11 @@ int bt_read_loop(t_read *data)
if (read(data->fd, buf, 1) <= 0)
return (1);
buf[1] = 0;
DG("got input [%x]", *buf);
if (!esc && *buf == data->delim)
break ;
esc = esc ? 0 : !(data->opts & READ_OPT_LR) && (*buf == '\\');
ft_strappend(&data->input, buf);
if (!(data->opts & READ_OPT_LS))
ft_putchar(*buf);
if (*buf == '\n' && !(data->opts & READ_OPT_LR))
ft_putstr("> ");
if ((data->opts & READ_OPT_LN) && ++i >= data->nchars)
@ -73,6 +73,7 @@ int bt_read_assign(t_read *data)
{
if (!(names[1]) || !IFS)
{
DG("setting env: %s=%x%x%x", *names, *start, start[1],start[2]);
builtin_setenv("setenv", (char*[]){"setenv", *names, start}, NULL);
break ;
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
/* Updated: 2017/01/27 19:00:07 by jhalford ### ########.fr */
/* Updated: 2017/02/06 14:05:23 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,8 +34,6 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[])
str = ft_str3join(av[0], "=", av[1]);
while ((*env)[i])
{
/* DG("check 2: i=%i, (*env)[i]=%p",i, (*env)[i]); */
/* DG("content=%s", (*env)[i]); */
if (ft_strcmp((*env)[i], av[0]) == '=')
{
ft_strdel(&(*env)[i]);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/10 14:54:57 by jhalford #+# #+# */
/* Updated: 2017/01/27 15:55:54 by wescande ### ########.fr */
/* Updated: 2017/02/06 14:02:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/10 14:57:53 by jhalford #+# #+# */
/* Updated: 2017/01/27 15:56:40 by wescande ### ########.fr */
/* Updated: 2017/02/06 14:05:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/02/03 17:33:56 by jhalford ### ########.fr */
/* Updated: 2017/02/06 13:26:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */