norm: fix all easy issues

This commit is contained in:
Khaïs COLIN 2025-04-14 12:52:20 +02:00
parent 1c9653a5a5
commit 7425195350
4 changed files with 33 additions and 50 deletions

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* minishell.c :+: :+: :+: */ /* minishell.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/06 13:44:06 by kcolin #+# #+# */ /* Created: 2025/04/14 12:53/08 by khais #+# #+# */
/* Updated: 2025/04/07 18:07:30 by jguelen ### ########.fr */ /* Updated: 2025/04/14 12:53:08 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "env/env_convert.h" #include "env/env_convert.h"
#include "postprocess/expansion/expand_vars.h" #include "postprocess/expansion/expand_vars.h"
#include "parser/cmd_parsing.h"
/* /*
** Parse shell commands from line. ** Parse shell commands from line.
@ -76,35 +76,20 @@ static void app_init(t_minishell *app, char **envp)
app->env = env_from_envp(envp); app->env = env_from_envp(envp);
} }
t_cmd *minishell_parse(t_minishell *app, char *command_line);
int main(int argc, char *argv[], char **envp) int main(int argc, char *argv[], char **envp)
{ {
char *line; char *line;
t_simple_cmd *cmd; t_simple_cmd *cmd;
t_minishell app; t_minishell app;
(void)argc;
(void)argv;
app_init(&app, envp);
line = "echo coucou";
minishell_parse(&app, line);
return (0);
(void)argc; (void)argc;
(void)argv; (void)argv;
app_init(&app, envp);
line = "echo coucou";
minishell_parse(&app, line);
return (0);
app_init(&app, envp); app_init(&app, envp);
line = get_command(); line = get_command();
while (line != NULL) while (line != NULL)

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* minishell.h :+: :+: :+: */ /* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/28 14:55:31 by khais #+# #+# */ /* Created: 2025/04/14 12:50/31 by khais #+# #+# */
/* Updated: 2025/04/08 19:46:43 by jguelen ### ########.fr */ /* Updated: 2025/04/14 12:50:31 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -128,6 +128,6 @@ void redirect_destroy(t_redirect *redirections);
/* /*
** This function recursively destroys the whole command tree. ** This function recursively destroys the whole command tree.
*/ */
void t_cmd_destroy(t_cmd *cmd); void t_cmd_destroy(t_cmd *cmd);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */ /* Created: 2025/03/31 10:28:28 by jguelen #+# #+# */
/* Updated: 2025/04/14 12:48:26 by khais ### ########.fr */ /* Updated: 2025/04/14 12:57:46 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -88,8 +88,8 @@ static int redir_open_flags_from_type(t_redir_type type)
return (0); return (0);
} }
static t_redirect *redir_from_words(t_worddesc *operator,
static t_redirect *redir_from_words(t_worddesc *operator, t_worddesc *specifier, t_minishell *app) t_worddesc *specifier, t_minishell *app)
{ {
t_redirect *redir; t_redirect *redir;
@ -117,12 +117,12 @@ static t_redirect *redir_from_words(t_worddesc *operator, t_worddesc *specifier,
t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder) t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder)
{ {
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
t_redirect *redir_list; t_redirect *redir_list;
t_worddesc *redir_operator; t_worddesc *redir_operator;
t_worddesc *redir_specifier; t_worddesc *redir_specifier;
t_redirect *new_redir; t_redirect *new_redir;
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
redir_list = NULL; redir_list = NULL;
while (is_redir(builder->tokens->word)) while (is_redir(builder->tokens->word))
{ {
@ -141,11 +141,10 @@ t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder)
*/ */
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder) t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder)
{ {
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
t_cmd *simple; t_cmd *simple;
t_redirect *redir; t_redirect *redir;
t_worddesc *word;
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
simple = ft_calloc(1, sizeof(t_cmd)); simple = ft_calloc(1, sizeof(t_cmd));
if (!simple) if (!simple)
{ {
@ -166,7 +165,7 @@ t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder)
while (builder->tokens && builder->tokens->word->token_type == WORD_TOKEN) while (builder->tokens && builder->tokens->word->token_type == WORD_TOKEN)
{ {
simple->value.simple->words = wordlist_push(simple->value.simple->words, simple->value.simple->words = wordlist_push(simple->value.simple->words,
wordlist_pop(&builder->tokens)); wordlist_pop(&builder->tokens));
if (!simple->value.simple->words) if (!simple->value.simple->words)
return (ft_errno(FT_EERRNO), t_cmd_destroy(simple), NULL); return (ft_errno(FT_EERRNO), t_cmd_destroy(simple), NULL);
redir = minishell_redir_parse(app, builder); redir = minishell_redir_parse(app, builder);
@ -200,10 +199,10 @@ t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_cmd_builder *builder)
*/ */
t_cmd *minishell_group_or_smp_parse(t_minishell *app, t_cmd_builder *builder) t_cmd *minishell_group_or_smp_parse(t_minishell *app, t_cmd_builder *builder)
{ {
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
t_cmd *subtree; t_cmd *subtree;
t_cmd *group; t_cmd *group;
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
if (builder->tokens->word->token_type == OPEN_PARENTH_TOKEN) if (builder->tokens->word->token_type == OPEN_PARENTH_TOKEN)
{ {
worddesc_destroy(wordlist_pop(&builder->tokens)); worddesc_destroy(wordlist_pop(&builder->tokens));
@ -222,7 +221,8 @@ ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
return (ft_errno(FT_ENOMEM), t_cmd_destroy(subtree), NULL); return (ft_errno(FT_ENOMEM), t_cmd_destroy(subtree), NULL);
group->value.group->cmd = subtree; group->value.group->cmd = subtree;
group->value.group->redirects = minishell_redir_parse(app, builder); group->value.group->redirects = minishell_redir_parse(app, builder);
if (group->value.group->redirects == NULL && ft_errno_get() != FT_ESUCCESS) if (group->value.group->redirects == NULL
&& ft_errno_get() != FT_ESUCCESS)
return (t_cmd_destroy(group), NULL); return (t_cmd_destroy(group), NULL);
return (group); return (group);
} }
@ -235,11 +235,10 @@ ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder, t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder,
t_connector *connec) t_connector *connec)
{ {
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
t_worddesc *token; t_worddesc *token;
t_cmd *opt; t_cmd *opt;
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
token = builder->tokens->word; token = builder->tokens->word;
if (token->token_type == OR_TOKEN || token->token_type == AND_TOKEN) if (token->token_type == OR_TOKEN || token->token_type == AND_TOKEN)
{ {
@ -290,8 +289,7 @@ t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder)
t_cmd *opt; t_cmd *opt;
t_cmd *pipeline; t_cmd *pipeline;
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
subtree = minishell_group_or_smp_parse(app, builder); subtree = minishell_group_or_smp_parse(app, builder);
if (!subtree) if (!subtree)
return (NULL); return (NULL);
@ -325,7 +323,7 @@ t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder)
t_cmd *list; t_cmd *list;
t_connector connec; t_connector connec;
ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word); ft_printf("%s() %s\n", __FUNCTION__, builder->tokens->word->word);
subtree = minishell_pipeline_parse(app, builder); subtree = minishell_pipeline_parse(app, builder);
if (!subtree) if (!subtree)
return (NULL); return (NULL);
@ -371,7 +369,7 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line)
return (wordlist_destroy(builder.tokens), NULL); return (wordlist_destroy(builder.tokens), NULL);
} }
if (builder.tokens) if (builder.tokens)
{ {
parse_error(app, builder.tokens->word); parse_error(app, builder.tokens->word);
wordlist_destroy(builder.tokens); wordlist_destroy(builder.tokens);
t_cmd_destroy(root_cmd); t_cmd_destroy(root_cmd);

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* cmd_parsing.h :+: :+: :+: */ /* cmd_parsing.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: jguelen <jguelen@student.42.fr> +#+ +:+ +#+ */ /* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/28 17:49:55 by jguelen #+# #+# */ /* Created: 2025/04/14 12:53/43 by khais #+# #+# */
/* Updated: 2025/04/10 18:51:38 by jguelen ### ########.fr */ /* Updated: 2025/04/14 12:53:43 by khais ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -36,11 +36,11 @@ t_cmd *minishell_parse(t_minishell *app, char *command_line);
t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder); t_cmd *minishell_cmds_parse(t_minishell *app, t_cmd_builder *builder);
t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder); t_cmd *minishell_pipeline_parse(t_minishell *app, t_cmd_builder *builder);
t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder, t_cmd *minishell_opt_cmds_parse(t_minishell *app, t_cmd_builder *builder,
t_connector *connec); t_connector *connec);
t_cmd *minishell_group_or_smp_parse(t_minishell *app, t_cmd *minishell_group_or_smp_parse(t_minishell *app,
t_cmd_builder *builder); t_cmd_builder *builder);
t_cmd *minishell_opt_pipeline_parse(t_minishell *app, t_cmd *minishell_opt_pipeline_parse(t_minishell *app,
t_cmd_builder *builder); t_cmd_builder *builder);
t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder); t_cmd *minishell_simple_parse(t_minishell *app, t_cmd_builder *builder);
t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder); t_redirect *minishell_redir_parse(t_minishell *app, t_cmd_builder *builder);