Merge branch 'codegen'
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
#include "../../mem/allocator/mem_allocator.h"
|
||||
#include "../../mem/arena/mem_arena_allocator.h"
|
||||
#include "../../strings/str8/str8.h"
|
||||
#include "../../strings/str8/str8_list.h"
|
||||
#include "../../../containers/dbl_list/dbl_list.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) {
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
if (!dst || !parts) {
|
||||
return CPATH_JOIN_INVALID_ARGS;
|
||||
}
|
||||
@@ -28,12 +28,12 @@ u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) {
|
||||
}
|
||||
|
||||
// Handle first node
|
||||
const DBL_NODE(Str8) *first_node = wapp_dbl_list_get(Str8, parts, 0);
|
||||
const Str8Node *first_node = wapp_str8_list_get(parts, 0);
|
||||
wapp_str8_copy_str8_capped(dst, first_node->item);
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
const DBL_NODE(Str8) *node = first_node;
|
||||
const Str8Node *node = first_node;
|
||||
u64 node_index = 1;
|
||||
bool running = true;
|
||||
while (running && node->next) {
|
||||
@@ -91,7 +91,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
|
||||
goto RETURN_DIRUP;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *parts = wapp_str8_split(&tmp_arena, path, &separator);
|
||||
Str8List *parts = wapp_str8_split(&tmp_arena, path, &separator);
|
||||
if (!parts) {
|
||||
goto RETURN_DIRUP;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
|
||||
wapp_str8_push_back(output, absolute ? PATH_SEP : '.');
|
||||
} else {
|
||||
for (u64 i = 0; i < levels; ++i) {
|
||||
wapp_dbl_list_pop_back(Str8, parts);
|
||||
wapp_str8_list_pop_back(parts);
|
||||
}
|
||||
|
||||
u64 alignment = sizeof(void *) * 2;
|
||||
|
@@ -28,7 +28,7 @@ enum {
|
||||
CPATH_JOIN_INSUFFICIENT_DST_CAPACITY,
|
||||
};
|
||||
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts);
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
|
||||
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "../../../mem/allocator/mem_allocator.h"
|
||||
#include "../../../mem/arena/mem_arena_allocator.h"
|
||||
#include "../../../strings/str8/str8.h"
|
||||
#include "../../../../containers/dbl_list/dbl_list.h"
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../../common/misc/misc_utils.h"
|
||||
#include <stdarg.h>
|
||||
@@ -18,7 +19,7 @@
|
||||
internal inline CMDResult execute_command(Str8RO *cmd, CMDOutHandling out_handling, Str8 *out_buf);
|
||||
internal inline CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str8 *out_buf);
|
||||
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd) {
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd) {
|
||||
if (!cmd) {
|
||||
return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS);
|
||||
}
|
||||
|
@@ -14,7 +14,7 @@ BEGIN_C_LINKAGE
|
||||
|
||||
#define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR})
|
||||
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd);
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd);
|
||||
|
||||
external CMDError get_output_status(FILE *fp, i32 *status_out);
|
||||
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#include "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 <stdarg.h>
|
||||
#include <stddef.h>
|
||||
@@ -302,19 +300,19 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
if (!allocator || !str || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8)));
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = full;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -332,10 +330,10 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str
|
||||
}
|
||||
|
||||
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = before_str;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
|
||||
@@ -346,30 +344,30 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str
|
||||
}
|
||||
|
||||
// Ensure the last part of the string after the delimiter is added to the list
|
||||
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = rest;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
return output;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
if (!allocator || !str || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8)));
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = full;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
wapp_str8_list_push_back(output, node);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -386,10 +384,10 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st
|
||||
}
|
||||
|
||||
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = after_str;
|
||||
wapp_dbl_list_push_front(output, node);
|
||||
wapp_str8_list_push_front(output, node);
|
||||
}
|
||||
|
||||
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
|
||||
@@ -399,17 +397,17 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st
|
||||
}
|
||||
|
||||
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
if (node) {
|
||||
node->item = rest;
|
||||
wapp_dbl_list_push_front(output, node);
|
||||
wapp_str8_list_push_front(output, node);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str8RO *delimiter) {
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) {
|
||||
if (!allocator || !list || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -419,11 +417,11 @@ Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
DBL_NODE(Str8) *node;
|
||||
Str8Node *node;
|
||||
u64 node_index = 0;
|
||||
bool running = true;
|
||||
while (running) {
|
||||
node = wapp_dbl_list_get(Str8, list, node_index);
|
||||
node = wapp_str8_list_get(list, node_index);
|
||||
wapp_str8_concat_capped(output, node->item);
|
||||
if (node_index + 1 < list->node_count) {
|
||||
wapp_str8_concat_capped(output, delimiter);
|
||||
@@ -435,3 +433,17 @@ Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
u64 wapp_str8_list_total_size(const Str8List *list) {
|
||||
if (!list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 output = 0;
|
||||
for (u64 i = 0; i < list->node_count; ++i) {
|
||||
Str8Node *node = wapp_str8_list_get(list, i);
|
||||
output += node->item->size;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#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"
|
||||
@@ -85,15 +84,16 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr);
|
||||
*/
|
||||
#define wapp_str8_split(ALLOCATOR, STR, DELIMITER) wapp_str8_split_with_max(ALLOCATOR, STR, DELIMITER, -1)
|
||||
#define wapp_str8_rsplit(ALLOCATOR, STR, DELIMITER) wapp_str8_rsplit_with_max(ALLOCATOR, STR, DELIMITER, -1)
|
||||
DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits);
|
||||
DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits);
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str8RO *delimiter);
|
||||
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits);
|
||||
Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits);
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter);
|
||||
|
||||
/**
|
||||
* Str8 list utilities
|
||||
*/
|
||||
#define wapp_str8_node_from_cstr(STRING) wapp_dbl_list_node_from_item(Str8, &wapp_str8_lit(STRING))
|
||||
#define wapp_str8_node_from_str8(STRING) wapp_dbl_list_node_from_item(Str8, &(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
|
||||
END_C_LINKAGE
|
||||
|
@@ -1,18 +0,0 @@
|
||||
#include "./str8_list.h"
|
||||
#include "./str8.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../containers/dbl_list/dbl_list.h"
|
||||
|
||||
u64 wapp_str8_list_total_size(const DBL_LIST(Str8) *list) {
|
||||
if (!list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 output = 0;
|
||||
for (u64 i = 0; i < list->node_count; ++i) {
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list, i);
|
||||
output += node->item->size;
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
@@ -1,25 +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"
|
||||
#include "../../../containers/dbl_list/dbl_list.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
typedef struct str8 Str8;
|
||||
|
||||
DBL_LIST_DECL(Str8);
|
||||
|
||||
u64 wapp_str8_list_total_size(const DBL_LIST(Str8) *list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !STR8_LIST_H
|
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user