termios stuff added
This commit is contained in:
parent
8e3f84cef1
commit
d3fd7bbded
6 changed files with 73 additions and 27 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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[];
|
||||
|
||||
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);
|
||||
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);
|
||||
struct termios *bt_read_term(int init);
|
||||
int bt_read_terminit(t_read *data);
|
||||
int bt_read_termexit(void);
|
||||
|
||||
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
|
||||
|
|
|
|||
49
42sh/src/builtin/bt_read_term.c
Normal file
49
42sh/src/builtin/bt_read_term.c
Normal 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);
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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])
|
||||
{
|
||||
j = 0;
|
||||
DG("check 1");
|
||||
if (av[i][j++] == '-')
|
||||
{
|
||||
if (av[i][j] == '-' && av[i][j + 1] == 0)
|
||||
{
|
||||
DG("check 2");
|
||||
i++;
|
||||
break ;
|
||||
}
|
||||
DG("check 3");
|
||||
while (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++;
|
||||
}
|
||||
DG("check 4");
|
||||
}
|
||||
else
|
||||
break ;
|
||||
|
|
@ -103,7 +99,7 @@ int builtin_read(const char *path, char *const av[], char *const envp[])
|
|||
{
|
||||
t_read data;
|
||||
int i;
|
||||
char buf[5];
|
||||
char buf[2];
|
||||
char *input;
|
||||
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",
|
||||
data.delim, data.nchars, data.prompt, data.timeout, data.fd);
|
||||
ft_sstrprint(data.names, ',');
|
||||
bt_read_terminit(&data);
|
||||
i = 0;
|
||||
esc = 0;
|
||||
if (data.prompt)
|
||||
ft_printf(data.prompt);
|
||||
while (42)
|
||||
{
|
||||
if (read(0, buf, 1) < 0)
|
||||
if (read(data.fd, buf, 1) < 0)
|
||||
return (1);
|
||||
buf[1] = 0;
|
||||
if (!esc && *buf == data.delim)
|
||||
{
|
||||
DG("CHECK 1");
|
||||
break ;
|
||||
}
|
||||
if (*buf == '\n' && !(data.opts & READ_OPT_LR))
|
||||
ft_putstr("> ");
|
||||
esc = esc ? 0 : !(data.opts & READ_OPT_LR) && (*buf == '\\');
|
||||
ft_strappend(&input, buf);
|
||||
ft_putchar(*buf);
|
||||
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)
|
||||
{
|
||||
DG("CHECK 2");
|
||||
break ;
|
||||
}
|
||||
}
|
||||
ft_putchar('\n');
|
||||
DG("input=%s", input);
|
||||
bt_read_termexit();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
if (ft_parse(&ast, &token))
|
||||
return (1);
|
||||
/* btree_print(STDBUG, ast, &ft_putast); */
|
||||
btree_print(STDBUG, ast, &ft_putast);
|
||||
/* /1* ft_dprintf(STDBUG, "\n--- INFIX BREAKDOWN ---\n"); *1/ */
|
||||
/* /1* btree_apply_infix(ast, &ft_putast2); *1/ */
|
||||
if (ft_exec(&ast))
|
||||
|
|
|
|||
Loading…
Reference in a new issue