From 3cd231f031a99cee823f4ab3a8e724abfff35db1 Mon Sep 17 00:00:00 2001 From: Matteo Flebus Date: Sat, 31 Jan 2026 12:53:23 +0100 Subject: [PATCH] fix: build and .sh test file for functions --- src/utils/Makefile.am | 3 ++- src/utils/ast/ast.c | 8 +++++--- src/utils/ast/ast.h | 1 + src/utils/ast/ast_function.c | 2 +- src/utils/ast/ast_function.h | 3 ++- src/utils/ast/ast_loop.h | 2 +- tests/func.sh | 0 7 files changed, 12 insertions(+), 7 deletions(-) mode change 100644 => 100755 tests/func.sh diff --git a/src/utils/Makefile.am b/src/utils/Makefile.am index 085ae1b..17454d2 100644 --- a/src/utils/Makefile.am +++ b/src/utils/Makefile.am @@ -20,7 +20,8 @@ libutils_a_SOURCES = \ ast/ast_loop.c \ args/args.c \ vars/vars.c \ - ast/ast_assignment.c + ast/ast_assignment.c \ + ast/ast_function.c libutils_a_CPPFLAGS = -I$(top_srcdir)/src diff --git a/src/utils/ast/ast.c b/src/utils/ast/ast.c index ee0f031..5f5f65b 100644 --- a/src/utils/ast/ast.c +++ b/src/utils/ast/ast.c @@ -11,7 +11,8 @@ void ast_free(struct ast **node) { if (node == NULL || *node == NULL) { - fprintf(stderr, + fprintf( + stderr, "WARNING: Internal error: failed to free AST node (NULL argument)"); return; } @@ -56,8 +57,9 @@ void ast_free(struct ast **node) break; default: - fprintf(stderr, "WARNING: Internal error: failed to free an AST node (Unknown " - "type)"); + fprintf(stderr, + "WARNING: Internal error: failed to free an AST node (Unknown " + "type)"); return; } diff --git a/src/utils/ast/ast.h b/src/utils/ast/ast.h index 1ba949b..f0023f3 100644 --- a/src/utils/ast/ast.h +++ b/src/utils/ast/ast.h @@ -6,6 +6,7 @@ #include "ast_base.h" #include "ast_command.h" #include "ast_end.h" +#include "ast_function.h" #include "ast_if.h" #include "ast_list.h" #include "ast_loop.h" diff --git a/src/utils/ast/ast_function.c b/src/utils/ast/ast_function.c index edd53e0..b0356c1 100644 --- a/src/utils/ast/ast_function.c +++ b/src/utils/ast/ast_function.c @@ -23,7 +23,7 @@ struct ast *ast_create_function(char *name, struct ast *value) if (!function_data) return NULL; - function_data->name = strdup(name); + function_data->name = name; function_data->value = value; return ast_create(AST_FUNCTION, function_data); diff --git a/src/utils/ast/ast_function.h b/src/utils/ast/ast_function.h index 9294295..a16dc17 100644 --- a/src/utils/ast/ast_function.h +++ b/src/utils/ast/ast_function.h @@ -1,13 +1,14 @@ #ifndef AST_FUNCTION_H #define AST_FUNCTION_H +#include + struct ast_function { char *name; struct ast *value; }; - /** * Checks if the given AST node is an ast_function */ diff --git a/src/utils/ast/ast_loop.h b/src/utils/ast/ast_loop.h index 7c5ba6e..9718db1 100644 --- a/src/utils/ast/ast_loop.h +++ b/src/utils/ast/ast_loop.h @@ -24,7 +24,7 @@ struct ast_loop *ast_get_loop(struct ast *node); /** * Creates a new AST node representing a loop. */ -struct ast *ast_create_loop(struct ast* condition, struct ast* body); +struct ast *ast_create_loop(struct ast *condition, struct ast *body); /* * @brief: frees the given ast_loop and sets the pointer to NULL. diff --git a/tests/func.sh b/tests/func.sh old mode 100644 new mode 100755