math as a builtin
This commit is contained in:
commit
36e0522fb3
24 changed files with 202 additions and 266 deletions
|
|
@ -270,8 +270,6 @@ main/data_singleton.c\
|
||||||
main/ft_putast.c\
|
main/ft_putast.c\
|
||||||
main/instruction_free.c\
|
main/instruction_free.c\
|
||||||
main/main.c\
|
main/main.c\
|
||||||
main/shell_get_avdata.c\
|
|
||||||
main/shell_get_opts.c\
|
|
||||||
main/shell_init.c\
|
main/shell_init.c\
|
||||||
parser/add_bang.c\
|
parser/add_bang.c\
|
||||||
parser/add_case.c\
|
parser/add_case.c\
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
|
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 20:39:49 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 19:57:25 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 23:02:23 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 21:17:31 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/12 01:01:44 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 21:34:13 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -34,10 +34,10 @@
|
||||||
|
|
||||||
struct s_data
|
struct s_data
|
||||||
{
|
{
|
||||||
|
t_flag opts;
|
||||||
char **env;
|
char **env;
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
t_flag opts;
|
|
||||||
t_line line;
|
t_line line;
|
||||||
t_comp *comp;
|
t_comp *comp;
|
||||||
t_exec exec;
|
t_exec exec;
|
||||||
|
|
@ -47,11 +47,9 @@ struct s_data
|
||||||
t_list *lst_func;
|
t_list *lst_func;
|
||||||
};
|
};
|
||||||
|
|
||||||
void shell_get_opts(int ac, char **av);
|
int shell_init(int ac, char **av);
|
||||||
char *shell_get_avdata();
|
|
||||||
void shell_init(int ac, char **av);
|
|
||||||
void shell_exit(void);
|
void shell_exit(void);
|
||||||
int data_init(void);
|
int data_init(int ac, char **av);
|
||||||
void data_exit(void);
|
void data_exit(void);
|
||||||
|
|
||||||
int instruction_free(t_list **token, t_parser *parser,
|
int instruction_free(t_list **token, t_parser *parser,
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 22:04:24 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 22:53:17 by ariard ### ########.fr */
|
||||||
/* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -38,9 +37,10 @@ typedef struct s_comp t_comp;
|
||||||
typedef struct s_exec t_exec;
|
typedef struct s_exec t_exec;
|
||||||
typedef struct s_jobc t_jobc;
|
typedef struct s_jobc t_jobc;
|
||||||
typedef enum e_mode t_mode;
|
typedef enum e_mode t_mode;
|
||||||
|
typedef struct s_data_template t_btexport;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Execution types
|
** Lexer types
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct s_lexer t_lexer;
|
typedef struct s_lexer t_lexer;
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 9382dc10fdb91892ab26604a5776e5301ab88b71
|
Subproject commit 938a355bac5f6d4c7941968d3ef0da0d984a9329
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
|
/* Created: 2017/01/21 18:00:03 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/07 11:27:49 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 18:11:36 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,65 @@
|
||||||
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */
|
/* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */
|
||||||
/* Updated: 2017/03/13 19:00:58 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 21:39:12 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
int builtin_export(const char *path, char *const av[], char *const envp[])
|
static t_cliopts export_opts[] =
|
||||||
{
|
{
|
||||||
|
{'p', NULL, BT_EXPORT_LP, 0, NULL},
|
||||||
|
{0, NULL, 0, 0, NULL},
|
||||||
|
};
|
||||||
|
|
||||||
|
int bt_export_print(void)
|
||||||
|
{
|
||||||
|
char **env;
|
||||||
char *equal;
|
char *equal;
|
||||||
|
|
||||||
if ((equal = ft_strchr(av[1], '=')))
|
env = data_singleton()->env;
|
||||||
|
while (*env)
|
||||||
{
|
{
|
||||||
*equal = 0;
|
if ((equal = ft_strchr(*env, '=')))
|
||||||
builtin_setenv(path, (char*[]){"setenv", av[1], equal + 1}, envp);
|
ft_printf("export %s\n", *env);
|
||||||
|
else
|
||||||
|
ft_printf("export %s\n", *env);
|
||||||
|
env++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int builtin_export(
|
||||||
|
const char *path, char *const av[], char *const envp[])
|
||||||
|
{
|
||||||
|
char *equal;
|
||||||
|
t_btexport data;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
(void)envp;
|
||||||
|
(void)path;
|
||||||
|
data.flag = 0;
|
||||||
|
if (cliopts_get((char**)av, export_opts, &data))
|
||||||
|
ft_perror();
|
||||||
|
if (data.flag & BT_EXPORT_LP)
|
||||||
|
return (bt_export_print());
|
||||||
|
av = cliopts_getdata((char**)av);
|
||||||
|
while (*av)
|
||||||
|
{
|
||||||
|
if ((equal = ft_strchr(*av, '=')))
|
||||||
|
{
|
||||||
|
*equal = 0;
|
||||||
|
builtin_setenv("internal", (char*[]){"global", *av, equal + 1}, NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
equal = ft_getenv(data_singleton()->local_var, *av);
|
||||||
|
builtin_setenv("internal", (char*[]){"global", *av, equal}, NULL);
|
||||||
|
}
|
||||||
|
builtin_unsetenv("internal", (char*[]){"local", *av}, NULL);
|
||||||
|
av++;
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
/* Created: 2017/01/20 15:01:45 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/06 14:02:17 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 18:08:35 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 22:44:18 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 22:53:59 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -23,10 +23,7 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[])
|
||||||
i = 0;
|
i = 0;
|
||||||
env = ft_strcmp(av[0], "local") == 0 ?
|
env = ft_strcmp(av[0], "local") == 0 ?
|
||||||
&data_singleton()->local_var : &data_singleton()->env;
|
&data_singleton()->local_var : &data_singleton()->env;
|
||||||
if (ft_strcmp(av[0], "setenv") == 0
|
av++;
|
||||||
|| ft_strcmp(av[0], "export") == 0
|
|
||||||
|| ft_strcmp(av[0], "local") == 0)
|
|
||||||
av++;
|
|
||||||
if (!av[0])
|
if (!av[0])
|
||||||
{
|
{
|
||||||
ft_sstrprint(*env, '\n');
|
ft_sstrprint(*env, '\n');
|
||||||
|
|
@ -34,7 +31,6 @@ int builtin_setenv(const char *path, char *const av[], char *const envp[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DG("str3join(%s,%s,%s)", av[0], "=", av[1]);
|
|
||||||
str = ft_str3join(av[0], "=", av[1]);
|
str = ft_str3join(av[0], "=", av[1]);
|
||||||
while ((*env) && (*env)[i])
|
while ((*env) && (*env)[i])
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */
|
/* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */
|
||||||
/* Updated: 2016/12/03 11:55:53 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 21:13:35 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -20,7 +20,8 @@ int builtin_unsetenv(const char *path, char *const av[], char *const envp[])
|
||||||
|
|
||||||
(void)envp;
|
(void)envp;
|
||||||
(void)path;
|
(void)path;
|
||||||
env = &data_singleton()->env;
|
env = ft_strcmp(av[0], "local") == 0 ?
|
||||||
|
&data_singleton()->local_var : &data_singleton()->env;
|
||||||
i = 1;
|
i = 1;
|
||||||
while (av[i])
|
while (av[i])
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
|
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/14 21:49:17 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 22:55:12 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
|
/* Created: 2017/03/07 11:12:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/14 19:56:38 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 22:55:04 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -30,6 +30,6 @@ int exec_var(t_btree **ast)
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
av = token_to_argv(node->data.cmd.token, 1);
|
av = token_to_argv(node->data.cmd.token, 1);
|
||||||
set_var(av[0], &var, &value);
|
set_var(av[0], &var, &value);
|
||||||
builtin_setenv("setenv", (char*[]){"local", var, value, 0}, data_singleton()->local_var);
|
builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 23:15:06 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 21:48:36 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -40,7 +40,7 @@ int plaunch_file(t_process *p)
|
||||||
}
|
}
|
||||||
else if (S_ISDIR(p->data.cmd.stat->st_mode))
|
else if (S_ISDIR(p->data.cmd.stat->st_mode))
|
||||||
{
|
{
|
||||||
ft_dprintf(2, "{red}%s: %s: Is a directory{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
ft_dprintf(2, "{red}%s: %s: is a directory{eoc}\n", SHELL_NAME, p->data.cmd.av[0]);
|
||||||
exit(126);
|
exit(126);
|
||||||
}
|
}
|
||||||
else if (access(p->data.cmd.path, X_OK) == -1)
|
else if (access(p->data.cmd.path, X_OK) == -1)
|
||||||
|
|
|
||||||
|
|
@ -3,93 +3,53 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* command_getoutput.c :+: :+: :+: */
|
/* command_getoutput.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
|
/* Created: 2017/03/14 19:44:25 by wescande #+# #+# */
|
||||||
/* Updated: 2017/03/13 23:32:52 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 19:44:37 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
#define BUF_SIZE 1024
|
#define BUF_SIZE 1024
|
||||||
|
|
||||||
/*static char *manage_output(int *fds)
|
static char *manage_output(int *fds)
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
char buf[BUF_SIZE + 1];
|
|
||||||
char *output;
|
|
||||||
|
|
||||||
output = NULL;
|
|
||||||
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0)
|
|
||||||
{
|
|
||||||
buf[ret] = 0;
|
|
||||||
ft_strappend(&output, buf);
|
|
||||||
}
|
|
||||||
close(fds[PIPE_READ]);
|
|
||||||
return (output);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
static t_btree *gen_t_btree(const char *command)
|
|
||||||
{
|
{
|
||||||
t_btree *ast;
|
|
||||||
t_astnode item;
|
|
||||||
int len;
|
|
||||||
unsigned char *esc;
|
|
||||||
|
|
||||||
ft_bzero(&item, sizeof(t_astnode));
|
|
||||||
item.type = SUBSHELL;
|
|
||||||
ast = btree_create_node(&item, sizeof(t_astnode));
|
|
||||||
ft_bzero(&item, sizeof(t_astnode));
|
|
||||||
item.type = CMD;
|
|
||||||
len = ft_strlen(command);
|
|
||||||
esc = ft_memalloc((len >> 3) + 1);
|
|
||||||
ft_ld_pushfront(&item.data.cmd.token, gen_tab(command, esc, esc, 1));
|
|
||||||
ast->right = btree_create_node(&item, sizeof(t_astnode));
|
|
||||||
return (ast);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *command_getoutput(char *command)
|
|
||||||
{
|
|
||||||
t_btree *ast;
|
|
||||||
char *output;
|
|
||||||
char buf[BUF_SIZE + 1];
|
|
||||||
t_exec *exec;
|
|
||||||
t_process p;
|
|
||||||
int ret;
|
int ret;
|
||||||
int pid;
|
char buf[BUF_SIZE + 1];
|
||||||
|
char *output;
|
||||||
|
|
||||||
return (NULL);
|
|
||||||
output = NULL;
|
output = NULL;
|
||||||
exec = &data_singleton()->exec;
|
close(fds[PIPE_WRITE]);
|
||||||
DG("%p exec ?", exec);
|
while ((ret = read(fds[PIPE_READ], buf, BUF_SIZE)) > 0)
|
||||||
DG("\033[38;5;46mbefore");
|
|
||||||
ast = gen_t_btree(command);
|
|
||||||
DG();
|
|
||||||
if (process_set(&p, ast))
|
|
||||||
return (NULL);
|
|
||||||
DG();
|
|
||||||
if (!(pid = plaunch_subshell(&p)))
|
|
||||||
return (NULL);
|
|
||||||
waitpid(pid, &ret, WUNTRACED);
|
|
||||||
DG();
|
|
||||||
// exec_leaf(&ast);
|
|
||||||
/*
|
|
||||||
DG();
|
|
||||||
set_process(&p, ast);
|
|
||||||
DG();
|
|
||||||
launch_process(&p);
|
|
||||||
DG();
|
|
||||||
close(p.fdout);*/
|
|
||||||
DG();
|
|
||||||
while ((ret = read(exec->fdin, buf, BUF_SIZE)) > 0)
|
|
||||||
{
|
{
|
||||||
buf[ret] = 0;
|
buf[ret] = 0;
|
||||||
ft_strappend(&output, buf);
|
ft_strappend(&output, buf);
|
||||||
}
|
}
|
||||||
DG();
|
close(fds[PIPE_READ]);
|
||||||
close(exec->fdin);
|
return (output);
|
||||||
DG("done with %s\033[0m", output);
|
}
|
||||||
|
|
||||||
|
char *command_getoutput(char *command)
|
||||||
|
{
|
||||||
|
char *output;
|
||||||
|
int ret;
|
||||||
|
int pid;
|
||||||
|
int fds[2];
|
||||||
|
|
||||||
|
if (!command)
|
||||||
|
return (NULL);
|
||||||
|
pipe(fds);
|
||||||
|
if (!(pid = fork()))
|
||||||
|
{
|
||||||
|
close(fds[PIPE_READ]);
|
||||||
|
dup2_close(fds[PIPE_WRITE], STDOUT);
|
||||||
|
execle(data_singleton()->argv[0],data_singleton()->argv[0],
|
||||||
|
"-c", command, NULL,
|
||||||
|
data_singleton()->env);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
waitpid(pid, &ret, WUNTRACED);
|
||||||
|
output = manage_output(fds);
|
||||||
return (output);
|
return (output);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
|
/* Created: 2017/02/17 17:47:53 by wescande #+# #+# */
|
||||||
/* Updated: 2017/02/24 22:04:59 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 20:07:47 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ static char *get_output(char *command)
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (!(output = command_getoutput(command)))
|
if (!(output = command_getoutput(command)))
|
||||||
return (ft_strnew(0));
|
return (NULL);//ft_strnew(0));
|
||||||
len = ft_strlen(output);
|
len = ft_strlen(output);
|
||||||
while (output[--len] == '\n')
|
while (output[--len] == '\n')
|
||||||
output[len] = '\0';
|
output[len] = '\0';
|
||||||
|
|
@ -98,10 +98,8 @@ static int search_bquote(t_bquote *me)
|
||||||
me->mid = ft_strsub(sta, 1, me->str - sta - 1);
|
me->mid = ft_strsub(sta, 1, me->str - sta - 1);
|
||||||
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
|
me->s1 = ft_strsub(CH(*me->wk)[0], 0, sta - CH(*me->wk)[0]);
|
||||||
me->s2 = ft_strdup(me->str + 1);
|
me->s2 = ft_strdup(me->str + 1);
|
||||||
content = get_output(me->mid);
|
if ((content = get_output(me->mid)))
|
||||||
DG();
|
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
|
||||||
init_expand(me, content, is_char_esc(me->esc, CH(*me->wk)[0], sta));
|
|
||||||
DG();
|
|
||||||
ft_strdel(&me->mid);
|
ft_strdel(&me->mid);
|
||||||
ft_strdel(&me->s1);
|
ft_strdel(&me->s1);
|
||||||
ft_strdel(&me->s2);
|
ft_strdel(&me->s2);
|
||||||
|
|
@ -113,6 +111,13 @@ static int search_bquote(t_bquote *me)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void delete(t_ld **tmp, t_ld **src)
|
||||||
|
{
|
||||||
|
if (*tmp == *src)
|
||||||
|
ft_ld_del(src, &ft_tabdel);
|
||||||
|
else
|
||||||
|
ft_ld_del(tmp, &ft_tabdel);
|
||||||
|
}
|
||||||
void expand_bquote(t_glob *gl)
|
void expand_bquote(t_glob *gl)
|
||||||
{
|
{
|
||||||
t_ld *tmp;
|
t_ld *tmp;
|
||||||
|
|
@ -133,8 +138,9 @@ void expand_bquote(t_glob *gl)
|
||||||
me.str = CH(gl->m_pat)[0];
|
me.str = CH(gl->m_pat)[0];
|
||||||
if ((tmp = gl->m_pat) &&
|
if ((tmp = gl->m_pat) &&
|
||||||
(do_it = search_bquote(&me)) == 1)
|
(do_it = search_bquote(&me)) == 1)
|
||||||
ft_ld_del(&tmp, &ft_tabdel);
|
delete(&tmp, &gl->m_pat);
|
||||||
if (!gl->m_pat->next)
|
// ft_ld_del(&tmp, &ft_tabdel);
|
||||||
|
if (!gl->m_pat || !gl->m_pat->next)
|
||||||
break ;
|
break ;
|
||||||
gl->m_pat = gl->m_pat->next;
|
gl->m_pat = gl->m_pat->next;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
|
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:29:29 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 20:21:46 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -42,7 +42,8 @@ static void process_format_com_long(t_list **plist)
|
||||||
t_process *p;
|
t_process *p;
|
||||||
|
|
||||||
p = (*plist)->content;
|
p = (*plist)->content;
|
||||||
(p->map.print)(p);
|
if (p->map.print)
|
||||||
|
(p->map.print)(p);
|
||||||
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
|
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
|
||||||
if ((*plist)->next)
|
if ((*plist)->next)
|
||||||
ft_putstr(" |");
|
ft_putstr(" |");
|
||||||
|
|
@ -64,7 +65,8 @@ static void process_format_com_short(t_list **plist, t_flag state)
|
||||||
p->attrs &= ~PROCESS_STATE_MASK;
|
p->attrs &= ~PROCESS_STATE_MASK;
|
||||||
p->attrs &= ~PROCESS_RUNNING;
|
p->attrs &= ~PROCESS_RUNNING;
|
||||||
}
|
}
|
||||||
(p->map.print)(p);
|
if (p->map.print)
|
||||||
|
(p->map.print)(p);
|
||||||
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
|
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
|
||||||
if ((*plist)->next)
|
if ((*plist)->next)
|
||||||
ft_putstr(" | ");
|
ft_putstr(" | ");
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 22:19:53 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 20:19:22 by wescande ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -36,7 +36,8 @@ void process_free(void *content, size_t content_size)
|
||||||
/* return ; */
|
/* return ; */
|
||||||
/* if (g_freemap[p->type].f) */
|
/* if (g_freemap[p->type].f) */
|
||||||
/* (g_freemap[p->type].f)(p); */
|
/* (g_freemap[p->type].f)(p); */
|
||||||
(p->map.free)(p);
|
if (p->map.free)
|
||||||
|
(p->map.free)(p);
|
||||||
ft_lstdel(&p->redirs, redir_free);
|
ft_lstdel(&p->redirs, redir_free);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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/13 14:43:28 by jhalford ### ########.fr */
|
/* Updated: 2017/03/14 21:34:46 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/13 23:48:04 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 21:39:13 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -14,12 +14,14 @@
|
||||||
|
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
|
|
||||||
int data_init(void)
|
int data_init(int ac, char **av)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_data *data;
|
||||||
char *term_name;
|
char *term_name;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
|
data->argc = ac;
|
||||||
|
data->argv = ft_sstrdup(av);
|
||||||
data->env = ft_sstrdup(environ);
|
data->env = ft_sstrdup(environ);
|
||||||
data->local_var = NULL;
|
data->local_var = NULL;
|
||||||
set_exitstatus(0, 1);
|
set_exitstatus(0, 1);
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/14 22:09:29 by ariard ### ########.fr */
|
/* Updated: 2017/03/14 22:51:29 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -31,13 +31,11 @@ int handle_instruction(int fd)
|
||||||
if ((ret = readline(fd, get_lexer_stack(lexer) ||
|
if ((ret = readline(fd, get_lexer_stack(lexer) ||
|
||||||
parser.state == UNDEFINED || lexer.state == HEREDOC, &str)))
|
parser.state == UNDEFINED || lexer.state == HEREDOC, &str)))
|
||||||
{
|
{
|
||||||
DG("readline trap");
|
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
return (-1);
|
return (-1);
|
||||||
return (parser.state == UNDEFINED ? error_eof(&token,
|
return (parser.state == UNDEFINED ? error_eof(&token,
|
||||||
&parser, &ast) : 1);
|
&parser, &ast) : 1);
|
||||||
}
|
}
|
||||||
DG("INPUT STRING IS [%s]", str);
|
|
||||||
if (lexer.state == HEREDOC)
|
if (lexer.state == HEREDOC)
|
||||||
{
|
{
|
||||||
ft_strappend(&lexer.str, (char[]){'\n', 0});
|
ft_strappend(&lexer.str, (char[]){'\n', 0});
|
||||||
|
|
@ -62,7 +60,6 @@ int handle_instruction(int fd)
|
||||||
if (parser.state == ERROR)
|
if (parser.state == ERROR)
|
||||||
error_syntax(&token, &parser, &ast);
|
error_syntax(&token, &parser, &ast);
|
||||||
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
|
lexer.state = data_singleton()->heredoc_queue ? HEREDOC : 0;
|
||||||
/* DG("lexer.state=%i", lexer.state); */
|
|
||||||
if (lexer.state)
|
if (lexer.state)
|
||||||
continue;
|
continue;
|
||||||
else if (parser.state == SUCCESS)
|
else if (parser.state == SUCCESS)
|
||||||
|
|
@ -84,12 +81,13 @@ int handle_instruction(int fd)
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_input_fd()
|
int get_input_fd(char **av)
|
||||||
{
|
{
|
||||||
t_data *data;
|
t_data *data;
|
||||||
char *file;
|
char *file;
|
||||||
int fds[2];
|
int fds[2];
|
||||||
int fd;
|
int fd;
|
||||||
|
struct stat buf;
|
||||||
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
if (SH_IS_INTERACTIVE(data->opts))
|
if (SH_IS_INTERACTIVE(data->opts))
|
||||||
|
|
@ -98,38 +96,39 @@ int get_input_fd()
|
||||||
{
|
{
|
||||||
pipe(fds);
|
pipe(fds);
|
||||||
fd = fds[PIPE_READ];
|
fd = fds[PIPE_READ];
|
||||||
file = shell_get_avdata();
|
file = *cliopts_getdata(av);
|
||||||
write(fds[PIPE_WRITE], file, ft_strlen(file));
|
write(fds[PIPE_WRITE], file, ft_strlen(file));
|
||||||
close(fds[PIPE_WRITE]);
|
close(fds[PIPE_WRITE]);
|
||||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||||
return (fd);
|
return (fd);
|
||||||
}
|
}
|
||||||
else if ((file = shell_get_avdata()))
|
else if ((file = *cliopts_getdata(av)))
|
||||||
{
|
{
|
||||||
if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0)
|
stat(file, &buf);
|
||||||
return (-1);
|
fd = -1;
|
||||||
|
if (S_ISDIR(buf.st_mode))
|
||||||
|
ft_printf("{red}%s: %s: is a directory\n{eoc}", g_argv[0], file);
|
||||||
|
else if ((fd = open(file, O_RDONLY | O_CLOEXEC)) < 0)
|
||||||
|
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", g_argv[0], file);
|
||||||
return (fd);
|
return (fd);
|
||||||
}
|
}
|
||||||
else
|
return (STDIN);
|
||||||
return (STDIN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int ac, char **av)
|
int main(int ac, char **av)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
g_argv = av;
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
DG("{inv}{bol}{gre}start of shell{eoc}");
|
DG("{inv}{bol}{gre}start of shell{eoc}");
|
||||||
shell_init(ac, av);
|
if (shell_init(ac, av))
|
||||||
if ((fd = get_input_fd()) < 0)
|
return (1);
|
||||||
{
|
if ((fd = get_input_fd(av)) < 0)
|
||||||
ft_printf("{red}%s: %s: No such file or directory\n{eoc}", SHELL_NAME, shell_get_avdata());
|
|
||||||
return (1);
|
return (1);
|
||||||
}
|
|
||||||
DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd);
|
DG("JOBC is %s, fd=[%i]", SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF", fd);
|
||||||
while (handle_instruction(fd) == 0)
|
while (handle_instruction(fd) == 0)
|
||||||
;
|
;
|
||||||
DG("gonna exit");
|
|
||||||
builtin_exit(NULL, NULL, NULL);
|
builtin_exit(NULL, NULL, NULL);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* shell_get_avdata.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2017/01/11 17:14:52 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/03/03 17:33:33 by wescande ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
char *shell_get_avdata()
|
|
||||||
{
|
|
||||||
t_data *data;
|
|
||||||
char **av;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
data = data_singleton();
|
|
||||||
av = data->argv;
|
|
||||||
i = 1;
|
|
||||||
while (av[i] && av[i][0] == '-')
|
|
||||||
{
|
|
||||||
if (ft_strcmp(av[i], "--") == 0)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return(av[i]);
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* shell_get_opts.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2017/01/11 14:04:48 by jhalford #+# #+# */
|
|
||||||
/* Updated: 2017/03/06 16:52:34 by jhalford ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "minishell.h"
|
|
||||||
|
|
||||||
static void shell_parse_long_opt(char *str)
|
|
||||||
{
|
|
||||||
if (ft_strcmp("no-jobcontrol", str) == 0)
|
|
||||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void shell_parse_short_opt(char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
if (*str == 'c')
|
|
||||||
{
|
|
||||||
data_singleton()->opts |= SH_OPTS_LC;
|
|
||||||
data_singleton()->opts &= ~SH_OPTS_JOBC;
|
|
||||||
data_singleton()->opts &= ~SH_INTERACTIVE;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void shell_get_opts(int ac, char **av)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
if (isatty(STDIN) && !av[1])
|
|
||||||
{
|
|
||||||
data_singleton()->opts |= SH_INTERACTIVE;
|
|
||||||
data_singleton()->opts |= SH_OPTS_JOBC;
|
|
||||||
}
|
|
||||||
while (i < ac && av[i][0] == '-')
|
|
||||||
{
|
|
||||||
if (ft_strcmp(av[i], "--") == 0)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
if (av[i][1] == '-')
|
|
||||||
shell_parse_long_opt(av[i] + 2);
|
|
||||||
else
|
|
||||||
shell_parse_short_opt(av[i] + 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,43 +6,66 @@
|
||||||
/* 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/14 11:09:31 by gwojda ### ########.fr */
|
/* Updated: 2017/03/14 21:50:11 by jhalford ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "minishell.h"
|
#include "minishell.h"
|
||||||
|
|
||||||
void shell_init(int ac, char **av)
|
static t_cliopts shell_opts[] =
|
||||||
|
{
|
||||||
|
{'c', NULL, SH_OPTS_LC, SH_OPTS_JOBC | SH_INTERACTIVE, NULL},
|
||||||
|
{-1, "no-jobcontrol", 0, SH_OPTS_JOBC, NULL},
|
||||||
|
{0, 0, 0, 0, 0},
|
||||||
|
};
|
||||||
|
|
||||||
|
static int interactive_settings(void)
|
||||||
{
|
{
|
||||||
int *shell_pgid;
|
int *shell_pgid;
|
||||||
t_data *data;
|
t_data *data;
|
||||||
|
|
||||||
DG("check");
|
|
||||||
data_init();
|
|
||||||
data = data_singleton();
|
data = data_singleton();
|
||||||
data->argc = ac;
|
DG("interactive shell settings");
|
||||||
data->argv = ft_sstrdup(av);
|
shell_pgid = &data->jobc.shell_pgid;
|
||||||
shell_get_opts(ac, av);
|
while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp()))
|
||||||
if (SH_IS_INTERACTIVE(data->opts))
|
kill(-*shell_pgid, SIGTTIN);
|
||||||
|
signal(SIGINT, sigint_handler);
|
||||||
|
signal(SIGQUIT, SIG_IGN);
|
||||||
|
signal(SIGTSTP, sigtstp_handler);
|
||||||
|
signal(SIGTTIN, SIG_IGN);
|
||||||
|
signal(SIGTTOU, SIG_IGN);
|
||||||
|
signal(SIGCHLD, SIG_DFL);
|
||||||
|
signal(SIGWINCH, sigwinch_resize);
|
||||||
|
*shell_pgid = getpid();
|
||||||
|
if (setpgid(*shell_pgid, *shell_pgid))
|
||||||
{
|
{
|
||||||
DG("interactive shell settings");
|
ft_dprintf(2, "Couldnt put the shell in it's own process group");
|
||||||
shell_pgid = &data->jobc.shell_pgid;
|
exit (1);
|
||||||
while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp()))
|
|
||||||
kill(-*shell_pgid, SIGTTIN);
|
|
||||||
signal(SIGINT, sigint_handler);
|
|
||||||
signal(SIGQUIT, SIG_IGN);
|
|
||||||
signal(SIGTSTP, sigtstp_handler);
|
|
||||||
signal(SIGTTIN, SIG_IGN);
|
|
||||||
signal(SIGTTOU, SIG_IGN);
|
|
||||||
signal(SIGCHLD, SIG_DFL);
|
|
||||||
signal(SIGWINCH, sigwinch_resize);
|
|
||||||
*shell_pgid = getpid();
|
|
||||||
if (setpgid(*shell_pgid, *shell_pgid))
|
|
||||||
{
|
|
||||||
ft_dprintf(2, "Couldnt put the shell in it's own process group");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
tcsetpgrp(STDIN, *shell_pgid);
|
|
||||||
tcgetattr(STDIN, &data->jobc.shell_tmodes);
|
|
||||||
}
|
}
|
||||||
|
tcsetpgrp(STDIN, *shell_pgid);
|
||||||
|
tcgetattr(STDIN, &data->jobc.shell_tmodes);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int shell_init(int ac, char **av)
|
||||||
|
{
|
||||||
|
t_data *data;
|
||||||
|
|
||||||
|
data = data_singleton();
|
||||||
|
data_init(ac, av);
|
||||||
|
if (isatty(STDIN) && !*cliopts_getdata(av))
|
||||||
|
{
|
||||||
|
DG("interactive");
|
||||||
|
data->opts |= SH_INTERACTIVE;
|
||||||
|
data->opts |= SH_OPTS_JOBC;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DG("non interactive");
|
||||||
|
if (cliopts_get(av, shell_opts, data))
|
||||||
|
return (ft_perror());
|
||||||
|
if (SH_IS_INTERACTIVE(data->opts))
|
||||||
|
interactive_settings();
|
||||||
|
else
|
||||||
|
DG("not interactive");
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue