2026-01-27 00:30:19 +01:00
|
|
|
#include "ast_list.h"
|
2026-01-17 19:11:55 +01:00
|
|
|
|
2026-01-31 15:50:57 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2026-01-15 17:12:06 +01:00
|
|
|
struct ast *ast_create_list(struct list *list)
|
|
|
|
|
{
|
|
|
|
|
struct ast_list *ast_list = malloc(sizeof(struct ast_list));
|
|
|
|
|
if (ast_list == NULL)
|
2026-01-31 15:50:57 +01:00
|
|
|
{
|
|
|
|
|
perror("Error: could not allocate more memory");
|
2026-01-15 17:12:06 +01:00
|
|
|
return NULL;
|
2026-01-31 15:50:57 +01:00
|
|
|
}
|
2026-01-15 17:12:06 +01:00
|
|
|
|
2026-01-15 18:49:42 +01:00
|
|
|
ast_list->children = list;
|
2026-01-15 17:12:06 +01:00
|
|
|
|
2026-01-31 15:50:57 +01:00
|
|
|
struct ast *result = ast_create(AST_LIST, ast_list);
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
free(ast_list);
|
|
|
|
|
|
|
|
|
|
return result;
|
2026-01-15 17:12:06 +01:00
|
|
|
}
|
2026-01-15 15:59:42 +01:00
|
|
|
|
2026-01-15 17:12:06 +01:00
|
|
|
struct ast_list *ast_get_list(struct ast *node)
|
|
|
|
|
{
|
2026-01-31 15:50:57 +01:00
|
|
|
if (node == NULL || node->type != AST_LIST)
|
2026-01-27 00:30:19 +01:00
|
|
|
return NULL;
|
|
|
|
|
return node->data;
|
2026-01-15 17:12:06 +01:00
|
|
|
}
|
2026-01-15 15:59:42 +01:00
|
|
|
|
2026-01-15 18:49:42 +01:00
|
|
|
void ast_free_list(struct ast_list *ast_list)
|
2026-01-15 15:59:42 +01:00
|
|
|
{
|
2026-01-15 18:49:42 +01:00
|
|
|
if (ast_list == NULL)
|
2026-01-15 15:59:42 +01:00
|
|
|
return;
|
|
|
|
|
|
2026-01-17 17:33:22 +01:00
|
|
|
ast_list_deep_destroy(ast_list->children);
|
2026-01-15 18:49:42 +01:00
|
|
|
free(ast_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ast_list_deep_destroy(struct list *l)
|
|
|
|
|
{
|
|
|
|
|
struct list *elt = l;
|
|
|
|
|
struct list *next_elt;
|
|
|
|
|
while (elt != NULL)
|
|
|
|
|
{
|
|
|
|
|
next_elt = elt->next;
|
|
|
|
|
|
2026-01-31 15:50:57 +01:00
|
|
|
struct ast *node = elt->data;
|
2026-01-17 17:33:22 +01:00
|
|
|
ast_free(&node);
|
2026-01-15 18:49:42 +01:00
|
|
|
free(elt);
|
|
|
|
|
elt = next_elt;
|
|
|
|
|
}
|
2026-01-15 15:59:42 +01:00
|
|
|
}
|