From: Dominik Kaiser Date: Sun, 11 Aug 2024 10:27:02 +0000 (+0200) Subject: Remove assigns X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=99e8655aaf9827c7d5248c7f3d0913fcb1377cfb;p=42%2Fminishell.git Remove assigns I found out that there's a difference between shell variables and env variables. We don't have to implement shell variables, so I removed all code that handles them. --- diff --git a/Makefile b/Makefile index d4778bf..827c317 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ HEADERS = -I include -I $(LIB_DIR)/libft VPATH := src SRC := main.c debug_tools.c init.c signal_handling.c repl.c new_token.c \ free_token.c new_node.c free_node.c tokenizer.c parser.c \ - parse_cmd.c collect_assigns.c collect_redirs.c print_ast.c + parse_cmd.c collect_redirs.c print_ast.c OBJ_DIR := _obj OBJ := $(addprefix $(OBJ_DIR)/, $(SRC:%.c=%.o)) diff --git a/include/ast.h b/include/ast.h index bf19083..cd2f9c9 100644 --- a/include/ast.h +++ b/include/ast.h @@ -6,7 +6,7 @@ /* By: dkaiser type == STRING_TOKEN - && !is_quote(cur->content.string[0]) && ft_strchr(cur->content.string, - '=') != NULL) - { - result[i++] = to_assign(cur->content.string); - if (cur->next != NULL) - { - cur = cur->next; - free_token(cur->previous); - } - else - free_token(cur); - } - *tokens = cur; - result[i] = NULL; - return (result); -} - -static t_assign *to_assign(char *str) -{ - t_assign *result; - char *split_pos; - - split_pos = ft_strchr(str, '='); - *split_pos = '\0'; - result = malloc(sizeof(t_assign)); - if (result == NULL) - { - return (NULL); - } - result->var = str; - result->value = split_pos + 1; - return (result); -} - -static int count_tokens(t_token *tokens) -{ - int len; - - len = 0; - while (tokens != NULL && tokens->type == STRING_TOKEN - && !is_quote(tokens->content.string[0]) - && ft_strchr(tokens->content.string, '=') != NULL) - { - len++; - tokens = tokens->next; - } - return (len); -} - -static int is_quote(char c) -{ - return (c == '"' || c == '\''); -} diff --git a/src/free_node.c b/src/free_node.c index f387c0a..6eae059 100644 --- a/src/free_node.c +++ b/src/free_node.c @@ -6,7 +6,7 @@ /* By: dkaiser content.cmd.args); - free_assigns(node->content.cmd.assigns); if (node->content.cmd.redirs[0].type != 0 && node->content.cmd.redirs[0].specifier != NULL) free(node->content.cmd.redirs[0].specifier); @@ -54,19 +52,3 @@ static void free_cmd_node(t_node *node) && node->content.cmd.redirs[0].specifier != NULL) free(node->content.cmd.redirs[1].specifier); } - -static void free_assigns(t_assign **assigns) -{ - int i; - - i = 0; - if (assigns == 0) - return ; - while (assigns[i] != NULL) - { - free(assigns[i]->var); - free(assigns[i]); - i++; - } - free(assigns); -} diff --git a/src/new_node.c b/src/new_node.c index c2458d0..6da9f9e 100644 --- a/src/new_node.c +++ b/src/new_node.c @@ -6,7 +6,7 @@ /* By: dkaiser content.cmd.args = args; - node->content.cmd.assigns = assigns; node->content.cmd.redirs[0] = redirs[0]; node->content.cmd.redirs[1] = redirs[1]; free(redirs); diff --git a/src/parse_cmd.c b/src/parse_cmd.c index eb70f0d..2755cae 100644 --- a/src/parse_cmd.c +++ b/src/parse_cmd.c @@ -6,7 +6,7 @@ /* By: dkaiser content.cmd.args[i]); i++; } - i = 0; - printf("\n%*sASSIGNS:", indent + 2, ""); - while (ast->content.cmd.assigns[i] != NULL) - { - printf(" %s=%s", ast->content.cmd.assigns[i]->var, - ast->content.cmd.assigns[i]->value); - i++; - } printf("\n%*sREDIRS:", indent + 2, ""); printf("\n%*sIN: %d %s", indent + 4, "", ast->content.cmd.redirs[0].type, ast->content.cmd.redirs[0].specifier);