aboutsummaryrefslogtreecommitdiff
path: root/src/parse_cmd.c
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-25 15:42:11 +0100
committerDominik Kaiser2025-01-25 15:42:11 +0100
commit21874e1446ccd08f4433870a69dbe1c08f8331a9 (patch)
treee0d92a277fbb353167ff7909a2007f669058b5bc /src/parse_cmd.c
parentb427100b6c0c655f74dc689533a3f36edfeebffc (diff)
downloadminishell-21874e1446ccd08f4433870a69dbe1c08f8331a9.tar.gz
minishell-21874e1446ccd08f4433870a69dbe1c08f8331a9.zip
Make norminette happy
Diffstat (limited to 'src/parse_cmd.c')
-rw-r--r--src/parse_cmd.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/parse_cmd.c b/src/parse_cmd.c
index 5f9e36d..578601c 100644
--- a/src/parse_cmd.c
+++ b/src/parse_cmd.c
@@ -6,13 +6,14 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2025/01/25 11:36:09 by chuhlig ### ########.fr */
+/* Updated: 2025/01/25 15:00:55 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static char **collect_args(t_token **tokens, t_env **env);
+static void setup_vars(t_token **tokens, t_token **cur, int *i);
t_node *parse_cmd(t_token *tokens, t_env **env)
{
@@ -40,22 +41,19 @@ static char **collect_args(t_token **tokens, t_env **env)
int i;
t_token *next;
- cur = *tokens;
- i = 0;
+ setup_vars(tokens, &cur, &i);
while (cur != NULL && ++i)
cur = cur->next;
result = malloc(sizeof(char *) * (i + 1));
if (result == NULL)
return (free_tokens(*tokens), NULL);
- cur = *tokens;
- i = 0;
+ setup_vars(tokens, &cur, &i);
while (cur != NULL && cur->type == STRING_TOKEN)
{
next = cur->next;
if (cur->previous)
free_token2(cur->previous);
- result[i] = format_string(cur->content.string, *env, ft_atoi("0"));
- i++;
+ result[i++] = format_string(cur->content.string, *env, ft_atoi("0"));
if (cur->next == NULL)
free_token2(cur);
cur = next;
@@ -63,3 +61,9 @@ static char **collect_args(t_token **tokens, t_env **env)
result[i] = NULL;
return (result);
}
+
+static void setup_vars(t_token **tokens, t_token **cur, int *i)
+{
+ *cur = *tokens;
+ *i = 0;
+}