Compare commits

...

3 Commits

3 changed files with 41 additions and 7 deletions

View File

@ -4,7 +4,7 @@
#include "list.h" #include "list.h"
list_node * insert_end(list_node* list, void* data) list_node * insert_node(list_node* list, void* data)
{ {
list_node* node = (list_node*)malloc(sizeof(list_node)); list_node* node = (list_node*)malloc(sizeof(list_node));
if (node == NULL) if (node == NULL)
@ -41,8 +41,10 @@ void delete_node(list_node* node)
{ {
if (node == NULL) if (node == NULL)
return; return;
node->previous->next = node->next; if (node->previous != NULL)
node->next->previous = node->previous; node->previous->next = node->next;
if (node->next != NULL)
node->next->previous = node->previous;
free(node); free(node);
} }
@ -53,11 +55,36 @@ void iterate_list(list_node* list, bool forward, int (*iterFunc)(const void*))
list_node * current = list; list_node * current = list;
while (current != NULL) while (current != NULL)
{ {
if (iterFunc(current->data) == 1) list_node* temp_next = current->next;
list_node* temp_previous = current->previous;
// State
int iter_state = iterFunc(current->data);
if (iter_state & DELETE)
delete_node(current);
if (iter_state & BREAK)
break; break;
if (forward)
current = temp_next;
else
current = temp_previous;
}
}
list_node* find_node(list_node* list_start, bool forward, int (*findFunc)(const void*))
{
if (list_start == NULL || findFunc == NULL)
return NULL;
list_node* current = list_start;
while (current != NULL)
{
if (findFunc(current->data) == 1)
return current;
if (forward) if (forward)
current = current->next; current = current->next;
else else
current = current->previous; current = current->previous;
} }
return NULL;
} }

View File

@ -2,6 +2,13 @@
#define NETEX_LIST_H #define NETEX_LIST_H
typedef enum list_iterate_states
{
CONTINUE = 0 << 0,
BREAK = 1 << 0,
DELETE = 1 << 1
}iterate_state;
typedef struct list_node typedef struct list_node
{ {
void* data; void* data;
@ -9,6 +16,7 @@ typedef struct list_node
struct list_node* next; struct list_node* next;
} list_node; } list_node;
void delete_node(list_node* node);
void iterate_list(list_node* list, bool forward, int (*iterFunc)(const void*)); void iterate_list(list_node* list, bool forward, int (*iterFunc)(const void*));
#endif //NETEX_LIST_H #endif //NETEX_LIST_H

View File

@ -18,16 +18,15 @@ int shutdown_logger(const void* data)
logger->app_logger = NULL; logger->app_logger = NULL;
logger->name = NULL; logger->name = NULL;
free(logger); free(logger);
return 0; return DELETE | BREAK;
} }
void shutdown_log(app_logger_info* appLogger) void shutdown_log(app_logger_info* appLogger)
{ {
canLog = false; canLog = false;
iterate_list(appLogger->loggers, true, &shutdown_logger); iterate_list(appLogger->loggers, true, &shutdown_logger);
} }
logger* create_logger(app_logger_info* appLogger, char* name) logger* create_logger(app_logger_info* appLogger, char* name)
{ {
return NULL; return NULL;