Merge branch 'master' of https://github.com/jzck/42sh
This commit is contained in:
commit
9ccb83ac17
5 changed files with 40 additions and 20 deletions
|
|
@ -6,13 +6,13 @@
|
||||||
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
|
/* Created: 2017/02/15 12:03:30 by alao #+# #+# */
|
||||||
/* Updated: 2017/03/28 08:14:15 by alao ### ########.fr */
|
/* Updated: 2017/03/28 16:09:08 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "completion.h"
|
#include "completion.h"
|
||||||
|
|
||||||
static char *c_current_words(void)
|
static char *c_current_words(void)
|
||||||
{
|
{
|
||||||
size_t pos;
|
size_t pos;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/27 16:46:26 by jhalford ### ########.fr */
|
/* Updated: 2017/03/28 15:36:13 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -16,12 +16,12 @@ int process_fork(t_process *p)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
if (!p)
|
|
||||||
return (0);
|
|
||||||
if ((pid = fork()) == -1)
|
if ((pid = fork()) == -1)
|
||||||
exit(SH_ERR("fork(): %s", strerror(errno)));
|
exit(SH_ERR("fork(): %s", strerror(errno)));
|
||||||
else if (pid != 0)
|
else if (pid != 0)
|
||||||
return (pid);
|
return (pid);
|
||||||
|
if (!p)
|
||||||
|
return (0);
|
||||||
exec_destroy(&data_singleton()->exec);
|
exec_destroy(&data_singleton()->exec);
|
||||||
jobc_destroy(&data_singleton()->jobc);
|
jobc_destroy(&data_singleton()->jobc);
|
||||||
if ((pid = 1) && process_redirect(p) == 0)
|
if ((pid = 1) && process_redirect(p) == 0)
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,18 @@
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
|
static char *h_free_one(t_list **head, t_list *list, t_list *ref)
|
||||||
|
{
|
||||||
|
if (!((*head)->next))
|
||||||
|
ft_lstdelone(head, &ft_hash_free);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ref->next = list->next;
|
||||||
|
ft_lstdelone(&list, &ft_hash_free);
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
char *ft_is_hash(char *cmd)
|
char *ft_is_hash(char *cmd)
|
||||||
{
|
{
|
||||||
t_list *list;
|
t_list *list;
|
||||||
|
|
@ -25,12 +37,9 @@ char *ft_is_hash(char *cmd)
|
||||||
{
|
{
|
||||||
if (!ft_strcmp(((t_hash *)list->content)->key, cmd))
|
if (!ft_strcmp(((t_hash *)list->content)->key, cmd))
|
||||||
{
|
{
|
||||||
if (access(((t_hash *)list->content)->path, X_OK))
|
if (access(((t_hash *)list->content)->path,
|
||||||
{
|
X_OK | F_OK) < 0)
|
||||||
ref->next = list->next;
|
return (h_free_one(&g_hash[id], list, ref));
|
||||||
ft_lstdelone(&list, &ft_hash_free);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
return (ft_strdup(((t_hash *)list->content)->path));
|
return (ft_strdup(((t_hash *)list->content)->path));
|
||||||
}
|
}
|
||||||
ref = list;
|
ref = list;
|
||||||
|
|
|
||||||
|
|
@ -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/27 18:10:21 by gwojda ### ########.fr */
|
/* Updated: 2017/03/28 14:57:13 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,6 +20,7 @@ int readline(int has_prompt, char **input)
|
||||||
data_singleton()->line.prompt_size = 1;
|
data_singleton()->line.prompt_size = 1;
|
||||||
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
if (!SH_IS_INTERACTIVE(data_singleton()->opts))
|
||||||
{
|
{
|
||||||
|
ft_strdel(input);
|
||||||
if ((ret = get_next_line(data_singleton()->fd, input)) >= 0)
|
if ((ret = get_next_line(data_singleton()->fd, input)) >= 0)
|
||||||
return (!ret);
|
return (!ret);
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
|
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/27 20:57:57 by ariard ### ########.fr */
|
/* Updated: 2017/03/28 16:00:36 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -32,6 +32,22 @@ static int do_readline_routine(char **stream)
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int exec_instruction(t_btree **ast, char **stream)
|
||||||
|
{
|
||||||
|
t_data *data;
|
||||||
|
|
||||||
|
data = data_singleton();
|
||||||
|
if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str)
|
||||||
|
ft_add_str_in_history(data->lexer.str);
|
||||||
|
else
|
||||||
|
ft_strdel(stream);
|
||||||
|
if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
|
||||||
|
exit(1);
|
||||||
|
else if (data->parser.state != SUCCESS)
|
||||||
|
set_exitstatus(1, 1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
static int handle_instruction(t_list **token, t_btree **ast)
|
static int handle_instruction(t_list **token, t_btree **ast)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -52,13 +68,7 @@ static int handle_instruction(t_list **token, t_btree **ast)
|
||||||
else if (ret > 0)
|
else if (ret > 0)
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
if (SH_IS_INTERACTIVE(data->opts) && data->lexer.str)
|
return (exec_instruction(ast, &stream));
|
||||||
ft_add_str_in_history(data->lexer.str);
|
|
||||||
if (data->parser.state == SUCCESS && ft_exec(ast) < 0)
|
|
||||||
exit(1);
|
|
||||||
else if (data->parser.state != SUCCESS)
|
|
||||||
set_exitstatus(1, 1);
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av, char **env)
|
int main(int ac, char **av, char **env)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue