termios stuff added

This commit is contained in:
Jack Halford 2017-01-25 18:13:15 +01:00
parent 8e3f84cef1
commit d3fd7bbded
6 changed files with 73 additions and 27 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/22 18:04:23 by jhalford ### ########.fr */ /* Updated: 2017/01/25 16:14:16 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -53,12 +53,16 @@ struct s_readopt
extern t_readopt g_readtab[]; 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[]);
int bt_read_getdelim(t_read *data, char *arg); struct termios *bt_read_term(int init);
int bt_read_getnchars(t_read *data, char *arg); int bt_read_terminit(t_read *data);
int bt_read_getprompt(t_read *data, char *arg); int bt_read_termexit(void);
int bt_read_gettimeout(t_read *data, char *arg);
int bt_read_getfd(t_read *data, char *arg); int bt_read_getdelim(t_read *data, char *arg);
int bt_read_getnchars(t_read *data, char *arg);
int bt_read_getprompt(t_read *data, char *arg);
int bt_read_gettimeout(t_read *data, char *arg);
int bt_read_getfd(t_read *data, char *arg);
#endif #endif

View file

@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* bt_read_term.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 16:02:05 by jhalford #+# #+# */
/* Updated: 2017/01/25 16:14:30 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "builtin.h"
struct termios *bt_read_term(int init)
{
static struct termios term;
if (init)
{
if (tcgetattr(0, &term) < 0)
return (NULL);
}
return (&term);
}
int bt_read_terminit(t_read *data)
{
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)
return (-1);
return (0);
}
int bt_read_termexit(void)
{
struct termios *term;
term = bt_read_term(0);
if (tcsetattr(0, TCSANOW, term) < 0)
return (-1);
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/22 18:21:50 by jhalford ### ########.fr */ /* Updated: 2017/01/25 16:19:50 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -64,16 +64,13 @@ int bt_read_parse(t_read *data, char **av)
while (av[i]) while (av[i])
{ {
j = 0; j = 0;
DG("check 1");
if (av[i][j++] == '-') if (av[i][j++] == '-')
{ {
if (av[i][j] == '-' && av[i][j + 1] == 0) if (av[i][j] == '-' && av[i][j + 1] == 0)
{ {
DG("check 2");
i++; i++;
break ; break ;
} }
DG("check 3");
while (av[i][j]) while (av[i][j])
{ {
if (!(opt = bt_read_getopt(av[i][j]))) if (!(opt = bt_read_getopt(av[i][j])))
@ -89,7 +86,6 @@ int bt_read_parse(t_read *data, char **av)
} }
j++; j++;
} }
DG("check 4");
} }
else else
break ; break ;
@ -103,7 +99,7 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
{ {
t_read data; t_read data;
int i; int i;
char buf[5]; char buf[2];
char *input; char *input;
int esc; int esc;
@ -117,32 +113,29 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
DG("\ndelim=%c\nnchars=%i\nprompt=%s\ntimeout=%i\nfd=%i", DG("\ndelim=%c\nnchars=%i\nprompt=%s\ntimeout=%i\nfd=%i",
data.delim, data.nchars, data.prompt, data.timeout, data.fd); data.delim, data.nchars, data.prompt, data.timeout, data.fd);
ft_sstrprint(data.names, ','); ft_sstrprint(data.names, ',');
bt_read_terminit(&data);
i = 0; i = 0;
esc = 0; esc = 0;
if (data.prompt) if (data.prompt)
ft_printf(data.prompt); ft_printf(data.prompt);
while (42) while (42)
{ {
if (read(0, buf, 1) < 0) if (read(data.fd, buf, 1) < 0)
return (1); return (1);
buf[1] = 0; buf[1] = 0;
if (!esc && *buf == data.delim) if (!esc && *buf == data.delim)
{
DG("CHECK 1");
break ; break ;
}
if (*buf == '\n' && !(data.opts & READ_OPT_LR))
ft_putstr("> ");
esc = esc ? 0 : !(data.opts & READ_OPT_LR) && (*buf == '\\'); esc = esc ? 0 : !(data.opts & READ_OPT_LR) && (*buf == '\\');
ft_strappend(&input, buf); ft_strappend(&input, buf);
ft_putchar(*buf);
i++; i++;
DG("%i:%i", data.opts & READ_OPT_LN, i >= data.nchars); if (*buf == '\n' && !(data.opts & READ_OPT_LR))
ft_putstr("> ");
if ((data.opts & READ_OPT_LN) && i >= data.nchars) if ((data.opts & READ_OPT_LN) && i >= data.nchars)
{
DG("CHECK 2");
break ; break ;
}
} }
ft_putchar('\n');
DG("input=%s", input); DG("input=%s", input);
bt_read_termexit();
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */ /* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 16:50:26 by sbenning #+# #+# */ /* Created: 2016/12/08 16:50:26 by sbenning #+# #+# */
/* Updated: 2017/01/21 18:40:44 by jhalford ### ########.fr */ /* Updated: 2017/01/25 15:04:17 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */ /* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/08 18:03:48 by sbenning #+# #+# */ /* Created: 2016/12/08 18:03:48 by sbenning #+# #+# */
/* Updated: 2017/01/22 18:15:18 by jhalford ### ########.fr */ /* Updated: 2017/01/25 15:04:22 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/21 18:04:06 by jhalford ### ########.fr */ /* Updated: 2017/01/25 17:58:18 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -33,7 +33,7 @@ int shell_single_command(char *command)
token_print(token); token_print(token);
if (ft_parse(&ast, &token)) if (ft_parse(&ast, &token))
return (1); return (1);
/* btree_print(STDBUG, ast, &ft_putast); */ btree_print(STDBUG, ast, &ft_putast);
/* /1* ft_dprintf(STDBUG, "\n--- INFIX BREAKDOWN ---\n"); *1/ */ /* /1* ft_dprintf(STDBUG, "\n--- INFIX BREAKDOWN ---\n"); *1/ */
/* /1* btree_apply_infix(ast, &ft_putast2); *1/ */ /* /1* btree_apply_infix(ast, &ft_putast2); *1/ */
if (ft_exec(&ast)) if (ft_exec(&ast))