Start str8 renaming

This commit is contained in:
2026-06-26 16:02:12 +01:00
parent cd797683d2
commit acbfc9088c
34 changed files with 729 additions and 729 deletions
+11 -11
View File
@@ -11,7 +11,7 @@
#include <stdio.h>
#include <string.h>
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
u32 wapp_cpath_join_path(WpStr8 *dst, const WpStr8List *parts) {
if (!dst || !parts) {
return CPATH_JOIN_INVALID_ARGS;
}
@@ -20,7 +20,7 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
return CPATH_JOIN_EMPTY_PARTS;
}
Str8 separator = wapp_str8_buf(4);
WpStr8 separator = wapp_str8_buf(4);
wapp_str8_push_back(&separator, WAPP_PATH_SEP);
u64 required_capacity = parts->node_count * separator.size + wapp_str8_list_total_size(parts);
@@ -29,16 +29,16 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
}
// Handle first node
Str8 *first_node = wapp_dbl_list_get(Str8, parts, 0);
WpStr8 *first_node = wapp_dbl_list_get(WpStr8, parts, 0);
wapp_str8_copy_str8_capped(dst, first_node);
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings
Str8 *node = first_node;
WpStr8 *node = first_node;
u64 node_index = 1;
b8 running = node_index < parts->node_count;
while (running) {
node = wapp_dbl_list_get(Str8, parts, node_index);
node = wapp_dbl_list_get(WpStr8, parts, node_index);
if (node->size == 0) {
goto CPATH_JOIN_LOOP_END;
}
@@ -63,14 +63,14 @@ CPATH_JOIN_LOOP_END:
return CPATH_JOIN_SUCCESS;
}
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
Str8 *output = NULL;
WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels) {
WpStr8 *output = NULL;
if (!allocator || !path) {
goto RETURN_DIRUP;
}
b8 absolute = wapp_str8_get(path, 0) == WAPP_PATH_SEP;
Str8 separator = wapp_str8_buf(4);
WpStr8 separator = wapp_str8_buf(4);
wapp_str8_push_back(&separator, WAPP_PATH_SEP);
if (path->size == 0) {
@@ -93,7 +93,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
goto RETURN_DIRUP;
}
Str8List *parts = wapp_str8_split(&tmp_arena, path, &separator);
WpStr8List *parts = wapp_str8_split(&tmp_arena, path, &separator);
if (!parts) {
goto RETURN_DIRUP;
}
@@ -107,7 +107,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
wapp_str8_push_back(output, absolute ? WAPP_PATH_SEP : '.');
} else {
for (u64 i = 0; i < levels; ++i) {
wapp_dbl_list_pop_back(Str8, parts);
wapp_dbl_list_pop_back(WpStr8, parts);
}
u64 alignment = sizeof(void *) * 2;
@@ -121,7 +121,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
wapp_str8_push_back(output, WAPP_PATH_SEP);
}
Str8 *joined = wapp_str8_join(&tmp_arena, parts, &separator);
WpStr8 *joined = wapp_str8_join(&tmp_arena, parts, &separator);
if (joined) {
wapp_str8_concat_capped(output, joined);
}
+2 -2
View File
@@ -35,8 +35,8 @@ enum {
CPATH_JOIN_INSUFFICIENT_DST_CAPACITY,
};
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
u32 wapp_cpath_join_path(WpStr8 *dst, const WpStr8List *parts);
WpStr8 *dirup(const Allocator *allocator, WpStr8RO *path, u64 levels);
#ifdef WP_PLATFORM_CPP
END_C_LINKAGE
+5 -5
View File
@@ -7,7 +7,7 @@
#include "../../base/array/array.h"
#include "../../base/strings/str8/str8.h"
WFile *wapp_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode) {
WFile *wapp_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
wpDebugAssert(allocator != NULL && filepath != NULL, "`allocator` and `filepath` should not be NULL");
wpDebugAssert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
return _file_open(allocator, filepath, mode);
@@ -56,12 +56,12 @@ i64 wapp_file_write(const void *src_buf, WFile *file, u64 byte_count) {
return _file_write(src_buf, file, byte_count);
}
u64 wapp_file_read_str8(Str8 *str, WFile *file) {
u64 wapp_file_read_str8(WpStr8 *str, WFile *file) {
wpDebugAssert(str != NULL, "`str` should not be NULL.");
return wapp_file_read((void *)(str->buf), file, str->size);
}
i64 wapp_file_write_str8(Str8RO *str, WFile *file) {
i64 wapp_file_write_str8(WpStr8RO *str, WFile *file) {
wpDebugAssert(str != NULL, "`str` should not be NULL.");
return wapp_file_write((void *)(str->buf), file, str->size);
}
@@ -124,7 +124,7 @@ i32 wapp_file_close(WFile *file) {
return _file_close(file);
}
i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath) {
i32 wapp_file_rename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
wpDebugAssert(old_filepath != NULL && new_filepath != NULL,
"`old_filepath` and `new_filepath` should not be NULL");
wpDebugAssert(old_filepath->size < WAPP_PATH_MAX, "`old_filepath` exceeds max path limit.");
@@ -132,7 +132,7 @@ i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath) {
return _file_rename(old_filepath, new_filepath);
}
i32 wapp_file_remove(Str8RO *filepath) {
i32 wapp_file_remove(WpStr8RO *filepath) {
wpDebugAssert(filepath != NULL, "`filepath` should not be NULL");
wpDebugAssert(filepath->size < WAPP_PATH_MAX, "`filepath` exceeds max path limit.");
return _file_remove(filepath);
+8 -8
View File
@@ -46,29 +46,29 @@ wp_extern WFile *wapp_file_stdout(void);
// wapp_file_stderr to get the standard error stream
wp_extern WFile *wapp_file_stderr(void);
WFile *wapp_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode);
WFile *wapp_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode);
i64 wapp_file_get_current_position(WFile *file);
i64 wapp_file_seek(WFile *file, i64 offset, FileSeekOrigin origin);
i64 wapp_file_get_length(WFile *file);
u64 wapp_file_read(void *dst_buf, WFile *file, u64 byte_count);
i64 wapp_file_write(const void *src_buf, WFile *file, u64 byte_count);
u64 wapp_file_read_str8(Str8 *str, WFile *file);
i64 wapp_file_write_str8(Str8RO *str, WFile *file);
u64 wapp_file_read_str8(WpStr8 *str, WFile *file);
i64 wapp_file_write_str8(WpStr8RO *str, WFile *file);
u64 wapp_file_read_array(GenericArray dst_buf, WFile *file, u64 item_count);
i64 wapp_file_write_array(const GenericArray src_buf, WFile *file, u64 item_count);
i32 wapp_file_flush(WFile *file);
i32 wapp_file_close(WFile *file);
i32 wapp_file_rename(Str8RO *old_filepath, Str8RO *new_filepath);
i32 wapp_file_remove(Str8RO *filepath);
i32 wapp_file_rename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
i32 wapp_file_remove(WpStr8RO *filepath);
wp_extern WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode);
wp_extern WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode);
wp_extern i64 _file_seek(WFile *file, i64 offset, FileSeekOrigin origin);
wp_extern u64 _file_read(void *dst_buf, u64 byte_count, WFile *file, u64 file_length);
wp_extern i64 _file_write(const void *src_buf, WFile *file, u64 byte_count);
wp_extern i32 _file_flush(WFile *file);
wp_extern i32 _file_close(WFile *file);
wp_extern i32 _file_rename(Str8RO *old_filepath, Str8RO *new_filepath);
wp_extern i32 _file_remove(Str8RO *filepath);
wp_extern i32 _file_rename(WpStr8RO *old_filepath, WpStr8RO *new_filepath);
wp_extern i32 _file_remove(WpStr8RO *filepath);
#ifdef WP_PLATFORM_CPP
END_C_LINKAGE
+3 -3
View File
@@ -64,7 +64,7 @@ WFile *wapp_file_stderr(void) {
return &_stderr;
}
WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode) {
WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
wp_persist c8 tmp[WAPP_PATH_MAX] = {0};
memset(tmp, 0, WAPP_PATH_MAX);
memcpy(tmp, filepath->buf, filepath->size);
@@ -107,7 +107,7 @@ i32 _file_close(WFile *file) {
return close(file->fd);
}
i32 _file_rename(Str8RO *old_filepath, Str8RO *new_filepath) {
i32 _file_rename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
wp_persist c8 old_tmp[WAPP_PATH_MAX] = {0};
wp_persist c8 new_tmp[WAPP_PATH_MAX] = {0};
memset(old_tmp, 0, WAPP_PATH_MAX);
@@ -123,7 +123,7 @@ i32 _file_rename(Str8RO *old_filepath, Str8RO *new_filepath) {
return link_result;
}
i32 _file_remove(Str8RO *filepath) {
i32 _file_remove(WpStr8RO *filepath) {
wp_persist c8 tmp[WAPP_PATH_MAX] = {0};
memset(tmp, 0, WAPP_PATH_MAX);
memcpy(tmp, filepath->buf, filepath->size);
+3 -3
View File
@@ -72,7 +72,7 @@ WFile *wapp_file_stderr(void) {
return &_stderr;
}
WFile *_file_open(const Allocator *allocator, Str8RO *filepath, FileAccessMode mode) {
WFile *_file_open(const Allocator *allocator, WpStr8RO *filepath, FileAccessMode mode) {
wp_persist c8 tmp[WAPP_PATH_MAX] = {0};
memset(tmp, 0, WAPP_PATH_MAX);
memcpy(tmp, filepath->buf, filepath->size);
@@ -147,7 +147,7 @@ i32 _file_close(WFile *file) {
return 0;
}
i32 _file_rename(Str8RO *old_filepath, Str8RO *new_filepath) {
i32 _file_rename(WpStr8RO *old_filepath, WpStr8RO *new_filepath) {
wp_persist c8 old_tmp[WAPP_PATH_MAX] = {0};
wp_persist c8 new_tmp[WAPP_PATH_MAX] = {0};
memset(old_tmp, 0, WAPP_PATH_MAX);
@@ -162,7 +162,7 @@ i32 _file_rename(Str8RO *old_filepath, Str8RO *new_filepath) {
return 0;
}
i32 _file_remove(Str8RO *filepath) {
i32 _file_remove(WpStr8RO *filepath) {
wp_persist c8 tmp[WAPP_PATH_MAX] = {0};
memset(tmp, 0, WAPP_PATH_MAX);
memcpy(tmp, filepath->buf, filepath->size);
+8 -8
View File
@@ -17,17 +17,17 @@
#define CMD_BUF_LEN 8192
#define OUT_BUF_LEN 4096
wp_intern CMDResult execute_command(Str8RO *cmd, CMDOutHandling out_handling, Str8 *out_buf);
wp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str8 *out_buf);
wp_intern CMDResult execute_command(WpStr8RO *cmd, CMDOutHandling out_handling, WpStr8 *out_buf);
wp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, WpStr8 *out_buf);
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd) {
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, WpStr8 *out_buf, const WpStr8List *cmd) {
if (!cmd) {
return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS);
}
Allocator arena = wapp_mem_arena_allocator_init(KiB(500));
Str8 *cmd_str = wapp_str8_join(&arena, cmd, &wapp_str8_lit_ro(" "));
WpStr8 *cmd_str = wapp_str8_join(&arena, cmd, &wapp_str8_lit_ro(" "));
if (!cmd_str) {
wapp_mem_arena_allocator_destroy(&arena);
return CMD_NO_EXIT(SHELL_ERR_ALLOCATION_FAIL);
@@ -43,7 +43,7 @@ CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_bu
return output;
}
wp_intern CMDResult execute_command(Str8RO *cmd, CMDOutHandling out_handling, Str8 *out_buf) {
wp_intern CMDResult execute_command(WpStr8RO *cmd, CMDOutHandling out_handling, WpStr8 *out_buf) {
char cmd_buf[CMD_BUF_LEN] = {0};
wapp_str8_copy_to_cstr(cmd_buf, cmd, CMD_BUF_LEN);
@@ -83,8 +83,8 @@ EXECUTE_COMMAND_CLOSE:
return output;
}
wp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str8 *out_buf) {
Str8 out = wapp_str8_buf(OUT_BUF_LEN);
wp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, WpStr8 *out_buf) {
WpStr8 out = wapp_str8_buf(OUT_BUF_LEN);
out.size = fread((void *)out.buf, sizeof(c8), out.capacity, fp);
if (out_handling == SHELL_OUTPUT_CAPTURE && out_buf != NULL) {
@@ -94,7 +94,7 @@ wp_intern CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str
wapp_str8_concat_capped(out_buf, &out);
} else if (out_handling == SHELL_OUTPUT_PRINT) {
printf(WAPP_STR8_SPEC, wapp_str8_varg(out));
printf(WP_STR8_SPEC, wpStr8Varg(out));
}
return SHELL_ERR_NO_ERROR;
+1 -1
View File
@@ -18,7 +18,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 Str8List *cmd);
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, WpStr8 *out_buf, const WpStr8List *cmd);
wp_extern CMDError get_output_status(FILE *fp, i32 *status_out);
@@ -9,7 +9,7 @@
#include "../terminal_colours.h"
#include <stdio.h>
wp_intern Str8RO colours[COUNT_TERM_COLOUR] = {
wp_intern WpStr8RO colours[COUNT_TERM_COLOUR] = {
[WAPP_TERM_COLOUR_FG_BLACK] = wapp_str8_lit_ro_initialiser_list("\033[30m"),
[WAPP_TERM_COLOUR_FG_RED] = wapp_str8_lit_ro_initialiser_list("\033[31m"),
[WAPP_TERM_COLOUR_FG_GREEN] = wapp_str8_lit_ro_initialiser_list("\033[32m"),
@@ -29,8 +29,8 @@ wp_intern Str8RO colours[COUNT_TERM_COLOUR] = {
[WAPP_TERM_COLOUR_CLEAR] = wapp_str8_lit_ro_initialiser_list("\033[0m"),
};
void print_coloured_text(Str8RO *text, TerminalColour colour) {
printf(WAPP_STR8_SPEC WAPP_STR8_SPEC, wapp_str8_varg(colours[colour]), wapp_str8_varg((*text)));
void print_coloured_text(WpStr8RO *text, TerminalColour colour) {
printf(WP_STR8_SPEC WP_STR8_SPEC, wpStr8Varg(colours[colour]), wpStr8Varg((*text)));
}
#endif // !WP_PLATFORM_POSIX
+2 -2
View File
@@ -4,7 +4,7 @@
#include "terminal_colours.h"
#include "../../../base/strings/str8/str8.h"
void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour) {
void wapp_shell_termcolour_print_text(WpStr8RO *text, TerminalColour colour) {
if (colour < WAPP_TERM_COLOUR_FG_BLACK || colour > WAPP_TERM_COLOUR_FG_BR_WHITE) {
return;
}
@@ -13,6 +13,6 @@ void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour) {
}
void wapp_shell_termcolour_clear_colour(void) {
Str8RO empty = wapp_str8_lit_ro("");
WpStr8RO empty = wapp_str8_lit_ro("");
print_coloured_text(&empty, WAPP_TERM_COLOUR_CLEAR);
}
+2 -2
View File
@@ -14,10 +14,10 @@ BEGIN_C_LINKAGE
// TODO (Abdelrahman): Look into moving away from stdio in the implementation
void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour);
void wapp_shell_termcolour_print_text(WpStr8RO *text, TerminalColour colour);
void wapp_shell_termcolour_clear_colour(void);
wp_extern void print_coloured_text(Str8RO *text, TerminalColour colour);
wp_extern void print_coloured_text(WpStr8RO *text, TerminalColour colour);
#ifdef WP_PLATFORM_CPP
END_C_LINKAGE
+2 -2
View File
@@ -43,7 +43,7 @@ wp_intern WORD colours[COUNT_TERM_COLOUR] = {
[WAPP_TERM_COLOUR_FG_BR_WHITE] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,
};
void print_coloured_text(Str8RO *text, TerminalColour colour) {
void print_coloured_text(WpStr8RO *text, TerminalColour colour) {
wp_persist TermcolourData data = {0};
if (data.handle == 0) {
init_data(&data);
@@ -56,7 +56,7 @@ void print_coloured_text(Str8RO *text, TerminalColour colour) {
}
SetConsoleTextAttribute(data.handle, data.current_colour);
printf(WAPP_STR8_SPEC, wapp_str8_varg((*text)));
printf(WP_STR8_SPEC, wpStr8Varg((*text)));
}
wp_intern void init_data(TermcolourData *data) {