builtin read assignment and termcaps fix
This commit is contained in:
parent
8b6fd7bb1d
commit
cc7b533ee8
2 changed files with 7 additions and 10 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
|
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/25 04:20:00 by jhalford ### ########.fr */
|
/* Updated: 2017/03/29 15:02:36 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -28,12 +28,9 @@ int bt_read_terminit(t_read *data)
|
||||||
term = bt_read_term(1);
|
term = bt_read_term(1);
|
||||||
if (!(data->flag & BT_READ_INTER))
|
if (!(data->flag & BT_READ_INTER))
|
||||||
return (0);
|
return (0);
|
||||||
term.c_lflag = ECHO | ECHOE | ECHOK | ICANON;
|
term.c_lflag &= ~(ICANON | ECHO);
|
||||||
term.c_lflag &= data->timeout ? ~ICANON : ~0;
|
|
||||||
term.c_cc[VTIME] = data->timeout * 10;
|
term.c_cc[VTIME] = data->timeout * 10;
|
||||||
term.c_cc[VMIN] = data->timeout ? 0 : 1;
|
term.c_cc[VMIN] = data->timeout ? 0 : 1;
|
||||||
if (data->flag & BT_READ_LS)
|
|
||||||
term.c_lflag &= ~ECHO;
|
|
||||||
term.c_cc[VEOL] = data->delim;
|
term.c_cc[VEOL] = data->delim;
|
||||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/25 15:10:27 by jhalford ### ########.fr */
|
/* Updated: 2017/03/29 15:10:51 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -58,9 +58,10 @@ int bt_read_loop(t_read *data)
|
||||||
ft_printf(data->prompt);
|
ft_printf(data->prompt);
|
||||||
while (42)
|
while (42)
|
||||||
{
|
{
|
||||||
if ((ret = read(data->fd, buf, 1)) <= 0)
|
if ((ret = read(data->fd, buf, 4)) <= 0)
|
||||||
return (ret);
|
return (ret);
|
||||||
buf[ret] = 0;
|
buf[ret] = 0;
|
||||||
|
ft_putchar(data->flag & BT_READ_LS ? 0 : *buf);
|
||||||
if (!esc && *buf == data->delim)
|
if (!esc && *buf == data->delim)
|
||||||
break ;
|
break ;
|
||||||
esc = esc ? 0 : !(data->flag & BT_READ_LR) && (*buf == '\\');
|
esc = esc ? 0 : !(data->flag & BT_READ_LR) && (*buf == '\\');
|
||||||
|
|
@ -89,11 +90,10 @@ int bt_read_assign(t_read *data)
|
||||||
tok = ft_strtok(input, ifs);
|
tok = ft_strtok(input, ifs);
|
||||||
while (*names)
|
while (*names)
|
||||||
{
|
{
|
||||||
if (!(builtin_setenv("setenv", (char*[]){"read", *names, tok}, NULL)))
|
if ((builtin_setenv("setenv", (char*[]){"read", *names, tok}, NULL)))
|
||||||
return (1);
|
return (1);
|
||||||
ifs = names[1] ? ifs : NULL;
|
ifs = (++names)[1] ? ifs : NULL;
|
||||||
tok = ft_strtok(NULL, ifs);
|
tok = ft_strtok(NULL, ifs);
|
||||||
names++;
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue