some progress on c_cc[VTIME] understading, almost there

This commit is contained in:
Jack Halford 2017-01-26 18:41:07 +01:00
parent d3fd7bbded
commit 9d2e01de25
8 changed files with 33 additions and 25 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */ /* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
/* Updated: 2017/01/25 16:14:16 by jhalford ### ########.fr */ /* Updated: 2017/01/26 15:23:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -55,7 +55,7 @@ extern t_readopt g_readtab[];
int builtin_read(const char *path, char *const av[], char *const envp[]); int builtin_read(const char *path, char *const av[], char *const envp[]);
struct termios *bt_read_term(int init); struct termios bt_read_term(int init);
int bt_read_terminit(t_read *data); int bt_read_terminit(t_read *data);
int bt_read_termexit(void); int bt_read_termexit(void);

View file

@ -6,44 +6,50 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */ /* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
/* Updated: 2017/01/25 16:14:30 by jhalford ### ########.fr */ /* Updated: 2017/01/26 18:39:29 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "builtin.h" #include "builtin.h"
struct termios *bt_read_term(int init) struct termios bt_read_term(int init)
{ {
static struct termios term; static struct termios term;
if (init) if (init)
{ tcgetattr(0, &term);
if (tcgetattr(0, &term) < 0) return (term);
return (NULL);
}
return (&term);
} }
int bt_read_terminit(t_read *data) int bt_read_terminit(t_read *data)
{ {
struct termios *term; struct termios term;
(void)data; (void)data;
term = bt_read_term(1); term = bt_read_term(1);
term->c_lflag &= ~(ECHO | ICANON); term.c_lflag &= ~(ECHO | ICANON);
term->c_cc[VTIME] = 0; if (data->opts & READ_OPT_LT)
term->c_cc[VMIN] = 1; {
if (tcsetattr(0, TCSANOW, term) < 0) term.c_cc[VTIME] = data->timeout * 10;
term.c_cc[VMIN] = 0;
}
else
{
term.c_cc[VTIME] = 0;
term.c_cc[VMIN] = 1;
}
if (tcsetattr(0, TCSANOW, &term) < 0)
return (-1); return (-1);
DG("c_cc[VTIME]=%i", term.c_cc[VTIME]);
return (0); return (0);
} }
int bt_read_termexit(void) int bt_read_termexit(void)
{ {
struct termios *term; struct termios term;
term = bt_read_term(0); term = bt_read_term(0);
if (tcsetattr(0, TCSANOW, term) < 0) if (tcsetattr(0, TCSANOW, &term) < 0)
return (-1); return (-1);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */ /* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
/* Updated: 2017/01/25 16:19:50 by jhalford ### ########.fr */ /* Updated: 2017/01/26 18:39:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -102,6 +102,7 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
char buf[2]; char buf[2];
char *input; char *input;
int esc; int esc;
int ret;
(void)path; (void)path;
(void)envp; (void)envp;
@ -120,9 +121,10 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
ft_printf(data.prompt); ft_printf(data.prompt);
while (42) while (42)
{ {
if (read(data.fd, buf, 1) < 0) if ((ret = read(data.fd, buf, 1) <= 0))
return (1); return (1);
buf[1] = 0; DG("got *buf=%c, ret=%i", *buf, ret);
buf[ret] = 0;
if (!esc && *buf == data.delim) if (!esc && *buf == data.delim)
break ; break ;
esc = esc ? 0 : !(data.opts & READ_OPT_LR) && (*buf == '\\'); esc = esc ? 0 : !(data.opts & READ_OPT_LR) && (*buf == '\\');

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */ /* Created: 2016/12/03 11:56:49 by jhalford #+# #+# */
/* Updated: 2016/12/03 12:35:13 by jhalford ### ########.fr */ /* Updated: 2017/01/26 16:30:42 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */
/* Updated: 2017/01/11 15:45:53 by jhalford ### ########.fr */ /* Updated: 2017/01/26 16:30:43 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/01/11 15:38:03 by jhalford ### ########.fr */ /* Updated: 2017/01/26 15:56:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */ /* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */ /* Created: 2016/11/11 17:18:42 by jhalford #+# #+# */
/* Updated: 2017/01/22 16:44:15 by jhalford ### ########.fr */ /* Updated: 2017/01/26 18:32:42 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/01/25 17:58:18 by jhalford ### ########.fr */ /* Updated: 2017/01/26 15:16:00 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */