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; }