diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index bda0efe1..ab660d46 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -6,7 +6,7 @@ /* 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[]); -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); diff --git a/42sh/src/builtin/bt_read_term.c b/42sh/src/builtin/bt_read_term.c index c1313c16..cb57f1a9 100644 --- a/42sh/src/builtin/bt_read_term.c +++ b/42sh/src/builtin/bt_read_term.c @@ -6,44 +6,50 @@ /* 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" -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); } diff --git a/42sh/src/builtin/builtin_read.c b/42sh/src/builtin/builtin_read.c index b7298ddd..9f2b128c 100644 --- a/42sh/src/builtin/builtin_read.c +++ b/42sh/src/builtin/builtin_read.c @@ -6,7 +6,7 @@ /* 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 *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 == '\\'); diff --git a/42sh/src/lexer/lexer_backslash.c b/42sh/src/lexer/lexer_backslash.c index 9a6f2438..8439d549 100644 --- a/42sh/src/lexer/lexer_backslash.c +++ b/42sh/src/lexer/lexer_backslash.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/src/lexer/lexer_delim.c index 7542b57c..f0ceb531 100644 --- a/42sh/src/lexer/lexer_delim.c +++ b/42sh/src/lexer/lexer_delim.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index 53ed4746..8844b7db 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_append.c b/42sh/src/lexer/token_append.c index 2d2bbae1..2c422840 100644 --- a/42sh/src/lexer/token_append.c +++ b/42sh/src/lexer/token_append.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 52b34a99..e90ec878 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */