clean after rebase

This commit is contained in:
wescande 2017-01-26 16:59:41 +01:00 committed by Jack Halford
parent d857f74a86
commit a0feff2e2a
6 changed files with 55 additions and 193 deletions

View file

@ -122,14 +122,15 @@ INC_DIR = includes/
OBJ_DIR = objs/ OBJ_DIR = objs/
SRC_BASE = \ SRC_BASE = \
builtin/builtin.c\
builtin/builtin_cd.c\ builtin/builtin_cd.c\
builtin/builtin_echo.c\ builtin/builtin_echo.c\
builtin/builtin_env.c\ builtin/builtin_env.c\
builtin/builtin_exit.c\ builtin/builtin_exit.c\
builtin/builtin_setenv.c\ builtin/builtin_setenv.c\
builtin/builtin_unsetenv.c\ builtin/builtin_unsetenv.c\
builtin/is_builtin.c\
exec/ast_free.c\ exec/ast_free.c\
exec/exec_ampersand.c\
exec/exec_and_if.c\ exec/exec_and_if.c\
exec/exec_command.c\ exec/exec_command.c\
exec/exec_dgreat.c\ exec/exec_dgreat.c\
@ -138,10 +139,13 @@ exec/exec_less.c\
exec/exec_or_if.c\ exec/exec_or_if.c\
exec/exec_pipe.c\ exec/exec_pipe.c\
exec/exec_semi.c\ exec/exec_semi.c\
exec/fd_redirect.c\
exec/ft_cmd.c\
exec/ft_exec.c\ exec/ft_exec.c\
exec/ft_findexec.c\ exec/ft_findexec.c\
exec/launch_process.c\
exec/process_redirect.c\
exec/process_reset.c\
exec/process_setexec.c\
exec/process_setgroup.c\
exec/set_exitstatus.c\ exec/set_exitstatus.c\
glob/dir_glob.c\ glob/dir_glob.c\
glob/expand_brace.c\ glob/expand_brace.c\
@ -162,7 +166,42 @@ glob/lib_perso/ft_ld_to_tab.c\
glob/lib_perso/ft_strjoinf.c\ glob/lib_perso/ft_strjoinf.c\
glob/lib_perso/ft_tabdel.c\ glob/lib_perso/ft_tabdel.c\
glob/match_pattern.c\ glob/match_pattern.c\
job-control/builtin_bg.c\
job-control/builtin_fg.c\
job-control/builtin_jobs.c\
job-control/do_job_notification.c\
job-control/job_addprocess.c\
job-control/job_cmp_id.c\
job-control/job_format.c\
job-control/job_format_head.c\
job-control/job_free.c\
job-control/job_getprocess.c\
job-control/job_getrank.c\
job-control/job_is_completed.c\
job-control/job_is_stopped.c\
job-control/job_kill_all.c\
job-control/job_notify_change.c\
job-control/job_notify_new.c\
job-control/job_remove.c\
job-control/job_update_id.c\
job-control/job_update_status.c\
job-control/job_wait.c\
job-control/mark_job_as_running.c\
job-control/process_cmp_pid.c\
job-control/process_format.c\
job-control/process_free.c\
job-control/process_mark_status.c\
job-control/put_job_in_background.c\
job-control/put_job_in_foreground.c\
job-control/sigchld_handler.c\
job-control/sigint_handler.c\
job-control/sigtstp_handler.c\
job-control/sigttin_handler.c\
job-control/sigttou_handler.c\
lexer/command_getoutput.c\
lexer/ft_post_tokenize.c\
lexer/ft_tokenize.c\ lexer/ft_tokenize.c\
lexer/get_lexer_state.c\
lexer/lexer_backslash.c\ lexer/lexer_backslash.c\
lexer/lexer_default.c\ lexer/lexer_default.c\
lexer/lexer_delim.c\ lexer/lexer_delim.c\
@ -174,9 +213,14 @@ lexer/lexer_lessand.c\
lexer/lexer_number.c\ lexer/lexer_number.c\
lexer/lexer_quote.c\ lexer/lexer_quote.c\
lexer/lexer_sep.c\ lexer/lexer_sep.c\
lexer/lexer_special.c\
lexer/lexer_var.c\
lexer/lexer_word.c\ lexer/lexer_word.c\
lexer/reduce_bquotes.c\
lexer/reduce_parens.c\
lexer/token_append.c\ lexer/token_append.c\
lexer/token_cmp_type.c\ lexer/token_cmp_type.c\
lexer/token_expand_var.c\
lexer/token_free.c\ lexer/token_free.c\
lexer/token_init.c\ lexer/token_init.c\
lexer/token_print.c\ lexer/token_print.c\
@ -188,7 +232,6 @@ line-editing/curs_setup.c\
line-editing/curs_single.c\ line-editing/curs_single.c\
line-editing/curs_term_setup.c\ line-editing/curs_term_setup.c\
line-editing/curs_write.c\ line-editing/curs_write.c\
line-editing/ft_interactive_sh.c\
line-editing/ft_readline.c\ line-editing/ft_readline.c\
line-editing/rl_bitset.c\ line-editing/rl_bitset.c\
line-editing/rl_clear_function.c\ line-editing/rl_clear_function.c\
@ -212,11 +255,16 @@ line-editing/rl_word_move_function.c\
line-editing/rl_word_utility.c\ line-editing/rl_word_utility.c\
main/data_exit.c\ main/data_exit.c\
main/data_init.c\ main/data_init.c\
main/data_singleton.c\
main/ft_cleanup.c\ main/ft_cleanup.c\
main/ft_putast.c\ main/ft_putast.c\
main/ft_putast2.c\ main/ft_putast2.c\
main/lib_expansion.c\ main/lib_expansion.c\
main/main.c\ main/main.c\
main/shell_exit.c\
main/shell_get_avdata.c\
main/shell_get_opts.c\
main/shell_init.c\
main/sig_handler.c\ main/sig_handler.c\
parser/ft_parse.c\ parser/ft_parse.c\
parser/parse_dgreat.c\ parser/parse_dgreat.c\
@ -226,6 +274,7 @@ parser/parse_greatand.c\
parser/parse_less.c\ parser/parse_less.c\
parser/parse_lessand.c\ parser/parse_lessand.c\
parser/parse_separator.c\ parser/parse_separator.c\
parser/parse_subshell.c\
parser/parse_word.c parser/parse_word.c
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))

View file

@ -1,51 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 14:21:34 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:17:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_stof g_builtin[] = {
{"echo", &builtin_echo},
{"cd", &builtin_cd},
{"setenv", &builtin_setenv},
{"unsetenv", &builtin_unsetenv},
{"env", &builtin_env},
{"exit", &builtin_exit},
{NULL, NULL},
};
int ft_builtin(char **av, t_data *data)
{
int i;
int ret;
i = -1;
while (g_builtin[++i].name)
if (ft_strcmp(g_builtin[i].name, *av) == 0)
{
if (data->exec.fdout != STDOUT)
{
if (fork() == 0)
{
fd_redirect(data);
ret = (g_builtin[i].f)(av, data);
exit(ret);
}
}
else
{
ret = (g_builtin[i].f)(av, data);
set_exitstatus(data, ret);
}
return (1);
}
return (0);
}

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_redirect.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */
/* Updated: 2016/12/03 15:24:08 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void fd_redirect(t_data *data)
{
if (data->exec.fdin != STDIN)
{
dup2(data->exec.fdin, STDIN);
close(data->exec.fdin);
}
if (data->exec.fdout != STDOUT)
{
dup2(data->exec.fdout, STDOUT);
close(data->exec.fdout);
}
}

View file

@ -1,65 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 21:13:18 by jhalford #+# #+# */
/* Updated: 2016/12/09 21:50:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
extern pid_t g_pid;
int ft_cmd_process(char **argv, t_data *data)
{
char *execpath;
ft_expand_dollar(argv, data->env);
if (ft_builtin(argv, data))
return (0);
else if (ft_strchr(argv[0], '/'))
execpath = argv[0];
else if (!(execpath = ft_findexec(ft_getenv(data->env, "PATH"), argv[0])))
{
ft_dprintf(2, "%s: command not found: %s\n", SHELL_NAME, argv[0]);
set_exitstatus(data, 127);
return (-1);
}
return (ft_cmd_exec(execpath, argv, data));
}
int ft_cmd_exec(char *execpath, char **argv, t_data *data)
{
pid_t pid;
int status;
if (access(execpath, X_OK) == -1)
{
ft_dprintf(2, "%s: permission denied: %s\n", SHELL_NAME, argv[0]);
ft_strdel(&execpath);
return (-1);
}
if ((pid = fork()) == -1)
return (-1);
else if (pid == 0)
{
fd_redirect(data);
execve(execpath, argv, data->env);
}
else
{
ft_strdel(&execpath);
g_pid = pid;
if (data->exec.fdout == STDOUT)
{
waitpid(pid, &status, 0);
set_exitstatus(data, status);
}
g_pid = 0;
}
return (0);
}

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* interactive_sh.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sbenning <sbenning@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 09:44:43 by sbenning #+# #+# */
/* Updated: 2016/12/10 10:24:12 by sbenning ### ########.fr */
/* */
/* ************************************************************************** */
#include "line_editing.h"
t_data **data_singleton(void)
{
static t_data *data;
return (&data);
}
int ft_interactive_sh(t_data *data)
{
*data_singleton() = data;
return (ft_readline(&data->line));
}

View file

@ -6,11 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
<<<<<<< HEAD:src/main/main.c /* Updated: 2017/01/26 16:54:26 by wescande ### ########.fr */
/* Updated: 2017/01/12 14:02:30 by jhalford ### ########.fr */
=======
/* Updated: 2017/01/05 16:07:09 by wescande ### ########.fr */
>>>>>>> premier commit. working. . .:srcs/main/main.c
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,11 +26,11 @@ int shell_single_command(char *command)
return (1); return (1);
if (!token) if (!token)
return (0); return (0);
token_print(token);
if (ft_post_tokenize(&token, command)) if (ft_post_tokenize(&token, command))
return (1); return (1);
DG("after post_tokenize"); DG("after post_tokenize");
token_print(token); token_print(token);
glob_print(token, data_singleton());
if (ft_parse(&ast, &token)) if (ft_parse(&ast, &token))
return (1); return (1);
/* btree_print(STDBUG, ast, &ft_putast); */ /* btree_print(STDBUG, ast, &ft_putast); */
@ -56,21 +52,7 @@ int main(int ac, char **av)
} }
while (1) while (1)
{ {
<<<<<<< HEAD:src/main/main.c
if (ft_readline()) if (ft_readline())
=======
if (ft_interactive_sh(&data))
return (1);
DG("{inv}{mag}got command '%s'", data.line.input);
token = NULL;
if (ft_tokenize(&token, data.line.input, DEFAULT))
return (1);
if (!token)
continue ;
// token_print(token);
glob_print(token, &data);
if (ft_parse(&ast, &token))
>>>>>>> premier commit. working. . .:srcs/main/main.c
return (1); return (1);
if (shell_single_command(data_singleton()->line.input)) if (shell_single_command(data_singleton()->line.input))
return (1); return (1);