mean cleanup

This commit is contained in:
Jack Halford 2017-03-16 15:04:21 +01:00
parent 6efd4c7e1f
commit bed9f1d6c2
12 changed files with 87 additions and 68 deletions

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/03/16 14:15:02 by jhalford ### ########.fr */
/* Updated: 2017/03/16 15:04:04 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -36,6 +36,7 @@ struct s_data
{
t_flag opts;
char **env;
char **local_var;
int argc;
char **argv;
t_line line;
@ -43,7 +44,6 @@ struct s_data
t_exec exec;
t_jobc jobc;
t_list *heredoc_queue;
char **local_var;
t_list *lst_func;
};

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 10:58:49 by ariard #+# #+# */
/* Updated: 2017/03/16 14:18:05 by jhalford ### ########.fr */
/* Updated: 2017/03/16 14:24:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
/* Updated: 2017/03/15 02:04:38 by ariard ### ########.fr */
/* Updated: 2017/03/16 14:56:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/26 00:07:05 by ariard #+# #+# */
/* Updated: 2017/03/13 16:55:08 by ariard ### ########.fr */
/* Updated: 2017/03/16 14:41:00 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/21 21:05:23 by ariard #+# #+# */
/* Updated: 2017/03/15 16:31:49 by gwojda ### ########.fr */
/* Updated: 2017/03/16 14:41:14 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */
/* Updated: 2017/03/09 14:53:42 by jhalford ### ########.fr */
/* Updated: 2017/03/16 14:44:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */
/* Updated: 2017/03/13 15:41:30 by jhalford ### ########.fr */
/* Updated: 2017/03/16 14:45:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -58,7 +58,8 @@ int lexer_lex(t_list **alst, t_lexer *lexer)
if (!*alst)
{
token = token_init();
*alst = ft_lstnew(token, sizeof(*token));
if (!(*alst = ft_lstnew(token, sizeof(*token))))
return (-1);
}
return ((*g_lexer[lexer->state])(alst, lexer));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */
/* Updated: 2017/03/11 20:46:32 by ariard ### ########.fr */
/* Updated: 2017/03/16 14:44:46 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:34:44 by gwojda #+# #+# */
/* Updated: 2017/03/16 10:37:03 by gwojda ### ########.fr */
/* Updated: 2017/03/16 14:58:45 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,7 +24,7 @@ void ft_init_line(void)
data_singleton()->line.opt = 0;
}
void readline_init(int prompt)
void readline_init(int has_prompt)
{
static int beg = 0;
@ -40,6 +40,6 @@ void readline_init(int prompt)
ft_strdel(&STR);
data_singleton()->line.list_cur = data_singleton()->line.list_beg;
POS = 0;
prompt ? ft_putstr("> ") : ft_prompt();
has_prompt ? ft_prompt() : ft_putstr("> ");
data_singleton()->line.is_prompt = prompt ? 0 : 1;
}

View file

@ -6,24 +6,24 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/16 14:06:39 by jhalford ### ########.fr */
/* Updated: 2017/03/16 14:58:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int readline(int prompt, char **input)
int readline(int has_prompt, char **input)
{
int ret;
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
return ((ret = get_next_line(STDIN, input)) >= 0 ? !ret : ret);
readline_init(prompt);
readline_init(has_prompt);
*input = ft_read_stdin();
if (STR)
ft_current_str(STR, POS);
ft_putchar('\n');
if (!prompt)
if (has_prompt)
*input = ft_history_parsing();
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
return (-1);

View file

@ -6,70 +6,88 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/16 14:10:44 by jhalford ### ########.fr */
/* Updated: 2017/03/16 15:02:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static int handle_instruction( t_list **token,
t_btree **ast,
t_lexer lexer,
t_parser parser)
static int do_lexer_routine(t_list **token, t_lexer *lexer)
{
t_list *ltoken;
char *str;
int ret;
if (lexer->state == HEREDOC)
{
ft_strappend(&lexer->str, (char[]){'\n', 0});
lexer->pos++;
}
ft_strappend(&lexer->str, str);
if (get_lexer_stack(lexer) == BACKSLASH)
pop(&lexer->stack);
ltoken = ft_lstlast(*token);
if (lexer_lex(token ? &ltoken : token, lexer) < 1)
exit(1);
if (get_lexer_stack(lexer) > 2)
return (1);
lexer->state = DEFAULT;
return (0);
}
static int do_parser_routine(t_list **token, t_lexer *lexer, t_parser *parser)
{
if (get_reserved_words(token))
return (1);
token_print(*token);
if (insert_newline(token))
return (1);
ft_parse(ast, token, &parser);
if ((lexer->state = data_singleton()->heredoc_queue ? HEREDOC : DEFAULT))
return (0);
if (parse->state == ERROR)
{
error_syntax(token, &parser, ast);
return (1);
}
else if (parser->state == SUCCESS)
return (1);
return (0);
}
static int do_readline_routine(t_list **token, t_lexer *lexer, t_parser *parser)
{
int ret;
int prompt;
char *str;
has_prompt = !(get_lexer_stack(lexer) || parser->state == UNDEFINED || lexer->state == HEREDOC);
ret = readline(has_prompt, &str);
{
if (ret == -1)
return (-1);
return (parser.state == UNDEFINED ? error_eof(token,
&parser, ast) : 1);
}
}
static int handle_instruction( t_list **token,
t_btree **ast,
t_lexer *lexer,
t_parser *parser)
{
while (1)
{
if ((ret = readline(get_lexer_stack(lexer) ||
parser.state == UNDEFINED || lexer.state == HEREDOC, &str)))
{
if (ret == -1)
return (-1);
return (parser.state == UNDEFINED ? error_eof(token,
&parser, ast) : 1);
}
if (lexer.state == HEREDOC)
{
ft_strappend(&lexer.str, (char[]){'\n', 0});
lexer.pos++;
}
ft_strappend(&lexer.str, str);
if (get_lexer_stack(lexer) == BACKSLASH)
pop(&lexer.stack);
ltoken = ft_lstlast(*token);
if (lexer_lex(token ? &ltoken : token, &lexer))
return (1);
if (get_lexer_stack(lexer) > 2)
if (do_readline_routine(lexer, parser) > 0)
if (do_lexer_routine(token, lexer) > 0)
continue ;
lexer.state = DEFAULT;
if (get_reserved_words(token))
return (1);
token_print(*token);
if (insert_newline(token))
return (1);
if (ft_parse(ast, token, &parser))
continue ;
if (parser.state == ERROR)
error_syntax(token, &parser, ast);
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
if (lexer.state)
continue;
else if (parser.state == SUCCESS)
if (do_parser_routine(token, lexer, parser) > 0)
break ;
else if (parser.state == ERROR && SH_IS_INTERACTIVE(data_singleton()->opts))
{
ft_add_str_in_history(lexer.str);
return (error_syntax(token, &parser, ast));
}
}
/* btree_print(STDBUG, ast, &ft_putast); */
if (ft_exec(ast))
return (2);
if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer.str)
ft_add_str_in_history(lexer.str);
if (parser->state == SUCCESS && ft_exec(ast) < 0)
exit(1);
if (SH_IS_INTERACTIVE(data_singleton()->opts) && *lexer->str)
ft_add_str_in_history(lexer->str);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/11 16:17:38 by ariard #+# #+# */
/* Updated: 2017/03/15 19:59:19 by ariard ### ########.fr */
/* Updated: 2017/03/16 14:32:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */