This commit is contained in:
wescande 2017-03-20 15:11:32 +01:00
commit 692323a2f9
10 changed files with 33 additions and 32 deletions

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */ /* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */ /* Created: 2016/10/15 13:27:14 by alao #+# #+# */
/* Updated: 2017/03/19 15:34:38 by gwojda ### ########.fr */ /* Updated: 2017/03/20 14:41:04 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,8 @@ static int c_chevron(t_comp *c)
pos = c->ircmd; pos = c->ircmd;
if (pos >= ft_strlen(c->rcmd)) if (pos >= ft_strlen(c->rcmd))
pos = ft_strlen(c->rcmd) - (ft_strlen(data_singleton()->line.input) - pos); pos = ft_strlen(c->rcmd) - (ft_strlen(data_singleton()->line.input)
- pos);
while (pos) while (pos)
{ {
if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>') if (c->rcmd[pos] == '<' || c->rcmd[pos] == '>')

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* builtin_fg.c :+: :+: :+: */ /* builtin_fg.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */ /* Created: 2017/01/08 14:30:07 by jhalford #+# #+# */
/* Updated: 2017/03/20 12:12:16 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:42:22 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -27,7 +27,7 @@ int builtin_fg(const char *path, char *const av[], char *const envp[])
return (-1); return (-1);
} }
jobc = &data_singleton()->jobc; jobc = &data_singleton()->jobc;
job_getrank(&rank); job_getrank(&rank);
if (av[1] ? (id = *av[1]) : 0) if (av[1] ? (id = *av[1]) : 0)
{ {
if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id))) if ((jlist = ft_lst_find(jobc->first_job, &id, job_cmp_id)))

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/20 14:16:03 by gwojda ### ########.fr */ /* Updated: 2017/03/20 14:49:03 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */ /* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */
/* Updated: 2017/03/18 15:43:07 by gwojda ### ########.fr */ /* Updated: 2017/03/20 14:44:51 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -17,7 +17,6 @@ void data_exit(void)
t_data *data; t_data *data;
data = data_singleton(); data = data_singleton();
/* ft_strdel(&data->line.input); */
ft_sstrfree(data->env); ft_sstrfree(data->env);
ft_sstrfree(data->local_var); ft_sstrfree(data->local_var);
ft_sstrfree(data->argv); ft_sstrfree(data->argv);

View file

@ -6,13 +6,13 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */ /* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */
/* Updated: 2017/03/16 15:12:53 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:45:01 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
t_data *data_singleton() t_data *data_singleton(void)
{ {
static t_data *data = NULL; static t_data *data = NULL;

View file

@ -3,15 +3,16 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* main.c :+: :+: :+: */ /* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Updated: 2017/03/17 10:51:23 by gwojda ### ########.fr */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/20 14:46:44 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
static int do_readline_routine(char **stream) static int do_readline_routine(char **stream)
{ {
int ret; int ret;
int has_prompt; int has_prompt;
@ -55,7 +56,7 @@ static int handle_instruction(t_list **token, t_btree **ast)
return (0); return (0);
} }
int main(int ac, char **av) int main(int ac, char **av)
{ {
int ret; int ret;
t_data *data; t_data *data;
@ -67,7 +68,7 @@ int main(int ac, char **av)
DG("{inv}{bol}{gre}start of shell{eoc}"); DG("{inv}{bol}{gre}start of shell{eoc}");
if (shell_init(ac, av) != 0) if (shell_init(ac, av) != 0)
return (1); return (1);
DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF"); DG("JOBC is %s", SH_HAS_JOBC(data_singleton()->opts) ? "ON" : "OFF");
token = NULL; token = NULL;
ast = NULL; ast = NULL;
data = data_singleton(); data = data_singleton();

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/20 11:30:42 by jhalford ### ########.fr */ /* Updated: 2017/03/20 14:54:28 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,7 @@ static t_cliopts g_opts[] =
{0, 0, 0, 0, 0}, {0, 0, 0, 0, 0},
}; };
int get_c_arg(char ***av, t_data *data) int get_c_arg(char ***av, t_data *data)
{ {
if (!av || !*av) if (!av || !*av)
return (1); return (1);
@ -28,7 +28,7 @@ int get_c_arg(char ***av, t_data *data)
return (0); return (0);
} }
static int get_input_fd(t_data *data) static int get_input_fd(t_data *data)
{ {
static int fds[2] = {-1, STDIN}; static int fds[2] = {-1, STDIN};
char *file; char *file;
@ -47,7 +47,8 @@ static int get_input_fd(t_data *data)
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", ft_printf("{red}%s: %s: No such file or directory\n{eoc}",
data->argv[0], file); data->argv[0], file);
else if (S_ISDIR(buf.st_mode)) else if (S_ISDIR(buf.st_mode))
ft_printf("{red}%s: %s: is a directory\n{eoc}", data->argv[0], file); ft_printf("{red}%s: %s: is a directory\n{eoc}", data->argv[0],
file);
else if ((fds[PIPE_READ] = open(file, O_RDONLY | O_CLOEXEC)) < 0) else if ((fds[PIPE_READ] = open(file, O_RDONLY | O_CLOEXEC)) < 0)
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", ft_printf("{red}%s: %s: No such file or directory\n{eoc}",
data->argv[0], file); data->argv[0], file);
@ -115,7 +116,7 @@ int shell_init(int ac, char **av)
if ((data->fd = get_input_fd(data)) < 0) if ((data->fd = get_input_fd(data)) < 0)
return (-1); return (-1);
DG(); DG();
if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0) if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0)
return (-1); return (-1);
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */
/* Updated: 2017/03/18 15:50:28 by ariard ### ########.fr */ /* Updated: 2017/03/20 14:57:34 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -41,16 +41,16 @@ int add_subshell_cmd(t_btree **ast, t_list **lst)
token = (*lst)->content; token = (*lst)->content;
node = (*ast)->item; node = (*ast)->item;
if ((token->type == SUBSHELL && node->type == SUBSHELL) if ((token->type == SUBSHELL && node->type == SUBSHELL)
|| (token->type == TK_LBRACE && node->type == TK_LBRACE)) || (token->type == TK_LBRACE && node->type == TK_LBRACE))
node->nest++; node->nest++;
if (((token->type == TK_PAREN_CLOSE && node->type == SUBSHELL) if (((token->type == TK_PAREN_CLOSE && node->type == SUBSHELL)
|| (token->type == TK_RBRACE && node->type == TK_LBRACE)) && node->nest > 0) || (token->type == TK_RBRACE && node->type == TK_LBRACE)) && node->nest > 0)
node->nest--; node->nest--;
else if (token->type == TK_PAREN_CLOSE && node->type == SUBSHELL else if (token->type == TK_PAREN_CLOSE && node->type == SUBSHELL
&& node->nest == 0) && node->nest == 0)
return ((node->full = 1)); return ((node->full = 1));
else if (token->type == TK_RBRACE && node->type == TK_LBRACE else if (token->type == TK_RBRACE && node->type == TK_LBRACE
&& node->nest == 0) && node->nest == 0)
return ((node->full = 1)); return ((node->full = 1));
return (add_cmd(&(*ast)->right, lst)); return (add_cmd(&(*ast)->right, lst));
} }

View file

@ -6,13 +6,13 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
/* Updated: 2017/03/15 16:33:57 by ariard ### ########.fr */ /* Updated: 2017/03/20 14:59:23 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
char *read_state(t_sym current) char *read_state(t_sym current)
{ {
if (current == FNAME) if (current == FNAME)
return ("FNAME"); return ("FNAME");
@ -131,7 +131,7 @@ char *read_state(t_sym current)
if (current == TK_DONE) if (current == TK_DONE)
return ("TK_DONE"); return ("TK_DONE");
if (current == AND_OR_MINOR) if (current == AND_OR_MINOR)
return("AND_OR_MINOR"); return ("AND_OR_MINOR");
if (current == AND_OR_MAJOR) if (current == AND_OR_MAJOR)
return ("AND_OR_MAJOR"); return ("AND_OR_MAJOR");
if (current == TK_COMMAND) if (current == TK_COMMAND)
@ -227,7 +227,6 @@ int ft_read_stack(t_sym *stack)
return (0); return (0);
} }
int ft_show_heredoc_data(t_astnode *node) int ft_show_heredoc_data(t_astnode *node)
{ {
t_redir *redir; t_redir *redir;

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/18 17:13:31 by ariard #+# #+# */ /* Created: 2017/03/18 17:13:31 by ariard #+# #+# */
/* Updated: 2017/03/18 17:15:11 by ariard ### ########.fr */ /* Updated: 2017/03/20 14:57:58 by gwojda ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,4 +19,4 @@ void sym_free(void *data, size_t size)
(void)size; (void)size;
sym = data; sym = data;
free(sym); free(sym);
} }