forked from test34/can_wizard
added function to destroy list
This commit is contained in:
parent
c86191a104
commit
28c7242587
3 changed files with 26 additions and 41 deletions
|
@ -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 <stdlib.h>
|
|
||||||
|
|
||||||
// Header
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void list_push(List** head, void* data) {
|
void list_push(List** head, void* data) {
|
||||||
List* node = malloc(sizeof(List));
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,46 +1,30 @@
|
||||||
#ifndef LIST_H_DEF
|
#ifndef LIST_H_DEF
|
||||||
#define LIST_H_DEF 1
|
#define LIST_H_DEF
|
||||||
|
|
||||||
/*
|
|
||||||
File: list.h
|
|
||||||
Description: Linked list library definition
|
|
||||||
Created: March 21, 2017
|
|
||||||
Author: Matt Mumau
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef struct List {
|
typedef struct List {
|
||||||
void* data;
|
void* data;
|
||||||
struct List* next;
|
struct List* next;
|
||||||
} List;
|
} List;
|
||||||
|
|
||||||
/*
|
// Push data to the end of the list.
|
||||||
Push data to the end of the list.
|
|
||||||
*/
|
|
||||||
void list_push(List** head, void* data);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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
|
#endif
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "hal/twai_types.h"
|
#include "hal/twai_types.h"
|
||||||
#include "inttypes.h"
|
#include "inttypes.h"
|
||||||
|
#include "list.h"
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "freertos/projdefs.h"
|
#include "freertos/projdefs.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
@ -429,6 +430,13 @@ static int cansmartfilter(int argc, char **argv) {
|
||||||
arg_print_errors(stderr, cansmart_args.end, argv[0]);
|
arg_print_errors(stderr, cansmart_args.end, argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
list_destroy(&adv_filters.filters);
|
||||||
|
for (int i = 0; i < cansmart_args.filters->count; i++) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue