sample script

This commit is contained in:
Antoine Riard 2017-03-27 18:08:38 +02:00
commit 0b4bdc79a8
37 changed files with 202 additions and 162 deletions

View file

@ -6,7 +6,7 @@
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
# Updated: 2017/03/27 15:12:02 by ariard ### ########.fr #
# Updated: 2017/03/27 18:08:05 by ariard ### ########.fr #
# #
# **************************************************************************** #
@ -78,8 +78,6 @@ exec/exec_init.c\
exec/exec_leaf.c\
exec/exec_or_if.c\
exec/exec_pipe.c\
exec/exec_popfds.c\
exec/exec_pushfds.c\
exec/exec_semi.c\
exec/exec_var.c\
exec/fd_is_valid.c\
@ -197,6 +195,7 @@ job_control/job_update_id.c\
job_control/job_update_status.c\
job_control/job_wait.c\
job_control/jobc_destroy.c\
job_control/jobc_init.c\
job_control/mark_job_as_running.c\
job_control/pprint_brace.c\
job_control/pprint_case.c\
@ -286,8 +285,9 @@ main/data_init.c\
main/data_singleton.c\
main/ft_putast.c\
main/main.c\
main/shell_fds.c\
main/shell_init.c\
main/shell_reset.c\
main/shell_sig.c\
parser/add_bang.c\
parser/add_case.c\
parser/add_cmd.c\

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/02/18 11:13:04 by alao #+# #+# */
/* Updated: 2017/03/27 09:30:01 by alao ### ########.fr */
/* Updated: 2017/03/27 17:42:17 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -189,5 +189,6 @@ int ft_sstrlen(char **s);
char *ft_sstrtostr(char **s, char *sep);
char *ft_add_escape(char *str, char to_escape);
void c_lst_id(t_comp *c);
char *c_strdupi(char *s, int (*f)(char));
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/26 21:39:33 by jhalford ### ########.fr */
/* Updated: 2017/03/27 15:46:34 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -131,7 +131,6 @@ struct s_job
struct s_exec
{
t_job job;
t_list *fd_save[10];
t_flag attrs;
int fdin;
t_list *op_stack;
@ -141,8 +140,6 @@ struct s_exec
int exec_init(t_exec *exec);
int exec_destroy(t_exec *exec);
int exec_pushfds();
int exec_popfds();
int process_fork(t_process *p);
int process_setgroup(t_process *p, pid_t pid);
void process_setsig(void);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */
/* Updated: 2017/03/23 16:16:57 by gwojda ### ########.fr */
/* Updated: 2017/03/27 18:00:07 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -134,6 +134,7 @@ int ft_nb_of_line(char *str, size_t pos);
int ft_get_size_prev(char *str, size_t pos);
void sigwinch_resize(int sig);
size_t ft_hist_len(void);
int hist_is_delim(char c);
int underline_right(char **str, size_t *pos, size_t pos_ref);
int underline_left(char **str, size_t *pos, size_t pos_ref);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:11:08 by jhalford ### ########.fr */
/* Updated: 2017/03/27 16:01:12 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,6 +35,7 @@ struct s_jobc
struct termios shell_tmodes;
};
int jobc_init(t_jobc *jobc);
int jobc_destroy(t_jobc *jobc);
t_list *job_getprocess(pid_t pid);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */
/* Updated: 2017/03/25 15:44:08 by ariard ### ########.fr */
/* Updated: 2017/03/27 15:55:04 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -48,6 +48,7 @@ struct s_data
char **argv;
t_line line;
t_lexer lexer;
t_list *fd_save[10];
t_parser parser;
t_comp *comp;
t_exec exec;
@ -64,8 +65,14 @@ int data_init(int ac, char **av, char **env);
void data_exit(void);
int get_c_arg(char *opt_arg, t_data *data);
void shell_resetfds(void);
void shell_resetsig(void);
void shell_sig_reset(void);
void shell_fds_init(void);
void shell_fds_destroy(void);
int shell_fds_pop(void);
int shell_fds_push(void);
void shell_fds_reset(void);
void shell_fds_destroy(void);
char *ft_putast(void *node);
void ft_putast2(void *node);

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* cliopts.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/14 20:22:56 by jhalford #+# #+# */
/* Updated: 2017/03/25 14:59:53 by jhalford ### ########.fr */
/* Updated: 2017/03/27 17:17:05 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,7 +20,7 @@ typedef struct s_cliopts t_cliopts;
typedef struct s_data_template t_data_template;
typedef long long t_flag;
struct s_cliopts
struct s_cliopts
{
char c;
char *str;
@ -30,15 +30,18 @@ struct s_cliopts
int arg_required:1;
};
struct s_data_template
struct s_data_template
{
t_flag flag;
char **av_data;
};
int cliopts_get(char **av, t_cliopts opt_map[], void *data);
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[], char *arg);
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[], char arg);
int cliopts_has(char **av, char c);
int cliopts_get(char **av, t_cliopts opt_map[],
void *data);
t_cliopts *cliopts_getmap_long(t_cliopts opt_map[],
char *arg);
t_cliopts *cliopts_getmap_short(t_cliopts opt_map[],
char arg);
int cliopts_has(char **av, char c);
#endif

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* ft_lst_delif.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/04 11:09:12 by jhalford #+# #+# */
/* Updated: 2017/03/13 15:36:19 by jhalford ### ########.fr */
/* Updated: 2017/03/27 17:45:01 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 01:40:31 by jhalford #+# #+# */
/* Updated: 2017/03/25 01:42:02 by jhalford ### ########.fr */
/* Updated: 2017/03/27 16:58:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,6 +16,7 @@ int is_directory(const char *path)
{
struct stat path_stat;
stat(path, &path_stat);
if (stat(path, &path_stat) != 0)
return (0);
return (S_ISDIR(path_stat.st_mode));
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 01:10:56 by jhalford #+# #+# */
/* Updated: 2017/03/26 22:36:13 by jhalford ### ########.fr */
/* Updated: 2017/03/27 16:58:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,10 +15,10 @@
int try_access(char *file, int exists, t_flag a_flag)
{
if (exists && access(file, F_OK) != 0)
return (ERR_SET(E_SYS_NOFILE, file) * 0 - 1);
return (ERR_SET(E_SYS_NOFILE, file));
else if (is_directory(file))
return (ERR_SET(E_SYS_ISDIR, file) * 0 - 1);
return (ERR_SET(E_SYS_ISDIR, file));
else if (access(file, F_OK) == 0 && access(file, a_flag) != 0)
return (ERR_SET(E_SYS_NOPERM, file) * 0 - 1);
return (ERR_SET(E_SYS_NOPERM, file));
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/25 18:20:42 by ariard #+# #+# */
/* Updated: 2017/03/25 21:23:11 by ariard ### ########.fr */
/* Updated: 2017/03/27 17:11:36 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -31,7 +31,7 @@ static t_cliopts g_cdopts[] =
{0, NULL, 0, 0, NULL, 0},
};
int cd_file_autorisations(char *target, int flag)
int cd_file_autorisations(char *target, int flag)
{
(void)flag;
if (access(target, F_OK))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 13:09:57 by jhalford #+# #+# */
/* Updated: 2017/03/25 16:36:55 by ariard ### ########.fr */
/* Updated: 2017/03/27 16:03:10 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/15 13:27:14 by alao #+# #+# */
/* Updated: 2017/03/23 19:02:28 by gwojda ### ########.fr */
/* Updated: 2017/03/27 17:48:25 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,7 @@ static int c_is_delim(char c)
return (0);
}
static char *c_strdupi(char *s, int (*f)(char))
char *c_strdupi(char *s, int (*f)(char))
{
int i;
char *str;

View file

@ -6,7 +6,7 @@
/* By: alao <alao@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/20 14:50:33 by alao #+# #+# */
/* Updated: 2017/03/27 09:30:40 by alao ### ########.fr */
/* Updated: 2017/03/27 17:11:59 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,7 +29,7 @@ static void c_mv_tab(t_comp *c, int next)
ptr->next->cursor = 1;
else
ptr->prev->cursor = 1;
}
}
/*
** Once the completion has been processed, this is the return point.

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/27 03:09:58 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:10:37 by jhalford ### ########.fr */
/* Updated: 2017/03/27 15:56:47 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,9 @@
int exec_destroy(t_exec *exec)
{
if (!exec)
return (0);
return (1);
ft_lstdel(&exec->op_stack, ft_lst_cfree);
exec->attrs = 0;
exec->fdin = STDIN;
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/26 21:28:09 by jhalford #+# #+# */
/* Updated: 2017/03/26 22:13:04 by jhalford ### ########.fr */
/* Updated: 2017/03/27 15:57:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -24,19 +24,9 @@ int job_init(t_job *job)
int exec_init(t_exec *exec)
{
t_jobc *jobc;
int i;
jobc = &data_singleton()->jobc;
job_init(&exec->job);
i = -1;
while (++i < 10)
exec->fd_save[i] = NULL;
exec_pushfds();
exec->attrs = 0;
exec->fdin = STDIN;
exec->op_stack = NULL;
jobc->first_job = NULL;
jobc->current_id = 1;
return (0);
}

View file

@ -1,29 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_pushfds.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/26 21:31:46 by jhalford #+# #+# */
/* Updated: 2017/03/27 00:58:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int exec_pushfds(void)
{
int i;
int fd;
t_exec *exec;
exec = &data_singleton()->exec;
i = -1;
while (++i < 10)
{
fd = fcntl(i, F_DUPFD_CLOEXEC, 10);
push(&(exec->fd_save[i]), fd);
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
/* Updated: 2017/03/24 14:56:11 by wescande ### ########.fr */
/* Updated: 2017/03/27 16:03:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
/* Updated: 2017/03/22 21:32:36 by wescande ### ########.fr */
/* Updated: 2017/03/27 16:46:06 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -28,8 +28,8 @@ int plaunch_file(t_process *p)
error_launch(p->data.cmd.av[0], ": is a directory", 126);
else if (access(p->data.cmd.path, X_OK) == -1)
error_launch("permission denied: ", p->data.cmd.av[0], 126);
(*p->data.cmd.execf)(
p->data.cmd.path,
shell_fds_destroy();
execve(p->data.cmd.path,
p->data.cmd.av,
data_singleton()->env);
error_launch("internal execve error on ", p->data.cmd.av[0], 42);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
/* Updated: 2017/03/27 01:01:27 by jhalford ### ########.fr */
/* Updated: 2017/03/27 16:46:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -16,21 +16,24 @@ int process_fork(t_process *p)
{
pid_t pid;
if (!p)
return (0);
if ((pid = fork()) == -1)
exit(SH_ERR("fork(): %s", strerror(errno)));
else if (pid)
else if (pid != 0)
return (pid);
if (!p)
return (pid);
if (process_redirect(p))
exit(1);
process_setgroup(p, 0);
process_setsig();
exec_destroy(&data_singleton()->exec);
exec_init(&data_singleton()->exec);
data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC;
exit(p->map.launch(p));
jobc_destroy(&data_singleton()->jobc);
if ((pid = 1) && process_redirect(p) == 0)
{
shell_fds_push();
process_setgroup(p, 0);
process_setsig();
data_singleton()->opts &= ~(SH_INTERACTIVE | SH_OPTS_JOBC);
pid = p->map.launch(p);
}
shell_fds_destroy();
exit(pid);
}
int process_launch(t_process *p)
@ -52,12 +55,12 @@ int process_launch(t_process *p)
set_exitstatus(1, 1);
else
{
exec_pushfds();
shell_fds_push();
p->map.launch(p);
exec_popfds();
shell_resetfds();
shell_resetsig();
shell_fds_pop();
}
shell_fds_reset();
shell_sig_reset();
process_free(p, 0);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:07:37 by jhalford #+# #+# */
/* Updated: 2017/03/26 22:36:18 by jhalford ### ########.fr */
/* Updated: 2017/03/27 17:09:31 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -22,8 +22,7 @@ int redirect_dgreat(t_redir *redir)
if ((try_access(redir->word, 0, W_OK)))
return (ft_perror(NULL));
if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0)
exit (1);
exit(1);
fd_replace(fdold, fdnew);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */
/* Updated: 2017/03/26 22:36:20 by jhalford ### ########.fr */
/* Updated: 2017/03/27 16:40:05 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ int redirect_great(t_redir *redir)
if ((try_access(redir->word, 0, W_OK)))
return (ft_perror(NULL));
if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
exit (1);
exit(1);
fd_replace(fdold, fdnew);
return (0);
}

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* redirect_less.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */
/* Updated: 2017/03/27 01:02:30 by jhalford ### ########.fr */
/* Updated: 2017/03/27 17:12:24 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -21,7 +21,7 @@ int redirect_less(t_redir *redir)
if ((try_access(redir->word, 1, R_OK)) != 0)
return (ft_perror(NULL));
if ((fdold = open(redir->word, O_RDONLY, 0644)) < 0)
exit (1);
exit(1);
fd_replace(fdold, fdnew);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 11:39:47 by gwojda #+# #+# */
/* Updated: 2017/03/22 12:09:59 by gwojda ### ########.fr */
/* Updated: 2017/03/27 18:00:27 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -41,7 +41,6 @@ static int check_validity(char *str, int i)
else if (!str[i + 1] || str[i + 1] == '"')
return (0);
return (1);
}
static int history_parsing_nb_and_name(char *str, int *i)
@ -66,7 +65,7 @@ static int history_parsing_nb_and_name(char *str, int *i)
ft_strdupi_w(str + *i + 2));
else if (str[*i + 1] && str[*i + 1] != ' ')
ft_realloc_str_history_2(&(data_singleton()->line.input), *i,
ft_strdupi_w(str + *i + 1));
c_strdupi(str + *i + 1, hist_is_delim));
else
return (0);
return (1);

View file

@ -6,12 +6,19 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/25 14:09:39 by gwojda #+# #+# */
/* Updated: 2017/03/16 11:58:10 by gwojda ### ########.fr */
/* Updated: 2017/03/27 17:59:50 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int hist_is_delim(char c)
{
if (c == ' ' || c == '"')
return (1);
return (0);
}
static char *ft_nget_histo(size_t nb_his)
{
t_list_history *list;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 13:01:19 by jhalford #+# #+# */
/* Updated: 2017/03/21 14:14:45 by jhalford ### ########.fr */
/* Updated: 2017/03/27 15:58:33 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/27 03:09:41 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:10:55 by jhalford ### ########.fr */
/* Updated: 2017/03/27 15:59:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -1,30 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_popfds.c :+: :+: :+: */
/* jobc_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/26 21:31:05 by jhalford #+# #+# */
/* Updated: 2017/03/27 00:58:34 by jhalford ### ########.fr */
/* Created: 2017/03/27 15:59:03 by jhalford #+# #+# */
/* Updated: 2017/03/27 16:01:41 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int exec_popfds(void)
int jobc_init(t_jobc *jobc)
{
int i;
int fd;
t_exec *exec;
exec = &data_singleton()->exec;
i = -1;
while (++i < 10)
{
fd = pop(&exec->fd_save[i]);
if (fd != -1)
close(fd);
}
jobc->first_job = NULL;
jobc->current_id = 1;
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */
/* Updated: 2017/03/24 11:57:45 by gwojda ### ########.fr */
/* Updated: 2017/03/27 16:59:59 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -104,7 +104,7 @@ int ft_v(char **str, size_t *pos)
}
ft_current_str(*str, *pos);
ft_get_next_str(*str, pos);
ft_putnc('\b', *pos - tmp_pos);
ft_putnc('\b', *pos - tmp_pos + (((*str)[*pos]) ? 1 : 0));
*pos = tmp_pos;
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:33:41 by gwojda #+# #+# */
/* Updated: 2017/03/21 18:11:13 by gwojda ### ########.fr */
/* Updated: 2017/03/27 17:37:40 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/25 18:17:57 by ariard ### ########.fr */
/* Updated: 2017/03/27 17:38:51 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -35,6 +35,7 @@ int readline(int has_prompt, char **input)
if (has_prompt)
ret = ft_history_parsing(has_prompt, input);
ft_strdel(&data_singleton()->line.copy_tmp);
DG("ret = \"%s\"", *input);
if (tcsetattr(0, TCSANOW, ft_save_termios(0)) == -1)
return (-1);
return (ret);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/07 18:07:50 by jhalford #+# #+# */
/* Updated: 2017/03/27 03:11:57 by jhalford ### ########.fr */
/* Updated: 2017/03/27 16:04:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,7 +15,6 @@
void data_exit(void)
{
t_data *data;
int i;
data = data_singleton();
/* ft_strdel(&data->line.input); */
@ -27,9 +26,7 @@ void data_exit(void)
parser_destroy(&data->parser);
exec_destroy(&data->exec);
jobc_destroy(&data->jobc);
i = -1;
while (++i < 10)
ft_lstdel(&data->exec.fd_save[i], ft_lst_cfree);
shell_fds_destroy();
ft_lstdel(&data->lst_func, &tree_func_free);
ft_save_termios(-1);
ft_free_hash_table();

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */
/* Updated: 2017/03/26 21:54:19 by jhalford ### ########.fr */
/* Updated: 2017/03/27 16:00:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -86,6 +86,7 @@ int data_init(int ac, char **av, char **env)
lexer_init(&data->lexer);
parser_init(&data->parser);
exec_init(&data->exec);
jobc_init(&data->jobc);
if ((term_name = ft_getenv(data->env, "TERM")) == NULL)
term_name = "dumb";
if (tgetent(NULL, term_name) != 1)

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */
/* Updated: 2017/03/27 15:18:20 by ariard ### ########.fr */
/* Updated: 2017/03/27 18:08:20 by ariard ### ########.fr */
/* */
/* ************************************************************************** */

84
42sh/src/main/shell_fds.c Normal file
View file

@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* shell_fds.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/27 15:32:13 by jhalford #+# #+# */
/* Updated: 2017/03/27 15:57:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void shell_fds_init(void)
{
t_data *data;
int i;
data = data_singleton();
i = -1;
while (++i < 10)
data->fd_save[i] = NULL;
}
int shell_fds_push(void)
{
t_data *data;
int i;
int fd;
data = data_singleton();
i = -1;
while (++i < 10)
{
fd = fcntl(i, F_DUPFD_CLOEXEC, 10);
push(&(data->fd_save[i]), fd);
}
return (0);
}
int shell_fds_pop(void)
{
t_data *data;
int i;
int fd;
data = data_singleton();
i = -1;
while (++i < 10)
{
fd = pop(&data->fd_save[i]);
if (fd != -1)
close(fd);
}
return (0);
}
void shell_fds_reset(void)
{
t_data *data;
int i;
int fd;
data = data_singleton();
i = -1;
while (++i < 10)
{
fd = top(data->fd_save[i]);
if (fd != -1)
dup2(fd, i);
}
}
void shell_fds_destroy(void)
{
t_data *data;
int i;
data = data_singleton();
i = -1;
while (++i < 10)
ft_lstdel(&data->fd_save[i], ft_lst_cfree);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */
/* Updated: 2017/03/25 01:41:36 by wescande ### ########.fr */
/* Updated: 2017/03/27 17:13:41 by gwojda ### ########.fr */
/* */
/* ************************************************************************** */
@ -70,7 +70,7 @@ static int interactive_settings(void)
while (tcgetpgrp(STDIN) != (*shell_pgid = getpgrp()))
kill(-*shell_pgid, SIGTTIN);
*shell_pgid = getpid();
shell_resetsig();
shell_sig_reset();
if (setpgid(*shell_pgid, *shell_pgid))
{
SH_ERR("setpgid(): %s", strerror(errno));
@ -99,5 +99,6 @@ int shell_init(int ac, char **av, char **env)
return (-1);
if (SH_IS_INTERACTIVE(data->opts) && interactive_settings() < 0)
return (-1);
shell_fds_init();
return (0);
}

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* shell_reset.c :+: :+: :+: */
/* shell_sig_reset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/22 16:07:14 by jhalford #+# #+# */
/* Updated: 2017/03/24 20:09:29 by jhalford ### ########.fr */
/* Created: 2017/03/27 15:35:01 by jhalford #+# #+# */
/* Updated: 2017/03/27 15:35:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void shell_resetsig(void)
void shell_sig_reset(void)
{
signal(SIGINT, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
@ -21,19 +21,3 @@ void shell_resetsig(void)
signal(SIGTTOU, SIG_IGN);
signal(SIGCHLD, SIG_DFL);
}
void shell_resetfds(void)
{
t_exec *exec;
int i;
int fd;
exec = &data_singleton()->exec;
i = -1;
while (++i < 10)
{
fd = top(exec->fd_save[i]);
if (fd != -1)
dup2(fd, i);
}
}