Clang format list (#254)

* Finish clang-format on lists
This commit is contained in:
Rickey
2025-11-25 11:32:50 +02:00
committed by GitHub
parent 6db35b0f95
commit e910aee184
3 changed files with 78 additions and 71 deletions
@@ -20,6 +20,7 @@ jobs:
run: > run: >
clang-format --dry-run -Werror clang-format --dry-run -Werror
include/bitset.h source/bitset.c include/bitset.h source/bitset.c
include/list.h source/list.c
include/sprite.h source/sprite.c include/sprite.h source/sprite.c
include/splash_screen.h source/splash_screen.c include/splash_screen.h source/splash_screen.c
# Currently contains only the code that has been formatted to conform # Currently contains only the code that has been formatted to conform
+33 -27
View File
@@ -1,7 +1,9 @@
#include <stdbool.h>
#include "list.h" #include "list.h"
#include "pool.h" #include "pool.h"
#include <stdbool.h>
/** /**
* Remove a node from a list. * Remove a node from a list.
* *
@@ -12,7 +14,7 @@
* @param list pointer to a @ref List * @param list pointer to a @ref List
* @param node pointer to a @ref ListNode * @param node pointer to a @ref ListNode
*/ */
static void _list_remove_node(List *list, ListNode *node); static void s_list_remove_node(List* list, ListNode* node);
/** /**
* Get the next @ref ListNode in a @ref ListItr * Get the next @ref ListNode in a @ref ListItr
@@ -25,8 +27,7 @@ static void _list_remove_node(List *list, ListNode *node);
* *
* @return A pointer to the @ref ListNode in the itr, otherwise return NULL. * @return A pointer to the @ref ListNode in the itr, otherwise return NULL.
*/ */
static ListNode* _list_itr_node_next(ListItr* itr); static ListNode* s_list_itr_node_next(ListItr* itr);
List list_create(void) List list_create(void)
{ {
@@ -36,12 +37,13 @@ List list_create(void)
void list_clear(List* list) void list_clear(List* list)
{ {
if(list_is_empty(list)) return; if (list_is_empty(list))
return;
ListItr itr = list_itr_create(list); ListItr itr = list_itr_create(list);
ListNode* ln; ListNode* ln;
while((ln = _list_itr_node_next(&itr))) while ((ln = s_list_itr_node_next(&itr)))
{ {
POOL_FREE(ListNode, ln); POOL_FREE(ListNode, ln);
} }
@@ -121,7 +123,7 @@ void list_insert(List* list, void* data, unsigned int idx)
ListItr itr = list_itr_create(list); ListItr itr = list_itr_create(list);
ListNode* ln; ListNode* ln;
while((ln = _list_itr_node_next(&itr))) while ((ln = s_list_itr_node_next(&itr)))
{ {
if (idx == curr_idx++) if (idx == curr_idx++)
{ {
@@ -139,8 +141,10 @@ void list_insert(List* list, void* data, unsigned int idx)
bool list_swap(List* list, unsigned int idx_a, unsigned int idx_b) bool list_swap(List* list, unsigned int idx_a, unsigned int idx_b)
{ {
if(idx_a >= list->len || idx_b >= list->len) return false; if (idx_a >= list->len || idx_b >= list->len)
if(idx_a == idx_b) return true; // swapping with yourself isn't technically an error return false;
if (idx_a == idx_b)
return true; // swapping with yourself isn't technically an error
unsigned int curr_idx = 0; unsigned int curr_idx = 0;
unsigned int max_idx = idx_a > idx_b ? idx_a : idx_b; unsigned int max_idx = idx_a > idx_b ? idx_a : idx_b;
@@ -152,7 +156,7 @@ bool list_swap(List* list, unsigned int idx_a, unsigned int idx_b)
do do
{ {
ln = _list_itr_node_next(&itr); ln = s_list_itr_node_next(&itr);
if (idx_a == curr_idx) if (idx_a == curr_idx)
{ {
node_a = ln; node_a = ln;
@@ -163,8 +167,7 @@ bool list_swap(List* list, unsigned int idx_a, unsigned int idx_b)
node_b = ln; node_b = ln;
continue; continue;
} }
} } while (max_idx != curr_idx++);
while(max_idx != curr_idx++);
// Just swap the data pointers // Just swap the data pointers
void* tmp = node_a->data; void* tmp = node_a->data;
@@ -174,7 +177,7 @@ bool list_swap(List* list, unsigned int idx_a, unsigned int idx_b)
return true; return true;
} }
static void _list_remove_node(List *list, ListNode *node) static void s_list_remove_node(List* list, ListNode* node)
{ {
if (node->prev && !node->next) // end of list if (node->prev && !node->next) // end of list
{ {
@@ -209,7 +212,8 @@ int list_get_len(const List* list)
void* list_get_at_idx(List* list, unsigned int idx) void* list_get_at_idx(List* list, unsigned int idx)
{ {
if(idx >= list_get_len(list)) return NULL; if (idx >= list_get_len(list))
return NULL;
int curr_idx = 0; int curr_idx = 0;
ListItr itr = list_itr_create(list); ListItr itr = list_itr_create(list);
@@ -217,7 +221,8 @@ void* list_get_at_idx(List* list, unsigned int idx)
while ((data = list_itr_next(&itr))) while ((data = list_itr_next(&itr)))
{ {
if (idx == curr_idx++) return data; if (idx == curr_idx++)
return data;
} }
return NULL; return NULL;
@@ -225,17 +230,18 @@ void* list_get_at_idx(List* list, unsigned int idx)
bool list_remove_at_idx(List* list, unsigned int idx) bool list_remove_at_idx(List* list, unsigned int idx)
{ {
if(idx >= list_get_len(list)) return false; if (idx >= list_get_len(list))
return false;
int len = 0; int len = 0;
ListItr itr = list_itr_create(list); ListItr itr = list_itr_create(list);
ListNode* ln; ListNode* ln;
while((ln = _list_itr_node_next(&itr))) while ((ln = s_list_itr_node_next(&itr)))
{ {
if (idx == len++) if (idx == len++)
{ {
_list_remove_node(list, ln); s_list_remove_node(list, ln);
return true; return true;
} }
} }
@@ -244,8 +250,7 @@ bool list_remove_at_idx(List* list, unsigned int idx)
ListItr list_itr_create(List* list) ListItr list_itr_create(List* list)
{ {
ListItr itr = ListItr itr = {
{
.list = list, .list = list,
.next_node = !list_is_empty(list) ? list->head : NULL, .next_node = !list_is_empty(list) ? list->head : NULL,
.current_node = NULL, .current_node = NULL,
@@ -257,8 +262,7 @@ ListItr list_itr_create(List* list)
ListItr rev_list_itr_create(List* list) ListItr rev_list_itr_create(List* list)
{ {
ListItr itr = ListItr itr = {
{
.list = list, .list = list,
.next_node = !list_is_empty(list) ? list->tail : NULL, .next_node = !list_is_empty(list) ? list->tail : NULL,
.current_node = NULL, .current_node = NULL,
@@ -270,13 +274,14 @@ ListItr rev_list_itr_create(List* list)
void* list_itr_next(ListItr* itr) void* list_itr_next(ListItr* itr)
{ {
ListNode* ln = _list_itr_node_next(itr); ListNode* ln = s_list_itr_node_next(itr);
return ln ? ln->data : NULL; return ln ? ln->data : NULL;
} }
static ListNode* _list_itr_node_next(ListItr* itr) static ListNode* s_list_itr_node_next(ListItr* itr)
{ {
if(!itr->next_node) return NULL; if (!itr->next_node)
return NULL;
itr->current_node = itr->next_node; itr->current_node = itr->next_node;
@@ -295,8 +300,9 @@ static ListNode* _list_itr_node_next(ListItr* itr)
void list_itr_remove_current_node(ListItr* itr) void list_itr_remove_current_node(ListItr* itr)
{ {
if(!itr || !itr->current_node) return; if (!itr || !itr->current_node)
return;
ListNode* tmp_prev = itr->current_node->prev; ListNode* tmp_prev = itr->current_node->prev;
_list_remove_node(itr->list, itr->current_node); s_list_remove_node(itr->list, itr->current_node);
itr->current_node = tmp_prev; itr->current_node = tmp_prev;
} }