From 28c7242587c4a34daeb0d45d29a5e875e1e95678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=BB=D0=B0=20=D0=93=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D1=83=D1=88=D0=BA=D0=BE?= Date: Wed, 29 Nov 2023 12:01:20 +0300 Subject: [PATCH] added function to destroy list --- components/C-Linked-List/list.c | 23 ++++++++------------- components/C-Linked-List/list.h | 36 +++++++++------------------------ main/cmd_can.c | 8 ++++++++ 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/components/C-Linked-List/list.c b/components/C-Linked-List/list.c index c04e328..e83b30f 100644 --- a/components/C-Linked-List/list.c +++ b/components/C-Linked-List/list.c @@ -1,18 +1,5 @@ -#ifndef LIST_DEF -#define LIST_DEF 1 - -/* - File: list.c - Description: Implementation of linked list object functionality. - Created: March 21, 2017 - Author: Matt Mumau - */ - -// System dependencies -#include - -// Header #include "list.h" +#include void list_push(List** head, void* data) { List* node = malloc(sizeof(List)); @@ -108,4 +95,10 @@ void list_remove(List** head, unsigned int index) { } } -#endif +void list_destroy(List** head) { + while (*head != NULL) { + List* tmp_cursor = *head; + *head = (*head)->next; + free(tmp_cursor); + } +} diff --git a/components/C-Linked-List/list.h b/components/C-Linked-List/list.h index a340eaa..4108fba 100644 --- a/components/C-Linked-List/list.h +++ b/components/C-Linked-List/list.h @@ -1,46 +1,30 @@ #ifndef LIST_H_DEF -#define LIST_H_DEF 1 - -/* - File: list.h - Description: Linked list library definition - Created: March 21, 2017 - Author: Matt Mumau - */ +#define LIST_H_DEF typedef struct List { void* data; struct List* next; } List; -/* - Push data to the end of the list. - */ +// Push data to the end of the list. void list_push(List** head, void* data); -/* - Remove the final element of the list and return its data. - */ +// Remove the final element of the list and return its data. void* list_pop(List** head); -/* - Insert the data object to the beginning of the list. - */ +// Insert the data object to the beginning of the list. void list_insert(List** head, void* data); -/* - Get the size of the list. - */ +// Get the size of the list. unsigned int list_sizeof(List* head); -/* - Get the data of the node at the given ordinal number in the list. - */ +// Get the data of the node at the given ordinal number in the list. List* list_get(List* head, unsigned int index); -/* - Delete the item in the list at the given ordinal location (1 is the first). - */ +// Delete the item in the list at the given ordinal location (1 is the first). void list_remove(List** head, unsigned int index); +// Remove all element of the list and set the given ptr to NULL +void list_destroy(List** head); + #endif diff --git a/main/cmd_can.c b/main/cmd_can.c index 9aa2f3e..94c8106 100644 --- a/main/cmd_can.c +++ b/main/cmd_can.c @@ -4,6 +4,7 @@ #include "esp_log.h" #include "hal/twai_types.h" #include "inttypes.h" +#include "list.h" #include "sdkconfig.h" #include "freertos/projdefs.h" #include "string.h" @@ -429,6 +430,13 @@ static int cansmartfilter(int argc, char **argv) { arg_print_errors(stderr, cansmart_args.end, argv[0]); return 1; } + list_destroy(&adv_filters.filters); + for (int i = 0; i < cansmart_args.filters->count; i++) { + + } + + + return 0; }