mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
Compare commits
No commits in common. "38dfe3c084108d2bcbfb7afbe60950c895ced8e0" and "dd94aba23b73cf2a7abe39128df1072c6c34437f" have entirely different histories.
38dfe3c084
...
dd94aba23b
27 changed files with 133 additions and 139 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -39,5 +39,3 @@ fuzz
|
|||
fuzz_hand_tester
|
||||
*CORPUS
|
||||
crash-*
|
||||
test.sh
|
||||
std.supp
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/04 19:50:42 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 14:26:49 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/30 14:06:24 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,12 +21,14 @@
|
|||
t_subprocess group_cmd_execute(t_group_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
int pid;
|
||||
t_std_fds fds;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
{
|
||||
handle_redirections(cmd->redirects, app);
|
||||
handle_redirections(cmd->redirects, app, &fds);
|
||||
cmd_execute(cmd->cmd, app);
|
||||
restore_std_fds(&fds);
|
||||
return (SUBPROCESS);
|
||||
}
|
||||
if (pid < 0)
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 14:48:26 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 14:49:50 by kcolin ### ########.fr */
|
||||
/* Created: 2025/04/01 16:37:21 by kcolin #+# #+# */
|
||||
/* Updated: 2025/04/29 15:54:21 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "builtins.h"
|
||||
#include "handle_redirections.h"
|
||||
#include "libft.h"
|
||||
#include "simple_cmd_execute.h"
|
||||
#include "std_fds.h"
|
||||
|
|
@ -41,9 +40,8 @@ t_builtin_type get_builtin(t_simple_cmd *cmd)
|
|||
}
|
||||
|
||||
t_subprocess execute_builtin(t_simple_cmd *cmd, t_minishell *app,
|
||||
t_builtin_type type)
|
||||
t_std_fds *fds, t_builtin_type type)
|
||||
{
|
||||
t_std_fds fds;
|
||||
t_subprocess retvalue;
|
||||
static t_subprocess (*builtins[])(t_simple_cmd *, t_minishell *) = {
|
||||
[BUILTIN_INVALID] = builtin_invalid,
|
||||
|
|
@ -56,13 +54,8 @@ t_subprocess execute_builtin(t_simple_cmd *cmd, t_minishell *app,
|
|||
[BUILTIN_UNSET] = builtin_unset,
|
||||
};
|
||||
|
||||
std_fds_save(&fds);
|
||||
if (handle_redirections(cmd->redirections, app) == NULL)
|
||||
{
|
||||
restore_std_fds(&fds);
|
||||
return (PARENTPROCESS);
|
||||
}
|
||||
retvalue = builtins[type](cmd, app);
|
||||
restore_std_fds(&fds);
|
||||
if (type != BUILTIN_INVALID)
|
||||
restore_std_fds(fds);
|
||||
return (retvalue);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/31 14:16:13 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 14:49:59 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/29 15:46:28 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,6 +26,6 @@ t_subprocess builtin_unset(t_simple_cmd *cmd, t_minishell *app);
|
|||
|
||||
t_builtin_type get_builtin(t_simple_cmd *cmd);
|
||||
t_subprocess execute_builtin(t_simple_cmd *cmd, t_minishell *app,
|
||||
t_builtin_type type);
|
||||
t_std_fds *fds, t_builtin_type type);
|
||||
|
||||
#endif // BUILTINS_H
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 11:14:40 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:15:25 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/29 16:55:24 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,19 +41,16 @@ static t_redirect *do_redirection(t_redirect *redirection)
|
|||
return (redirection);
|
||||
}
|
||||
|
||||
t_minishell *handle_redirections(t_redirect *redirections, t_minishell *app)
|
||||
t_minishell *handle_redirections(t_redirect *redirections, t_minishell *app,
|
||||
t_std_fds *fds)
|
||||
{
|
||||
std_fds_save(fds);
|
||||
while (redirections != NULL)
|
||||
{
|
||||
if (do_redirection(redirections) == NULL)
|
||||
{
|
||||
restore_std_fds(fds);
|
||||
app->last_return_value = 1;
|
||||
while (redirections != NULL)
|
||||
{
|
||||
if (redirections->type == FT_HEREDOC)
|
||||
unlink(redirections->redirectee.filename->word);
|
||||
redirections = redirections->next;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
redirections = redirections->next;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/17 11:14:29 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 14:23:49 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/28 12:45:17 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,6 @@
|
|||
# include "../../minishell.h"
|
||||
|
||||
t_minishell *handle_redirections(t_redirect *redirections,
|
||||
t_minishell *app);
|
||||
t_minishell *app, t_std_fds *fds);
|
||||
|
||||
#endif // HANDLE_REDIRECTIONS_H
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* simple_cmd_execute.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 14:25:45 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 14:59:02 by kcolin ### ########.fr */
|
||||
/* Created: 2025/03/27 16:21:56 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/02 12:49:22 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -76,31 +76,34 @@ static t_subprocess fork_fail(t_minishell *app)
|
|||
return (PARENTPROCESS);
|
||||
}
|
||||
|
||||
static t_subprocess exec_external_cmd(t_simple_cmd *cmd, t_minishell *app)
|
||||
static t_subprocess exec_external_cmd(t_simple_cmd *cmd, t_minishell *app,
|
||||
t_std_fds *fds)
|
||||
{
|
||||
char *exe;
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
if (cmd->words == NULL)
|
||||
return (restore_std_fds(fds), PARENTPROCESS);
|
||||
exe = get_cmdpath(cmd->words->word->word, app);
|
||||
if (exe != NULL)
|
||||
{
|
||||
if (handle_redirections(cmd->redirections, app) == NULL)
|
||||
return (SUBPROCESS);
|
||||
if (cmd->words == NULL)
|
||||
return (SUBPROCESS);
|
||||
exe = get_cmdpath(cmd->words->word->word, app);
|
||||
if (exe == NULL)
|
||||
return (command_not_found(cmd, app), SUBPROCESS);
|
||||
return (execute_subprocess(exe, cmd, app));
|
||||
pid = fork();
|
||||
if (pid == 0)
|
||||
return (execute_subprocess(exe, cmd, app, fds));
|
||||
free(exe);
|
||||
if (pid < 0)
|
||||
return (fork_fail(app));
|
||||
do_waitpid(app, pid);
|
||||
}
|
||||
if (pid < 0)
|
||||
return (fork_fail(app));
|
||||
do_waitpid(app, pid);
|
||||
restore_std_fds(fds);
|
||||
if (exe == NULL)
|
||||
command_not_found(cmd, app);
|
||||
return (PARENTPROCESS);
|
||||
}
|
||||
|
||||
t_subprocess simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
|
||||
{
|
||||
t_std_fds fds;
|
||||
t_builtin_type type;
|
||||
|
||||
if (cmd == NULL)
|
||||
|
|
@ -113,8 +116,10 @@ t_subprocess simple_cmd_execute(t_simple_cmd *cmd, t_minishell *app)
|
|||
return (PARENTPROCESS);
|
||||
}
|
||||
simple_cmd_execute_debug(cmd, app);
|
||||
if (handle_redirections(cmd->redirections, app, &fds) == NULL)
|
||||
return (PARENTPROCESS);
|
||||
type = get_builtin(cmd);
|
||||
if (type != BUILTIN_INVALID)
|
||||
return (execute_builtin(cmd, app, type));
|
||||
return (exec_external_cmd(cmd, app));
|
||||
return (execute_builtin(cmd, app, &fds, type));
|
||||
return (exec_external_cmd(cmd, app, &fds));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 14:50:26 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 14:50:26 by kcolin ### ########.fr */
|
||||
/* Created: 2025/04/02 18:19:23 by kcolin #+# #+# */
|
||||
/* Updated: 2025/04/29 15:14:32 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -72,8 +72,9 @@ static int ft_execve(char *exe, char **argv, char **envp)
|
|||
}
|
||||
|
||||
t_subprocess execute_subprocess(char *exe, t_simple_cmd *cmd,
|
||||
t_minishell *app)
|
||||
t_minishell *app, t_std_fds *fds)
|
||||
{
|
||||
std_fds_close(fds);
|
||||
app->last_return_value = ft_execve(exe, argv_from_wordlist(cmd->words),
|
||||
envp_from_env(app->env));
|
||||
return (SUBPROCESS);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/02 18:17:48 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 14:50:33 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/29 15:14:09 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -16,6 +16,6 @@
|
|||
# include "../../minishell.h"
|
||||
|
||||
t_subprocess execute_subprocess(char *exe, t_simple_cmd *cmd,
|
||||
t_minishell *app);
|
||||
t_minishell *app, t_std_fds *fds);
|
||||
|
||||
#endif // SUBPROCESS_H
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* minishell.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 17:12:03 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:12:03 by kcolin ### ########.fr */
|
||||
/* Created: 2025/05/02 11:53:53 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/02 17:38:40 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ int main(int argc, char *argv[], char **envp)
|
|||
free(line);
|
||||
debug_command(cmd, &app);
|
||||
retvalue = execute_command(cmd, &app);
|
||||
cmd_destroy(cmd, false);
|
||||
cmd_destroy(cmd);
|
||||
if (retvalue == SUBPROCESS)
|
||||
break ;
|
||||
line = get_command(&app);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/09 16:53:02 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:10:21 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/05/05 11:22:40 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
#include "../simple_cmd/simple_cmd.h"
|
||||
#include "libft.h"
|
||||
|
||||
void redirect_destroy(t_redirect *redirect, bool delete_file)
|
||||
void redirect_destroy(t_redirect *redirect)
|
||||
{
|
||||
t_redirect *next;
|
||||
|
||||
|
|
@ -25,8 +25,7 @@ void redirect_destroy(t_redirect *redirect, bool delete_file)
|
|||
free(redirect->here_doc_eof);
|
||||
if (redirect->type == FT_HEREDOC
|
||||
&& redirect->redirectee.filename != NULL
|
||||
&& redirect->redirectee.filename->word != NULL
|
||||
&& delete_file)
|
||||
&& redirect->redirectee.filename->word != NULL)
|
||||
unlink(redirect->redirectee.filename->word);
|
||||
worddesc_destroy(redirect->redirectee.filename);
|
||||
free(redirect->unexpanded_filename);
|
||||
|
|
@ -35,33 +34,33 @@ void redirect_destroy(t_redirect *redirect, bool delete_file)
|
|||
}
|
||||
}
|
||||
|
||||
static void connec_cmd_destroy(t_connec_cmd *cmd, bool delete_file)
|
||||
static void connec_cmd_destroy(t_connec_cmd *cmd)
|
||||
{
|
||||
if (cmd == NULL)
|
||||
return ;
|
||||
cmd_destroy(cmd->first, delete_file);
|
||||
cmd_destroy(cmd->second, delete_file);
|
||||
cmd_destroy(cmd->first);
|
||||
cmd_destroy(cmd->second);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
static void group_cmd_destroy(t_group_cmd *cmd, bool delete_file)
|
||||
static void group_cmd_destroy(t_group_cmd *cmd)
|
||||
{
|
||||
if (cmd == NULL)
|
||||
return ;
|
||||
cmd_destroy(cmd->cmd, delete_file);
|
||||
redirect_destroy(cmd->redirects, delete_file);
|
||||
cmd_destroy(cmd->cmd);
|
||||
redirect_destroy(cmd->redirects);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
void cmd_destroy(t_cmd *cmd, bool delete_file)
|
||||
void cmd_destroy(t_cmd *cmd)
|
||||
{
|
||||
if (cmd == NULL)
|
||||
return ;
|
||||
if (cmd->type == FT_CONNECTION)
|
||||
connec_cmd_destroy(cmd->value.connection, delete_file);
|
||||
connec_cmd_destroy(cmd->value.connection);
|
||||
if (cmd->type == FT_GROUP)
|
||||
group_cmd_destroy(cmd->value.group, delete_file);
|
||||
group_cmd_destroy(cmd->value.group);
|
||||
if (cmd->type == FT_SIMPLE)
|
||||
simple_cmd_destroy(cmd->value.simple, delete_file);
|
||||
simple_cmd_destroy(cmd->value.simple);
|
||||
free(cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/09 16:52:31 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:08:41 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/14 15:10:13 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
# include "../../minishell.h"
|
||||
|
||||
void cmd_destroy(t_cmd *cmd, bool delete_file);
|
||||
void redirect_destroy(t_redirect *redirect, bool delete_file);
|
||||
void cmd_destroy(t_cmd *cmd);
|
||||
void redirect_destroy(t_redirect *redirect);
|
||||
|
||||
#endif // CMD_DESTROY_H
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* cmds_parse.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 17:09:29 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:10:00 by kcolin ### ########.fr */
|
||||
/* Created: 2025/04/16 13:11:33 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/02 12:49:54 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -29,7 +29,7 @@ t_cmd *minishell_cmds_parse(t_minishell *app, t_wordlist **tokens)
|
|||
return (NULL);
|
||||
opt = minishell_opt_cmds_parse(app, tokens, &connec);
|
||||
if (!opt && ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(subtree, true), NULL);
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
if (!opt)
|
||||
return (subtree);
|
||||
while (opt)
|
||||
|
|
@ -42,6 +42,6 @@ t_cmd *minishell_cmds_parse(t_minishell *app, t_wordlist **tokens)
|
|||
opt = minishell_opt_cmds_parse(app, tokens, &connec);
|
||||
}
|
||||
if (ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(subtree, true), NULL);
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
return (list);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* cmd_parsing.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 17:10:37 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:10:43 by kcolin ### ########.fr */
|
||||
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
|
||||
/* Updated: 2025/05/02 13:00:27 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line)
|
|||
else
|
||||
parse_error(app, tokens->word);
|
||||
wordlist_destroy(tokens);
|
||||
cmd_destroy(root_cmd, true);
|
||||
cmd_destroy(root_cmd);
|
||||
return (NULL);
|
||||
}
|
||||
return (root_cmd);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 11:37:35 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:10:36 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/15 11:39:41 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -21,16 +21,16 @@ t_cmd *connec_reorient_subtree(t_cmd **list, t_cmd **subtree,
|
|||
*list = cmd_create(FT_CONNECTION);
|
||||
if (!*list)
|
||||
{
|
||||
cmd_destroy(*subtree, true);
|
||||
cmd_destroy(*opt, true);
|
||||
cmd_destroy(*subtree);
|
||||
cmd_destroy(*opt);
|
||||
return (NULL);
|
||||
}
|
||||
(*list)->value.connection = ft_calloc(1, sizeof(t_connec_cmd));
|
||||
if (!(*list)->value.connection)
|
||||
{
|
||||
ft_errno(FT_ENOMEM);
|
||||
cmd_destroy(*subtree, true);
|
||||
cmd_destroy(*opt, true);
|
||||
cmd_destroy(*subtree);
|
||||
cmd_destroy(*opt);
|
||||
return (free(*list), NULL);
|
||||
}
|
||||
(*list)->type = FT_CONNECTION;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 10:46:28 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:11:19 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/28 14:26:10 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -26,19 +26,19 @@ t_cmd *minishell_group_cmd_parse(t_minishell *app, t_wordlist **tokens)
|
|||
subtree = minishell_cmds_parse(app, tokens);
|
||||
if (!subtree || (*tokens) == NULL
|
||||
|| (*tokens)->word->token_type != CLOSE_PARENTH_TOKEN)
|
||||
return (cmd_destroy(subtree, true), ft_errno(FT_EERRNO), NULL);
|
||||
return (cmd_destroy(subtree), ft_errno(FT_EERRNO), NULL);
|
||||
worddesc_destroy(wordlist_pop(tokens));
|
||||
group = cmd_create(FT_GROUP);
|
||||
if (!group)
|
||||
return (cmd_destroy(subtree, true), NULL);
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
group->value.group = ft_calloc(1, sizeof(t_group_cmd));
|
||||
if (!group->value.group)
|
||||
return (cmd_destroy(subtree, true), NULL);
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
group->value.group->cmd = subtree;
|
||||
group->value.group->redirects = minishell_redirect_parse(app, tokens);
|
||||
if (group->value.group->redirects == NULL
|
||||
&& ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(group, true), NULL);
|
||||
return (cmd_destroy(group), NULL);
|
||||
return (group);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 11:35:08 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:10:11 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/18 09:19:12 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ t_cmd *minishell_pipeline_parse(t_minishell *app, t_wordlist **tokens)
|
|||
return (NULL);
|
||||
opt = minishell_optional_pipeline_parse(app, tokens);
|
||||
if (!opt && ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(subtree, true), NULL);
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
if (!opt)
|
||||
return (subtree);
|
||||
while (opt)
|
||||
|
|
@ -36,12 +36,12 @@ t_cmd *minishell_pipeline_parse(t_minishell *app, t_wordlist **tokens)
|
|||
if (connec_reorient_subtree(&pipeline, &subtree, &opt, FT_PIPE) == NULL)
|
||||
{
|
||||
app->last_return_value = 1;
|
||||
return (cmd_destroy(subtree, true),
|
||||
return (cmd_destroy(subtree),
|
||||
ft_perror("minishell_pipeline_parse"), NULL);
|
||||
}
|
||||
opt = minishell_optional_pipeline_parse(app, tokens);
|
||||
}
|
||||
if (ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(subtree, true), NULL);
|
||||
return (cmd_destroy(subtree), NULL);
|
||||
return (pipeline);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/02 14:40:34 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 16:50:52 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/05/02 14:40:34 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ t_redirect *redir_from_words(t_worddesc *operator,
|
|||
here_doc(spec, STDIN_FILENO, app), 0, NULL, WORD_TOKEN);
|
||||
worddesc_destroy(spec);
|
||||
if (redir->redirectee.filename == NULL)
|
||||
return (redirect_destroy(redir, true), NULL);
|
||||
return (redirect_destroy(redir), NULL);
|
||||
}
|
||||
else
|
||||
redir->redirectee.filename = specifier;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 10:13:58 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 16:57:51 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/17 11:45:24 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -34,12 +34,11 @@ t_redirect *minishell_redirect_parse(t_minishell *app, t_wordlist **tokens)
|
|||
else
|
||||
{
|
||||
worddesc_destroy(redir_operator);
|
||||
return (ft_errno(FT_EERRNO), redirect_destroy(redir_list, true),
|
||||
NULL);
|
||||
return (ft_errno(FT_EERRNO), redirect_destroy(redir_list), NULL);
|
||||
}
|
||||
new_redir = redir_from_words(redir_operator, redir_specifier, app);
|
||||
if (new_redir == NULL && ft_errno_get() != FT_ESUCCESS)
|
||||
return (redirect_destroy(redir_list, true), NULL);
|
||||
return (redirect_destroy(redir_list), NULL);
|
||||
t_redirect_add_back(&redir_list, new_redir);
|
||||
}
|
||||
return (redir_list);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* cmdgroup_remove_quotes.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 16:50:43 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 16:50:43 by kcolin ### ########.fr */
|
||||
/* Created: 2025/03/20 17:36:20 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/02 12:53:03 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,10 +33,10 @@ static t_redirect *redirection_remove_quotes(t_redirect *in_list)
|
|||
current->redirectee.filename = result;
|
||||
if (current->redirectee.filename == NULL)
|
||||
{
|
||||
redirect_destroy(in_list, true);
|
||||
redirect_destroy(out_list, true);
|
||||
redirect_destroy(in_list);
|
||||
redirect_destroy(out_list);
|
||||
ft_errno(FT_EERRNO);
|
||||
return (redirect_destroy(current, true), NULL);
|
||||
return (redirect_destroy(current), NULL);
|
||||
}
|
||||
}
|
||||
out_list = t_redirect_add_back(&out_list, current);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* simple_cmd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 16:52:05 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:07:05 by kcolin ### ########.fr */
|
||||
/* Created: 2025/02/21 12:30:07 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/02 12:53:31 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -27,12 +27,12 @@ t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words)
|
|||
return (cmd);
|
||||
}
|
||||
|
||||
void simple_cmd_destroy(t_simple_cmd *cmd, bool delete_file)
|
||||
void simple_cmd_destroy(t_simple_cmd *cmd)
|
||||
{
|
||||
if (cmd == NULL)
|
||||
return ;
|
||||
wordlist_destroy(cmd->words);
|
||||
redirect_destroy(cmd->redirections, delete_file);
|
||||
redirect_destroy(cmd->redirections);
|
||||
free(cmd);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 12:24:57 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:11:01 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/10 15:33:10 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
# include "../../minishell.h"
|
||||
|
||||
t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words);
|
||||
void simple_cmd_destroy(t_simple_cmd *cmd, bool delete_file);
|
||||
void simple_cmd_destroy(t_simple_cmd *cmd);
|
||||
void simple_cmd_debug(t_simple_cmd *cmd, t_buffer *leader,
|
||||
bool is_last);
|
||||
void simple_cmd_root_debug(t_simple_cmd *cmd);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/15 10:38:47 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 17:11:41 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/28 14:30:35 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -41,19 +41,19 @@ t_cmd *minishell_simple_cmd_parse(t_minishell *app, t_wordlist **tokens)
|
|||
redir = minishell_redirect_parse(app, tokens);
|
||||
t_redirect_add_back(&simple->value.simple->redirections, redir);
|
||||
if (ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(simple, true), NULL);
|
||||
return (cmd_destroy(simple), NULL);
|
||||
while ((*tokens) && (*tokens)->word->token_type == WORD_TOKEN)
|
||||
{
|
||||
simple->value.simple->words = wordlist_push(simple->value.simple->words,
|
||||
wordlist_pop(tokens));
|
||||
if (!simple->value.simple->words)
|
||||
return (ft_errno(FT_EERRNO), cmd_destroy(simple, true), NULL);
|
||||
return (ft_errno(FT_EERRNO), cmd_destroy(simple), NULL);
|
||||
redir = minishell_redirect_parse(app, tokens);
|
||||
if (redir == NULL && ft_errno_get() != FT_ESUCCESS)
|
||||
return (cmd_destroy(simple, true), NULL);
|
||||
return (cmd_destroy(simple), NULL);
|
||||
t_redirect_add_back(&simple->value.simple->redirections, redir);
|
||||
}
|
||||
if (!simple->value.simple->words && !simple->value.simple->redirections)
|
||||
return (cmd_destroy(simple, true), ft_errno(FT_EERRNO), NULL);
|
||||
return (cmd_destroy(simple), ft_errno(FT_EERRNO), NULL);
|
||||
return (simple);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/01 13:34:51 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 16:52:25 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/28 14:38:29 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -36,9 +36,9 @@ static t_redirect *redirection_var_expansion(t_redirect *in_list,
|
|||
if (current->redirectee.filename == NULL
|
||||
&& ft_errno_get() != FT_ESUCCESS)
|
||||
{
|
||||
redirect_destroy(in_list, true);
|
||||
redirect_destroy(out_list, true);
|
||||
return (redirect_destroy(current, true), NULL);
|
||||
redirect_destroy(in_list);
|
||||
redirect_destroy(out_list);
|
||||
return (redirect_destroy(current), NULL);
|
||||
}
|
||||
}
|
||||
out_list = t_redirect_add_back(&out_list, current);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* expand_wildcard.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 16:51:47 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 16:52:34 by kcolin ### ########.fr */
|
||||
/* Created: 2025/04/03 19:28:28 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/02 13:00:43 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -30,13 +30,13 @@ static t_redirect *redirect_expand_wildcard_one(t_redirect *current)
|
|||
if (expansion_result != NULL)
|
||||
{
|
||||
ambiguous_redirect(current->unexpanded_filename);
|
||||
redirect_destroy(current, true);
|
||||
redirect_destroy(current);
|
||||
wordlist_destroy(expansion_result);
|
||||
return (ft_errno(FT_EERRNO), NULL);
|
||||
}
|
||||
}
|
||||
else if (expansion_result == NULL && ft_errno_get() != FT_ESUCCESS)
|
||||
return (redirect_destroy(current, true), NULL);
|
||||
return (redirect_destroy(current), NULL);
|
||||
return (current);
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +55,8 @@ static t_redirect *redirect_expand_wildcards(t_redirect *in_list)
|
|||
if (redirect_expand_wildcard_one(current) == NULL
|
||||
&& ft_errno_get() != FT_ESUCCESS)
|
||||
{
|
||||
redirect_destroy(in_list, true);
|
||||
redirect_destroy(out_list, true);
|
||||
redirect_destroy(in_list);
|
||||
redirect_destroy(out_list);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/04/21 11:54:16 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 16:51:36 by kcolin ### ########.fr */
|
||||
/* Updated: 2025/04/23 11:19:26 by kcolin ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -20,9 +20,9 @@
|
|||
static void redirect_fieldsplit_cleanup(t_redirect *in_list,
|
||||
t_redirect *out_list, t_redirect *current, t_simple_cmd *cmd)
|
||||
{
|
||||
redirect_destroy(in_list, true);
|
||||
redirect_destroy(out_list, true);
|
||||
redirect_destroy(current, true);
|
||||
redirect_destroy(in_list);
|
||||
redirect_destroy(out_list);
|
||||
redirect_destroy(current);
|
||||
cmd->redirections = NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@
|
|||
/* ::: :::::::: */
|
||||
/* sig_handlers.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/05/06 16:57:25 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/06 16:57:27 by kcolin ### ########.fr */
|
||||
/* Created: 2025/04/17 12:01:39 by kcolin #+# #+# */
|
||||
/* Updated: 2025/05/05 12:03:03 by jguelen ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -70,4 +70,4 @@ void sig_heredoc(int signum, siginfo_t *siginfo, void *context)
|
|||
ft_printf("\n");
|
||||
}
|
||||
g_signum = signum;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue