aboutsummaryrefslogtreecommitdiff
path: root/src/parse_cmd.c
diff options
context:
space:
mode:
authorChristopher Uhlig2025-01-23 18:41:18 +0100
committerChristopher Uhlig2025-01-23 18:41:18 +0100
commit18fb7cb8ae69fc3439266a154aa6b0f947d6805d (patch)
tree2cbdd7ab727d82cb69ea7acc431e2ffcc317e4ff /src/parse_cmd.c
parent202a5a26d1c0411c441cf12be2b22318abc4f3f9 (diff)
downloadminishell-18fb7cb8ae69fc3439266a154aa6b0f947d6805d.tar.gz
minishell-18fb7cb8ae69fc3439266a154aa6b0f947d6805d.zip
a
Diffstat (limited to 'src/parse_cmd.c')
-rw-r--r--src/parse_cmd.c99
1 files changed, 68 insertions, 31 deletions
diff --git a/src/parse_cmd.c b/src/parse_cmd.c
index 02c4bda..a978c99 100644
--- a/src/parse_cmd.c
+++ b/src/parse_cmd.c
@@ -6,7 +6,7 @@
/* By: chuhlig <chuhlig@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/08 15:06:25 by dkaiser #+# #+# */
-/* Updated: 2025/01/22 17:26:14 by dkaiser ### ########.fr */
+/* Updated: 2025/01/23 18:04:50 by chuhlig ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,10 +21,16 @@ t_node *parse_cmd(t_token *tokens, t_env **env)
t_list *create_files;
create_files = NULL;
- redirs = collect_redirs(&tokens, *env, &create_files);
+ printf("parse_cmd\n");
+ print_token_list(tokens);
+ redirs = collect_redirs(&tokens, *env, &create_files);// takes pos next to pipe or first token
+ printf("parse_cmdafter collect redir\n");
+ print_token_list(tokens);// still existing tokenlist
if (redirs == NULL)
return (NULL);
args = collect_args(&tokens, env);
+ printf("parse_cmdafter collect args\n");
+ // print_token_list(tokens);//here it gone
if (args == NULL)
{
free(redirs);
@@ -33,33 +39,64 @@ t_node *parse_cmd(t_token *tokens, t_env **env)
return (new_cmd_node(args, redirs, create_files));
}
-static char **collect_args(t_token **tokens, t_env **env)
-{
- t_token *cur;
- char **result;
- int i;
- t_token *next;
+// static char **collect_args(t_token **tokens, t_env **env)
+// {
+// t_token *cur;
+// char **result;
+// int i;
+// t_token *next;
- cur = *tokens;
- i = 0;
- 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;
- while (cur != NULL && cur->type == STRING_TOKEN)
- {
- next = cur->next;
- if (cur->previous)
- free_token(cur->previous);
- result[i] = format_string(cur->content.string, *env, ft_atoi("0"));
- i++;
- if (cur->next == NULL)
- free_token(cur);
- cur = next;
- }
- result[i] = NULL;
- return (result);
-}
+// cur = *tokens;
+// i = 0;
+// 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;
+// while (cur != NULL && cur->type == STRING_TOKEN)
+// {
+// next = cur->next;
+// if (cur->previous)
+// free_token(cur->previous);
+// result[i] = format_string(cur->content.string, *env, ft_atoi("0"));
+// i++;
+// if (cur->next == NULL)
+// free_token(cur);
+// cur = next;
+// }
+// result[i] = NULL;
+// return (result);
+// }
+
+static char **collect_args(t_token **tokens, t_env **env) {
+ t_token *cur;
+ char **result;
+ int i;
+ t_token *next;
+
+ cur = *tokens;
+ i = 0;
+ 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;
+ while (cur != NULL && cur->type == STRING_TOKEN) {
+ next = cur->next;
+ result[i] = format_string(cur->content.string, *env, ft_atoi("0"));
+ i++;
+ if (cur->previous)
+ cur->previous->next = cur->next;
+ if (cur->next)
+ cur->next->previous = cur->previous;
+ free_token(cur);
+ cur = next;
+ }
+ result[i] = NULL;
+ *tokens = cur; // Update the head of the token list
+ return (result);
+}// need to later the rest of the tokenlist