get_fd
This commit is contained in:
parent
c04006a471
commit
661cb0eb8b
6 changed files with 35 additions and 48 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/20 20:21:45 by ariard ### ########.fr */
|
||||
/* Updated: 2017/02/21 14:27:57 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -178,7 +178,7 @@ void ft_c(void);
|
|||
void ft_x(void);
|
||||
void ft_v(void);
|
||||
void ft_read_it(int input, size_t *pos, char **str);
|
||||
char *readline(char *);
|
||||
char *readline(int fd, char *prompt);
|
||||
int ft_completion(int ret);
|
||||
|
||||
struct termios *ft_save_termios(int save);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/20 22:39:18 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/21 14:28:48 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/20 22:39:45 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/20 22:43:47 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/20 22:21:35 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/20 22:43:53 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
|
||||
/* Updated: 2017/02/16 12:45:32 by gwojda ### ########.fr */
|
||||
/* Updated: 2017/02/21 14:20:16 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -95,10 +95,15 @@ void readline_init(char *prompt)
|
|||
prompt ? ft_putstr(prompt) : ft_prompt();
|
||||
}
|
||||
|
||||
char *readline(char *prompt)
|
||||
char *readline(int fd, char *prompt)
|
||||
{
|
||||
char *input;
|
||||
|
||||
if (fd != STDIN)
|
||||
{
|
||||
get_next_line(fd, &input);
|
||||
return (input);
|
||||
}
|
||||
readline_init(prompt);
|
||||
input = ft_read_stdin();
|
||||
ft_putchar('\n');
|
||||
|
|
|
|||
|
|
@ -6,54 +6,25 @@
|
|||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||
/* Updated: 2017/02/20 21:52:34 by jhalford ### ########.fr */
|
||||
/* Updated: 2017/02/21 14:29:13 by jhalford ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "minishell.h"
|
||||
|
||||
int non_interactive_shell(char *command)
|
||||
{
|
||||
t_list *token;
|
||||
t_lexer lexer;
|
||||
t_btree *ast;
|
||||
|
||||
lexer_init(&lexer);
|
||||
lexer.str = command;
|
||||
token = NULL;
|
||||
ast = NULL;
|
||||
while (lexer.str[lexer.pos])
|
||||
{
|
||||
if (lexer.stack && *(int*)lexer.stack->content == BACKSLASH)
|
||||
pop(&lexer.stack);
|
||||
do {
|
||||
lexer_lex(&token, &lexer);
|
||||
} while (lexer.str[lexer.pos] == '\n');
|
||||
if (!token)
|
||||
return (0);
|
||||
// if (bquotes_expand(&token))
|
||||
// return (1);
|
||||
//token_print(token);
|
||||
if (ft_parse(&ast, &token))
|
||||
return (1);
|
||||
if (ft_exec(&ast))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
int interactive_shell()
|
||||
int handle_instruction(int fd)
|
||||
{
|
||||
t_list *token;
|
||||
t_list *ltoken;
|
||||
t_lexer lexer;
|
||||
t_btree *ast;
|
||||
char *str;
|
||||
|
||||
lexer_init(&lexer);
|
||||
token = NULL;
|
||||
ast = NULL;
|
||||
do {
|
||||
char *str = readline(stack_to_prompt(lexer.stack));
|
||||
str = readline(fd, stack_to_prompt(lexer.stack));
|
||||
ft_strappend(&lexer.str, str);
|
||||
if (get_lexer_stack(lexer) == BACKSLASH)
|
||||
pop(&lexer.stack);
|
||||
|
|
@ -64,8 +35,6 @@ int interactive_shell()
|
|||
return (1);
|
||||
//token_print(token);
|
||||
} while (get_lexer_stack(lexer));
|
||||
// if (bquotes_expand(&token))
|
||||
// return (1);
|
||||
if (!token)
|
||||
return (0);
|
||||
ft_add_str_in_history(lexer.str);
|
||||
|
|
@ -78,20 +47,33 @@ int interactive_shell()
|
|||
return (0);
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
int get_input_fd()
|
||||
{
|
||||
t_data *data;
|
||||
|
||||
data = data_singleton();
|
||||
if (SH_IS_INTERACTIVE(data->opts))
|
||||
return (STDIN);
|
||||
/* else if (data->opts & SHELL_OPTS_LC) */
|
||||
/* { */
|
||||
/* } */
|
||||
else
|
||||
{
|
||||
return (open(shell_get_avdata(), O_RDONLY));
|
||||
}
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
int fd;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
shell_init(ac, av);
|
||||
// DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s", SH_HAS_JOBC(data->opts)?"ON":"OFF");
|
||||
if (SH_IS_INTERACTIVE(data->opts))
|
||||
fd = get_input_fd();
|
||||
while (handle_instruction(fd))
|
||||
{
|
||||
while (1)
|
||||
interactive_shell();
|
||||
;
|
||||
}
|
||||
else
|
||||
non_interactive_shell(shell_get_avdata());
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue