Update code generation to create one file for dbl_list

This commit is contained in:
2025-04-19 13:33:09 +01:00
parent 3c32b247c0
commit 63ed2633ea
11 changed files with 105 additions and 70 deletions

View File

@@ -1,8 +1,8 @@
#ifndef STR8_H
#define STR8_H
#include "./str8_list.h"
#include "../../../common/aliases/aliases.h"
#include "../../../containers/dbl_list/dbl_list.h"
#include "../../mem/allocator/mem_allocator.h"
#include <string.h>
#include <stdbool.h>
@@ -91,8 +91,8 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R
/**
* Str8 list utilities
*/
#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.item = &wapp_str8_lit(STRING)})
#define wapp_str8_node_from_str8(STRING) ((Str8Node){.item = &(STRING)})
#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node(&wapp_str8_lit(STRING))
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
u64 wapp_str8_list_total_size(const Str8List *list);
#ifdef __cplusplus

View File

@@ -1,210 +0,0 @@
/**
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
*/
#include "./str8_list.h"
#include "../../../common/aliases/aliases.h"
#include <stddef.h>
internal Str8List str8_node_to_list(Str8Node *node);
Str8Node wapp_str8_list_node(Str8 *item) {
return (Str8Node){.item = item};
}
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
if (index >= list->node_count) {
return NULL;
}
Str8Node *output = NULL;
Str8Node *current = list->first;
for (u64 i = 1; i <= index; ++i) {
current = current->next;
}
output = current;
return output;
}
void wapp_str8_list_push_front(Str8List *list, Str8Node *node) {
if (!list || !node || !(node->item)) {
return;
}
Str8List node_list = str8_node_to_list(node);
if (list->node_count == 0) {
*list = node_list;
return;
}
list->node_count += node_list.node_count;
Str8Node *first = list->first;
if (first) {
first->prev = node_list.last;
}
list->first = node_list.first;
node_list.last->next = first;
}
void wapp_str8_list_push_back(Str8List *list, Str8Node *node) {
if (!list || !node || !(node->item)) {
return;
}
Str8List node_list = str8_node_to_list(node);
if (list->node_count == 0) {
*list = node_list;
return;
}
list->node_count += node_list.node_count;
Str8Node *last = list->last;
if (last) {
last->next = node_list.first;
}
list->last = node_list.last;
node_list.first->prev = last;
}
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) {
if (!list || !node || !(node->item)) {
return;
}
if (index == 0) {
wapp_str8_list_push_front(list, node);
return;
} else if (index == list->node_count) {
wapp_str8_list_push_back(list, node);
return;
}
Str8Node *dst_node = wapp_str8_list_get(list, index);
if (!dst_node) {
return;
}
Str8List node_list = str8_node_to_list(node);
list->node_count += node_list.node_count;
Str8Node *prev = dst_node->prev;
dst_node->prev = node_list.last;
prev->next = node_list.first;
node_list.first->prev = prev;
node_list.last->next = dst_node;
}
Str8Node *wapp_str8_list_pop_front(Str8List *list) {
Str8Node *output = NULL;
if (!list || list->node_count == 0) {
goto RETURN_STR8_LIST_POP_FRONT;
}
output = list->first;
if (list->node_count == 1) {
*list = (Str8List){0};
goto RETURN_STR8_LIST_POP_FRONT;
}
--(list->node_count);
list->first = output->next;
output->prev = output->next = NULL;
RETURN_STR8_LIST_POP_FRONT:
return output;
}
Str8Node *wapp_str8_list_pop_back(Str8List *list) {
Str8Node *output = NULL;
if (!list || list->node_count == 0) {
goto RETURN_STR8_LIST_POP_BACK;
}
output = list->last;
if (list->node_count == 1) {
*list = (Str8List){0};
goto RETURN_STR8_LIST_POP_BACK;
}
--(list->node_count);
list->last = output->prev;
output->prev = output->next = NULL;
RETURN_STR8_LIST_POP_BACK:
return output;
}
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) {
Str8Node *output = NULL;
if (!list) {
goto RETURN_STR8_LIST_REMOVE;
}
if (index == 0) {
output = wapp_str8_list_pop_front(list);
goto RETURN_STR8_LIST_REMOVE;
} else if (index == list->node_count) {
output = wapp_str8_list_pop_back(list);
goto RETURN_STR8_LIST_REMOVE;
}
output = wapp_str8_list_get(list, index);
if (!output) {
goto RETURN_STR8_LIST_REMOVE;
}
output->prev->next = output->next;
output->next->prev = output->prev;
--(list->node_count);
output->prev = output->next = NULL;
RETURN_STR8_LIST_REMOVE:
return output;
}
void wapp_str8_list_empty(Str8List *list) {
if (!list) {
return;
}
u64 count = list->node_count;
for (u64 i = 0; i < count; ++i) {
wapp_str8_list_pop_back(list);
}
}
internal Str8List str8_node_to_list(Str8Node *node) {
Str8List output = {.first = node, .last = node, .node_count = 1};
while (output.first->prev != NULL) {
output.first = output.first->prev;
++(output.node_count);
}
while (output.last->next != NULL) {
output.last = output.last->next;
++(output.node_count);
}
return output;
}

View File

@@ -1,44 +0,0 @@
/**
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
*/
#ifndef STR8_LIST_H
#define STR8_LIST_H
#include "../../../common/aliases/aliases.h"
#ifdef __cplusplus
BEGIN_C_LINKAGE
#endif // !__cplusplus
typedef struct str8 Str8;
typedef struct Str8Node Str8Node;
struct Str8Node {
Str8 *item;
Str8Node *prev;
Str8Node *next;
};
typedef struct Str8List Str8List;
struct Str8List {
Str8Node *first;
Str8Node *last;
u64 node_count;
};
Str8Node wapp_str8_list_node(Str8 *item);
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index);
void wapp_str8_list_push_front(Str8List *list, Str8Node *node);
void wapp_str8_list_push_back(Str8List *list, Str8Node *node);
void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index);
Str8Node *wapp_str8_list_pop_front(Str8List *list);
Str8Node *wapp_str8_list_pop_back(Str8List *list);
Str8Node *wapp_str8_list_remove(Str8List *list, u64 index);
void wapp_str8_list_empty(Str8List *list);
#ifdef __cplusplus
END_C_LINKAGE
#endif // !__cplusplus
#endif // !STR8_LIST_H

View File

@@ -3,7 +3,6 @@
#include "wapp_core.h"
#include "strings/str8/str8.c"
#include "strings/str8/str8_list.c"
#include "os/shell/termcolour/posix/termcolour_posix.c"
#include "os/shell/termcolour/win/termcolour_win.c"
#include "os/shell/termcolour/termcolour.c"
@@ -18,5 +17,6 @@
#include "mem/allocator/mem_allocator.c"
#include "mem/arena/mem_arena.c"
#include "mem/arena/mem_arena_allocator.c"
#include "../containers/wapp_containers.c"
#endif // !WAPP_CORE_C

View File

@@ -2,7 +2,6 @@
#define WAPP_CORE_H
#include "strings/str8/str8.h"
#include "strings/str8/str8_list.h"
#include "os/shell/termcolour/termcolour.h"
#include "os/shell/termcolour/terminal_colours.h"
#include "os/shell/commander/commander.h"
@@ -18,5 +17,6 @@
#include "mem/arena/mem_arena_allocator.h"
#include "mem/arena/mem_arena.h"
#include "../common/wapp_common.h"
#include "../containers/wapp_containers.h"
#endif // !WAPP_CORE_H