herpderp (redux)
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
/* Created: 2024/02/07 14:12:49 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/03/23 17:13:22 by tomoron ### ########.fr */
|
/* Updated: 2024/03/23 19:04:17 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -98,6 +98,7 @@ void exec_commands(t_msh *msh)
|
|||||||
free(msh->fds);
|
free(msh->fds);
|
||||||
msh->fds = 0;
|
msh->fds = 0;
|
||||||
free(msh->pids);
|
free(msh->pids);
|
||||||
|
msh->pids = 0;
|
||||||
signal(SIGINT, signal_handler_interactive);
|
signal(SIGINT, signal_handler_interactive);
|
||||||
signal(SIGQUIT, signal_handler_interactive);
|
signal(SIGQUIT, signal_handler_interactive);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
/* Created: 2024/02/18 18:29:20 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/23 17:51:59 by tomoron ### ########.fr */
|
/* Updated: 2024/03/23 19:06:08 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -68,34 +68,43 @@ int ft_export(t_msh *msh)
|
|||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
int ft_unset(t_msh *msh)
|
void delete_from_env(t_env *env, char *name)
|
||||||
{
|
{
|
||||||
t_cmd *cmd;
|
|
||||||
t_env *tmp_env;
|
t_env *tmp_env;
|
||||||
t_env *prev;
|
t_env *prev;
|
||||||
|
|
||||||
|
while(tmp_env)
|
||||||
|
{
|
||||||
|
if(!strcmp(cmd->next->token, tmp_env->name))
|
||||||
|
{
|
||||||
|
free(tmp_env->name);
|
||||||
|
free(tmp_env->value);
|
||||||
|
if(!prev)
|
||||||
|
msh->env = tmp_env->next;
|
||||||
|
else
|
||||||
|
prev->next = tmp_env->next;
|
||||||
|
free(tmp_env);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
prev = tmp_env;
|
||||||
|
tmp_env = tmp_env->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
int ft_unset(t_msh *msh)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
t_cmd *cmd;
|
||||||
|
|
||||||
cmd = msh->cmds;
|
cmd = msh->cmds;
|
||||||
tmp_env = msh->env;
|
tmp_env = msh->env;
|
||||||
prev = 0;
|
prev = 0;
|
||||||
if(cmd && cmd->next && cmd->next->type == ARG)
|
if(cmd && cmd->next && cmd->next->type == ARG)
|
||||||
{
|
{
|
||||||
while(tmp_env)
|
|
||||||
{
|
|
||||||
if(!strcmp(cmd->next->token, tmp_env->name))
|
|
||||||
{
|
|
||||||
free(tmp_env->name);
|
|
||||||
free(tmp_env->value);
|
|
||||||
if(!prev)
|
|
||||||
msh->env = tmp_env->next;
|
|
||||||
else
|
|
||||||
prev->next = tmp_env->next;
|
|
||||||
free(tmp_env);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
prev = tmp_env;
|
|
||||||
tmp_env = tmp_env->next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
*/
|
||||||
|
(void)msh;
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/17 02:54:36 by tomoron #+# #+# */
|
/* Created: 2024/02/17 02:54:36 by tomoron #+# #+# */
|
||||||
/* Updated: 2024/02/21 17:21:27 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/23 18:35:04 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -30,6 +30,8 @@ t_cmd *handle_alias(t_msh *msh)
|
|||||||
while (tmp->next)
|
while (tmp->next)
|
||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
tmp->next = msh->cmds->next;
|
tmp->next = msh->cmds->next;
|
||||||
|
if(msh->cmds)
|
||||||
|
free(msh->cmds->token);
|
||||||
free(msh->cmds);
|
free(msh->cmds);
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
176
srcs/pids
Normal file
176
srcs/pids
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
exit.c: cur_cmd = msh->cmds->next;
|
||||||
|
exit.c: if(msh->fds)
|
||||||
|
exit.c: cmd_count = get_cmd_count(msh->cmds);
|
||||||
|
exit.c: free(msh->fds[cmd_count - 1]);
|
||||||
|
here_doc.c: write(msh->in_fd, line, ft_strlen(line));
|
||||||
|
here_doc.c: msh->in_fd = open(here_doc_file, O_CREAT | O_RDWR, 0644);
|
||||||
|
here_doc.c: if (msh->in_fd == -1)
|
||||||
|
here_doc.c: close(msh->in_fd);
|
||||||
|
here_doc.c: msh->in_fd = open(here_doc_file, O_RDWR, 0644);
|
||||||
|
here_doc.c: if (msh->in_fd == -1)
|
||||||
|
here_doc.c: close(msh->in_fd);
|
||||||
|
here_doc.c: msh->in_fd = open(here_doc_file, O_RDWR, 0644);
|
||||||
|
here_doc.c: if (msh->in_fd == -1)
|
||||||
|
unalias.c: alias = msh->aliases;
|
||||||
|
unalias.c: if (alias->next && msh->cmds->next
|
||||||
|
unalias.c: && !ft_strcmp(alias->next->name, msh->cmds->next->token))
|
||||||
|
unalias.c: if (msh->cmds->next && !ft_strcmp(msh->cmds->next->token, "-a"))
|
||||||
|
unalias.c: free_alias(msh->aliases);
|
||||||
|
unalias.c: msh->aliases = 0;
|
||||||
|
unalias.c: if (msh->cmds->next && msh->cmds->next->type == ARG)
|
||||||
|
unalias.c: msh->cmds->next->token);
|
||||||
|
pipe.c: if (msh->fds[i - 1][0] > 2)
|
||||||
|
pipe.c: close(msh->fds[i - 1][0]);
|
||||||
|
pipe.c: if (msh->fds[i - 1][1] > 2)
|
||||||
|
pipe.c: close(msh->fds[i - 1][1]);
|
||||||
|
pipe.c: if (msh->fds[i][0] > 2)
|
||||||
|
pipe.c: close(msh->fds[i][0]);
|
||||||
|
pipe.c: if (msh->fds[i][1] > 2)
|
||||||
|
pipe.c: close(msh->fds[i][1]);
|
||||||
|
pipe.c: if (msh->cmds->token && (!ft_strcmp(msh->cmds->token, "cd")
|
||||||
|
pipe.c: || !ft_strcmp(msh->cmds->token, "alias")
|
||||||
|
pipe.c: || !ft_strcmp(msh->cmds->token, "unalias")
|
||||||
|
pipe.c: || !ft_strcmp(msh->cmds->token, "exit") || exec_builtin(msh)))
|
||||||
|
pipe.c: free(msh->fds[i]);
|
||||||
|
pipe.c: msh->fds[i] = 0;
|
||||||
|
pipe.c: if (msh->cmds->token)
|
||||||
|
pipe.c: env = env_to_char_tab(msh->env);
|
||||||
|
pipe.c: execve(msh->cmds->token, cmd_args, env);
|
||||||
|
pipe.c: if ((msh->in_type != ARG && msh->in_type != PIPE)
|
||||||
|
pipe.c: || (msh->in_type == PIPE && i > 0))
|
||||||
|
pipe.c: if (msh->out_type == PIPE || msh->out_type == RED_O
|
||||||
|
pipe.c: || msh->out_type == RED_O_APP)
|
||||||
|
pipe.c: free(msh->fds[i]);
|
||||||
|
pipe.c: msh->fds[i] = 0;
|
||||||
|
pipe.c: if (msh->fds[i - 1][0] > 2)
|
||||||
|
pipe.c: close(msh->fds[i - 1][0]);
|
||||||
|
pipe.c: if (msh->fds[i - 1][1] > 2)
|
||||||
|
pipe.c: close(msh->fds[i - 1][1]);
|
||||||
|
pipe.c: if (msh->fds[i][0] > 2)
|
||||||
|
pipe.c: close(msh->fds[i][0]);
|
||||||
|
pipe.c: if (msh->fds[i][1] > 2)
|
||||||
|
pipe.c: close(msh->fds[i][1]);
|
||||||
|
pipe.c: if (msh->in_fd > 2)
|
||||||
|
pipe.c: close(msh->in_fd);
|
||||||
|
pipe.c: if (msh->out_fd > 2)
|
||||||
|
pipe.c: close(msh->out_fd);
|
||||||
|
exec.c: if (pipe(msh->fds[i]) == -1)
|
||||||
|
exec.c: msh->pids[i] = pid;
|
||||||
|
exec.c: msh->fds[i] = ft_calloc(2, sizeof(int *));
|
||||||
|
exec.c: if (!msh->fds[i])
|
||||||
|
exec.c: get_in_type(msh, msh->cmds);
|
||||||
|
exec.c: get_out_type(msh, msh->cmds);
|
||||||
|
exec.c: get_out_type(msh, msh->cmds);
|
||||||
|
exec.c: get_in_type(msh, msh->cmds);
|
||||||
|
exec.c: if (!cmd_is_builtin(msh, msh->cmds->token))
|
||||||
|
exec.c: if (!msh->cmds)
|
||||||
|
exec.c: cmd_count = get_cmd_count(msh->cmds);
|
||||||
|
exec.c: msh->fds = ft_calloc(cmd_count, sizeof(int **));
|
||||||
|
exec.c: msh->pids = ft_calloc(cmd_count, sizeof(int *));
|
||||||
|
exec.c: if (!msh->pids || !msh->fds)
|
||||||
|
exec.c: waitpid(msh->pids[i], &status, 0);
|
||||||
|
exec.c: free(msh->fds[i]);
|
||||||
|
exec.c: msh->fds[i] = 0;
|
||||||
|
exec.c: free(msh->fds);
|
||||||
|
exec.c: msh->fds = 0;
|
||||||
|
exec.c: free(msh->pids);
|
||||||
|
export.c: cmd = msh->cmds;
|
||||||
|
export.c: print_env_declare(msh->env);
|
||||||
|
export.c: msh->env = env_add_back(msh->env, name, value);
|
||||||
|
export.c: msh->env = tmp_env->next;
|
||||||
|
export.c: cmd = msh->cmds;
|
||||||
|
export.c: tmp_env = msh->env;
|
||||||
|
commands.c: args_count = get_args_count(msh->cmds);
|
||||||
|
commands.c: if (!cmd_args || !msh->fds)
|
||||||
|
commands.c: cur_cmd = msh->cmds;
|
||||||
|
commands.c: cur_cmd = msh->cmds;
|
||||||
|
commands.c: msh->in_type = cmd_tmp->type;
|
||||||
|
commands.c: msh->cmds = cur_cmd;
|
||||||
|
commands.c: msh->in_type = cur_cmd->type;
|
||||||
|
commands.c: msh->cmds = cur_cmd;
|
||||||
|
commands.c: msh->in_type = msh->cmds->type;
|
||||||
|
minishellrc.c: msh->cmds = parse_command(line, msh->env);
|
||||||
|
minishellrc.c: free_cmd(msh->cmds);
|
||||||
|
minishellrc.c: home = ft_get_env(msh->env, "HOME");
|
||||||
|
minishellrc.c: free(msh->env);
|
||||||
|
input_redirections.c: if (msh->in_type != PIPE)
|
||||||
|
input_redirections.c: if (dup2(msh->in_fd, 0) < 0)
|
||||||
|
input_redirections.c: close(msh->in_fd);
|
||||||
|
input_redirections.c: if (dup2(msh->fds[i - 1][0], 0) < 0)
|
||||||
|
input_redirections.c: if (msh->in_fd != 0)
|
||||||
|
input_redirections.c: close(msh->in_fd);
|
||||||
|
input_redirections.c: msh->in_fd = open((*cur_cmd)->next->token, O_RDONLY | O_CREAT);
|
||||||
|
input_redirections.c: if (msh->in_fd == -1 && !g_return_code)
|
||||||
|
input_redirections.c: msh->in_type = cur_cmd->type;
|
||||||
|
input_redirections.c: cur_cmd = msh->cmds;
|
||||||
|
path.c: path = ft_strjoin(tmp, msh->cmds->token);
|
||||||
|
path.c: free(msh->cmds->token);
|
||||||
|
path.c: msh->cmds->token = path;
|
||||||
|
path.c: paths = split_paths_from_env(msh->env);
|
||||||
|
path.c: if (ft_strchr(msh->cmds->token, '/'))
|
||||||
|
path.c: ft_printf_fd(2, "%s: command not found\n", msh->cmds->token);
|
||||||
|
path.c: free(msh->cmds->token);
|
||||||
|
path.c: msh->cmds->token = 0;
|
||||||
|
main.c: msh->aliases = alias_add_back(msh->aliases, ft_strdup("ls"), ft_strdup("ls --color=auto"));
|
||||||
|
main.c: while (msh->env && commands)
|
||||||
|
main.c: prompt = get_prompt(msh->env);
|
||||||
|
main.c: msh->cmds = parse_command(commands, msh->env);
|
||||||
|
main.c: msh->cmds = handle_alias(msh);
|
||||||
|
main.c: free_cmd(msh->cmds);
|
||||||
|
handle_alias.c: if (!msh->cmds)
|
||||||
|
handle_alias.c: if (msh->cmds->type == ARG)
|
||||||
|
handle_alias.c: alias_command = get_alias(msh->aliases, msh->cmds->token);
|
||||||
|
handle_alias.c: return (msh->cmds);
|
||||||
|
handle_alias.c: res = parse_command(alias_command, msh->env);
|
||||||
|
handle_alias.c: tmp->next = msh->cmds->next;
|
||||||
|
handle_alias.c: if(msh->cmds)
|
||||||
|
handle_alias.c: free(msh->cmds->token);
|
||||||
|
handle_alias.c: free(msh->cmds);
|
||||||
|
alias.c: if (!msh->cmds->next || msh->cmds->next->type != ARG)
|
||||||
|
alias.c: print_aliases(msh->aliases);
|
||||||
|
alias.c: name = get_alias_name(msh->cmds->next);
|
||||||
|
alias.c: if (ft_strchr(msh->cmds->next->token, '='))
|
||||||
|
alias.c: value = get_alias_value(msh->cmds->next);
|
||||||
|
alias.c: msh->aliases = alias_add_back(msh->aliases, name, value);
|
||||||
|
alias.c: if (get_alias(msh->aliases, name))
|
||||||
|
alias.c: ft_printf("alias %s=%s\n", name, get_alias(msh->aliases, name));
|
||||||
|
builtins.c: cd(msh->cmds);
|
||||||
|
builtins.c: if (!(msh->in_type == PIPE || msh->out_type == PIPE))
|
||||||
|
builtins.c: if (!msh->cmds->token)
|
||||||
|
builtins.c: if (!ft_strcmp(msh->cmds->token, "echo"))
|
||||||
|
builtins.c: g_return_code = echo(msh->cmds->next);
|
||||||
|
builtins.c: else if (!ft_strcmp(msh->cmds->token, "ret"))
|
||||||
|
builtins.c: g_return_code = ft_atoi(msh->cmds->next->token);
|
||||||
|
builtins.c: else if (!ft_strcmp(msh->cmds->token, "env"))
|
||||||
|
builtins.c: g_return_code = print_env(msh->env);
|
||||||
|
builtins.c: else if (!ft_strcmp(msh->cmds->token, "exit"))
|
||||||
|
builtins.c: else if (!ft_strcmp(msh->cmds->token, "pwd"))
|
||||||
|
builtins.c: else if (!ft_strcmp(msh->cmds->token, "cd"))
|
||||||
|
builtins.c: g_return_code = cd(msh->cmds);
|
||||||
|
builtins.c: else if (!ft_strcmp(msh->cmds->token, "alias"))
|
||||||
|
builtins.c: else if (!ft_strcmp(msh->cmds->token, "unalias"))
|
||||||
|
utils.c: free_env(msh->env);
|
||||||
|
utils.c: free_alias(msh->aliases);
|
||||||
|
utils.c: free(msh->pids);
|
||||||
|
utils.c: free(msh->fds);
|
||||||
|
utils.c: free_cmd(msh->cmds);
|
||||||
|
utils.c: fd = open(msh->cmds->token, O_DIRECTORY);
|
||||||
|
utils.c: ft_printf_fd(2, "minishell: %s: Is a directory\n", msh->cmds->token);
|
||||||
|
utils.c: if (access(msh->cmds->token, X_OK) != -1)
|
||||||
|
utils.c: ft_printf_fd(2, "minishell: %s: ", msh->cmds->token);
|
||||||
|
utils.c: if (access(msh->cmds->token, F_OK) != -1)
|
||||||
|
output_redirections.c: if (msh->out_type != PIPE)
|
||||||
|
output_redirections.c: if (dup2(msh->out_fd, 1) < 0)
|
||||||
|
output_redirections.c: if (dup2(msh->fds[i][1], 1) < 0)
|
||||||
|
output_redirections.c: msh->out_type = (*cur_cmd)->type;
|
||||||
|
output_redirections.c: if (msh->out_type == RED_O)
|
||||||
|
output_redirections.c: msh->out_fd = open((*cur_cmd)->next->token,
|
||||||
|
output_redirections.c: if (msh->out_type == RED_O_APP)
|
||||||
|
output_redirections.c: msh->out_fd = open((*cur_cmd)->next->token,
|
||||||
|
output_redirections.c: if (msh->out_fd == -1)
|
||||||
|
output_redirections.c: msh->out_type = ARG;
|
||||||
|
output_redirections.c: msh->out_fd = 0;
|
||||||
|
output_redirections.c: if (cmds->type && msh->cmds == cmds)
|
||||||
|
output_redirections.c: while (msh->cmds->type != ARG && msh->cmds->next->next)
|
||||||
|
output_redirections.c: msh->cmds = msh->cmds->next->next;
|
||||||
|
output_redirections.c: msh->out_type = ARG;
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
/* Created: 2024/03/05 18:19:26 by marde-vr #+# #+# */
|
||||||
/* Updated: 2024/03/23 18:14:05 by marde-vr ### ########.fr */
|
/* Updated: 2024/03/23 19:02:06 by tomoron ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -36,9 +36,9 @@ int file_access(t_msh *msh, int *found)
|
|||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd = open(msh->cmds->token, O_DIRECTORY);
|
fd = open(msh->cmds->token, O_DIRECTORY);
|
||||||
close(fd);
|
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
{
|
{
|
||||||
|
close(fd);
|
||||||
ft_printf_fd(2, "minishell: %s: Is a directory\n", msh->cmds->token);
|
ft_printf_fd(2, "minishell: %s: Is a directory\n", msh->cmds->token);
|
||||||
g_return_code = 126;
|
g_return_code = 126;
|
||||||
return (0);
|
return (0);
|
||||||
|
Reference in New Issue
Block a user