some progress on c_cc[VTIME] understading, almost there
This commit is contained in:
parent
d3fd7bbded
commit
9d2e01de25
8 changed files with 33 additions and 25 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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[]);
|
||||
|
||||
struct termios *bt_read_term(int init);
|
||||
struct termios bt_read_term(int init);
|
||||
int bt_read_terminit(t_read *data);
|
||||
int bt_read_termexit(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,44 +6,50 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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"
|
||||
|
||||
struct termios *bt_read_term(int init)
|
||||
struct termios bt_read_term(int init)
|
||||
{
|
||||
static struct termios term;
|
||||
|
||||
|
||||
if (init)
|
||||
{
|
||||
if (tcgetattr(0, &term) < 0)
|
||||
return (NULL);
|
||||
}
|
||||
return (&term);
|
||||
tcgetattr(0, &term);
|
||||
return (term);
|
||||
}
|
||||
|
||||
int bt_read_terminit(t_read *data)
|
||||
{
|
||||
struct termios *term;
|
||||
struct termios term;
|
||||
|
||||
(void)data;
|
||||
term = bt_read_term(1);
|
||||
term->c_lflag &= ~(ECHO | ICANON);
|
||||
term->c_cc[VTIME] = 0;
|
||||
term->c_cc[VMIN] = 1;
|
||||
if (tcsetattr(0, TCSANOW, term) < 0)
|
||||
term.c_lflag &= ~(ECHO | ICANON);
|
||||
if (data->opts & READ_OPT_LT)
|
||||
{
|
||||
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);
|
||||
DG("c_cc[VTIME]=%i", term.c_cc[VTIME]);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int bt_read_termexit(void)
|
||||
{
|
||||
struct termios *term;
|
||||
struct termios term;
|
||||
|
||||
term = bt_read_term(0);
|
||||
if (tcsetattr(0, TCSANOW, term) < 0)
|
||||
if (tcsetattr(0, TCSANOW, &term) < 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 *input;
|
||||
int esc;
|
||||
int ret;
|
||||
|
||||
(void)path;
|
||||
(void)envp;
|
||||
|
|
@ -120,9 +121,10 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
|
|||
ft_printf(data.prompt);
|
||||
while (42)
|
||||
{
|
||||
if (read(data.fd, buf, 1) < 0)
|
||||
if ((ret = read(data.fd, buf, 1) <= 0))
|
||||
return (1);
|
||||
buf[1] = 0;
|
||||
DG("got *buf=%c, ret=%i", *buf, ret);
|
||||
buf[ret] = 0;
|
||||
if (!esc && *buf == data.delim)
|
||||
break ;
|
||||
esc = esc ? 0 : !(data.opts & READ_OPT_LR) && (*buf == '\\');
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue