Compare commits
20 Commits
b9ea290322
...
generic
Author | SHA1 | Date | |
---|---|---|---|
|
31373eba03 | ||
|
778a4da092 | ||
|
6fb078a868 | ||
0942643b4e | |||
|
0e5942af34 | ||
|
c83c652b37 | ||
|
74428f1caf | ||
|
d661312cfa | ||
70e075d2f6 | |||
96db885344 | |||
fb512e4a15 | |||
9361f0fe37 | |||
e7d2553400 | |||
509724cc31 | |||
|
82c23eed5e | ||
|
9403193f09 | ||
|
fa1d9eec0d | ||
|
4c14588d92 | ||
|
9e66bd60bd | ||
|
ce4957d0a0 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -10,3 +10,4 @@ compile_commands.json
|
||||
libwapp-build
|
||||
libwapp.so
|
||||
*.vs
|
||||
__pycache__
|
||||
|
63
Makefile
Normal file
63
Makefile
Normal file
@@ -0,0 +1,63 @@
|
||||
CC = clang
|
||||
BUILD_TYPE = debug
|
||||
CFLAGS = -Wall -Wextra -Werror -pedantic
|
||||
LIBFLAGS = -fPIC -shared
|
||||
KERNEL = $(shell uname -s)
|
||||
MACHINE = $(shell uname -m)
|
||||
PLATFORM = $(KERNEL)_$(MACHINE)
|
||||
TEST_INCLUDE = -Isrc $(shell find tests -type d | xargs -I{} echo -n "-I{} ")
|
||||
TEST_SRC = src/wapp.c $(shell find tests -type f -name "*.c" | xargs -I{} echo -n "{} ")
|
||||
BUILD_DIR = libwapp-build/$(PLATFORM)-$(BUILD_TYPE)
|
||||
LIB_OUT = $(BUILD_DIR)/libwapp.so
|
||||
TEST_OUT = $(BUILD_DIR)/wapptest
|
||||
|
||||
ifeq ($(BUILD_TYPE),debug)
|
||||
CFLAGS += -g -fsanitize=address,undefined
|
||||
else ifeq ($(BUILD_TYPE),release)
|
||||
CFLAGS += -O3
|
||||
else
|
||||
$(error Invalid BUILD type '$(BUILD_TYPE)'. Use 'debug' or 'release')
|
||||
endif
|
||||
|
||||
ifeq ($(CC),gcc)
|
||||
# Used to disable the "ASan runtime does not come first in initial library list" error when compiling with gcc
|
||||
export ASAN_OPTIONS=verify_asan_link_order=0
|
||||
endif
|
||||
|
||||
.PHONY: all clean builddir build-test run-test build-lib full prng testing uuid core containers
|
||||
|
||||
all: clean builddir run-test full
|
||||
|
||||
clean:
|
||||
@rm -rf $(BUILD_DIR)
|
||||
|
||||
builddir:
|
||||
@mkdir -p $(BUILD_DIR)
|
||||
|
||||
build-test:
|
||||
$(CC) $(CFLAGS) $(TEST_INCLUDE) $(TEST_SRC) -o $(TEST_OUT)
|
||||
|
||||
run-test: build-test
|
||||
@$(TEST_OUT)
|
||||
@rm $(TEST_OUT)
|
||||
|
||||
build-lib:
|
||||
$(CC) $(CFLAGS) $(LIBFLAGS) $(LIB_SRC) -o $(LIB_OUT)
|
||||
|
||||
full: LIB_SRC = src/wapp.c
|
||||
full: build-lib
|
||||
|
||||
prng: LIB_SRC = src/prng/wapp_prng.c
|
||||
prng: build-lib
|
||||
|
||||
testing: LIB_SRC = src/testing/wapp_testing.c
|
||||
testing: build-lib
|
||||
|
||||
uuid: LIB_SRC = src/uuid/wapp_uuid.c
|
||||
uuid: build-lib
|
||||
|
||||
core: LIB_SRC = src/core/wapp_core.c
|
||||
core: build-lib
|
||||
|
||||
containers: LIB_SRC = src/core/wapp_containers.c
|
||||
containers: build-lib
|
19
build
19
build
@@ -1,3 +1,20 @@
|
||||
#!/bin/bash
|
||||
|
||||
bear -- ./compile $@
|
||||
BUILD_TYPE="debug"
|
||||
ARGS=""
|
||||
|
||||
while [[ $# > 0 ]];do
|
||||
case $1 in
|
||||
--release)
|
||||
BUILD_TYPE="release"
|
||||
shift
|
||||
;;
|
||||
*|-*|--*)
|
||||
rest=("$@")
|
||||
ARGS+=" ${rest[0]}"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
bear -- make BUILD_TYPE=$BUILD_TYPE $ARGS
|
||||
|
@@ -11,7 +11,7 @@ $Kernel = (Get-ChildItem Env:OS).Value
|
||||
$Machine = (Get-ChildItem Env:PROCESSOR_ARCHITECTURE).Value
|
||||
$Platform = "${Kernel}_${Machine}"
|
||||
|
||||
$IncludeDirs = Get-ChildItem -Path src -Recurse -Directory -ErrorAction SilentlyContinue -Force | %{$("/I " + '"' + $_.FullName + '"')}
|
||||
$IncludeDirs = "/I src"
|
||||
$SrcFiles = "src/wapp.c"
|
||||
|
||||
$TestIncludeDirs = Get-ChildItem -Path tests -Recurse -Directory -ErrorAction SilentlyContinue -Force | %{$("/I " + '"' + $_.FullName + '"')}
|
||||
@@ -45,6 +45,9 @@ mkdir -p $ObjDir > $null
|
||||
mkdir -p $OutDir > $null
|
||||
mkdir -p $TestsDir > $null
|
||||
|
||||
# Run code generation
|
||||
Invoke-Expression "python3 -m codegen"
|
||||
|
||||
# Build and run tests
|
||||
Invoke-Expression "$Compiler $GeneralFlags $IncludeDirs $TestIncludeDirs $SrcFiles $TestSrcFiles $TestOutputs" -ErrorAction Stop
|
||||
|
||||
@@ -59,4 +62,4 @@ If ($Status -ne 0) {
|
||||
}
|
||||
|
||||
# Build library
|
||||
Invoke-Expression "$Compiler $GeneralFlags $LibraryFlags $IncludeDirs $SrcFiles $Objects $Outputs"
|
||||
Invoke-Expression "$Compiler $GeneralFlags $LibraryFlags $SrcFiles $Objects $Outputs"
|
||||
|
102
compile
102
compile
@@ -1,102 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
BUILD_TYPE="debug"
|
||||
COMPONENTS="all"
|
||||
|
||||
function join_array {
|
||||
DELIM="$1"
|
||||
shift
|
||||
local IFS="$DELIM"
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
SUPPORTED_COMPONENTS=("all" "testing" "core")
|
||||
COMPONENTS_STRING="$(join_array "|" ${SUPPORTED_COMPONENTS[@]})"
|
||||
|
||||
while [[ $# > 0 ]];do
|
||||
case $1 in
|
||||
--release)
|
||||
BUILD_TYPE="release"
|
||||
shift
|
||||
;;
|
||||
--components)
|
||||
COMPONENTS="$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
*|-*|--*)
|
||||
echo "Unknown option $1"
|
||||
echo "Usage: $0 [--release] [--components $COMPONENTS_STRING (Default: all)]"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
CC=clang
|
||||
CFLAGS="-Wall -Wextra -Werror -pedantic"
|
||||
LIBFLAGS="-fPIC -shared"
|
||||
KERNEL="$(uname -s)"
|
||||
MACHINE="$(uname -m)"
|
||||
PLATFORM="${KERNEL}_${MACHINE}"
|
||||
|
||||
if [[ $CC == "gcc" ]]; then
|
||||
# Used to disable the "ASan runtime does not come first in initial library list" error when compiling with gcc
|
||||
export ASAN_OPTIONS=verify_asan_link_order=0
|
||||
fi
|
||||
|
||||
INCLUDE="$(find src -type d | xargs -I{} echo -n "-I{} ")"
|
||||
|
||||
case $COMPONENTS in
|
||||
all)
|
||||
SRC="src/wapp.c"
|
||||
;;
|
||||
testing)
|
||||
SRC="src/testing/wapp_testing.c"
|
||||
;;
|
||||
core)
|
||||
SRC="src/core/wapp_core.c"
|
||||
;;
|
||||
*)
|
||||
echo "Unrecognised option for components: $COMPONENTS"
|
||||
echo "Accepted options: $COMPONENTS_STRING"
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
|
||||
TEST_INCLUDE="$(find tests -type d | xargs -I{} echo -n "-I{} ")"
|
||||
TEST_SRC="$(find tests -type f -name "*.c" | xargs -I{} echo -n "{} ")"
|
||||
|
||||
BUILD_DIR="libwapp-build/$PLATFORM-$BUILD_TYPE"
|
||||
if [[ -d $BUILD_DIR ]]; then
|
||||
rm -rf $BUILD_DIR
|
||||
fi
|
||||
mkdir -p $BUILD_DIR
|
||||
|
||||
if [[ $BUILD_TYPE == "release" ]]; then
|
||||
CFLAGS+=" -O3"
|
||||
else
|
||||
CFLAGS+=" -g -fsanitize=address,undefined"
|
||||
fi
|
||||
|
||||
OUT="$BUILD_DIR/libwapp.so"
|
||||
TEST_OUT="$BUILD_DIR/wapptest"
|
||||
|
||||
# Compile tests
|
||||
if [[ $(echo $TEST_SRC | xargs) != "" ]]; then
|
||||
(set -x ; $CC $CFLAGS $INCLUDE $TEST_INCLUDE $SRC $TEST_SRC -o $TEST_OUT)
|
||||
fi
|
||||
|
||||
# Run tests and exit on failure
|
||||
if [[ -f $TEST_OUT ]]; then
|
||||
$TEST_OUT
|
||||
STATUS="$?"
|
||||
|
||||
rm $TEST_OUT
|
||||
|
||||
if [[ $STATUS != "0" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Compile library
|
||||
(set -x ; $CC $CFLAGS $LIBFLAGS $INCLUDE $SRC -o $OUT)
|
@@ -1,7 +1,7 @@
|
||||
#ifndef MISC_UTILS_H
|
||||
#define MISC_UTILS_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "../aliases/aliases.h"
|
||||
|
||||
#define KB(SIZE) (SIZE * 1024ull)
|
||||
#define MB(SIZE) (KB(SIZE) * 1024)
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef WAPP_COMMON_H
|
||||
#define WAPP_COMMON_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "misc_utils.h"
|
||||
#include "platform.h"
|
||||
#include "aliases/aliases.h"
|
||||
#include "misc/misc_utils.h"
|
||||
#include "platform/platform.h"
|
||||
|
||||
#endif // !WAPP_COMMON_H
|
||||
|
209
src/containers/dbl_list/dbl_list.c
Normal file
209
src/containers/dbl_list/dbl_list.c
Normal file
@@ -0,0 +1,209 @@
|
||||
#include "./dbl_list.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include <stddef.h>
|
||||
|
||||
internal DBL_LIST(void) node_to_list(DBL_NODE(void) *node);
|
||||
|
||||
DBL_NODE(void) *_dbl_list_get(const DBL_LIST(void) *list, u64 index) {
|
||||
if (index >= list->node_count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBL_NODE(void) *output = NULL;
|
||||
DBL_NODE(void) *current = list->first;
|
||||
for (u64 i = 1; i <= index; ++i) {
|
||||
current = current->next;
|
||||
}
|
||||
|
||||
output = current;
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
void _dbl_list_push_front(DBL_LIST(void) *list, DBL_NODE(void) *node) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DBL_LIST(void) node_list = node_to_list(node);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
return;
|
||||
}
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
DBL_NODE(void) *first = list->first;
|
||||
if (first) {
|
||||
first->prev = node_list.last;
|
||||
}
|
||||
|
||||
list->first = node_list.first;
|
||||
node_list.last->next = first;
|
||||
|
||||
}
|
||||
|
||||
void _dbl_list_push_back(DBL_LIST(void) *list, DBL_NODE(void) *node) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DBL_LIST(void) node_list = node_to_list(node);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
return;
|
||||
}
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
DBL_NODE(void) *last = list->last;
|
||||
if (last) {
|
||||
last->next = node_list.first;
|
||||
}
|
||||
|
||||
list->last = node_list.last;
|
||||
node_list.first->prev = last;
|
||||
|
||||
}
|
||||
|
||||
void _dbl_list_insert(DBL_LIST(void) *list, DBL_NODE(void) *node, u64 index) {
|
||||
if (!list || !node || !(node->item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
_dbl_list_push_front(list, node);
|
||||
return;
|
||||
} else if (index == list->node_count) {
|
||||
_dbl_list_push_back(list, node);
|
||||
return;
|
||||
}
|
||||
|
||||
DBL_NODE(void) *dst_node = _dbl_list_get(list, index);
|
||||
if (!dst_node) {
|
||||
return;
|
||||
}
|
||||
|
||||
DBL_LIST(void) node_list = node_to_list(node);
|
||||
|
||||
list->node_count += node_list.node_count;
|
||||
|
||||
DBL_NODE(void) *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;
|
||||
|
||||
}
|
||||
|
||||
DBL_NODE(void) *_dbl_list_pop_front(DBL_LIST(void) *list) {
|
||||
DBL_NODE(void) *output = NULL;
|
||||
|
||||
if (!list || list->node_count == 0) {
|
||||
goto RETURN_STR8_LIST_POP_FRONT;
|
||||
}
|
||||
|
||||
output = list->first;
|
||||
|
||||
if (list->node_count == 1) {
|
||||
*list = (DBL_LIST(void)){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;
|
||||
|
||||
}
|
||||
|
||||
DBL_NODE(void) *_dbl_list_pop_back(DBL_LIST(void) *list) {
|
||||
DBL_NODE(void) *output = NULL;
|
||||
|
||||
if (!list || list->node_count == 0) {
|
||||
goto RETURN_STR8_LIST_POP_BACK;
|
||||
}
|
||||
|
||||
output = list->last;
|
||||
|
||||
if (list->node_count == 1) {
|
||||
*list = (DBL_LIST(void)){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;
|
||||
|
||||
}
|
||||
|
||||
DBL_NODE(void) *_dbl_list_remove(DBL_LIST(void) *list, u64 index) {
|
||||
DBL_NODE(void) *output = NULL;
|
||||
if (!list) {
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
|
||||
if (index == 0) {
|
||||
output = _dbl_list_pop_front(list);
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
} else if (index == list->node_count) {
|
||||
output = _dbl_list_pop_back(list);
|
||||
goto RETURN_STR8_LIST_REMOVE;
|
||||
}
|
||||
|
||||
output = _dbl_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 _dbl_list_empty(DBL_LIST(void) *list) {
|
||||
if (!list) {
|
||||
return;
|
||||
}
|
||||
|
||||
u64 count = list->node_count;
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
_dbl_list_pop_back(list);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal DBL_LIST(void) node_to_list(DBL_NODE(void) *node) {
|
||||
DBL_LIST(void) 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;
|
||||
}
|
75
src/containers/dbl_list/dbl_list.h
Normal file
75
src/containers/dbl_list/dbl_list.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef DBL_LIST_H
|
||||
#define DBL_LIST_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
#define DBL_NODE(T) T##Node
|
||||
#define DBL_LIST(T) T##List
|
||||
|
||||
#define CAST_NODE(NODE) ((DBL_NODE(void))(NODE))
|
||||
#define CAST_LIST(LIST) ((DBL_LIST(void))(LIST))
|
||||
|
||||
#define CAST_NODE_PTR(NODE_PTR) ((DBL_NODE(void)*)(NODE_PTR))
|
||||
#define CAST_LIST_PTR(LIST_PTR) ((DBL_LIST(void)*)(LIST_PTR))
|
||||
|
||||
#define DBL_LIST_DECL(T) typedef struct DBL_NODE(T) DBL_NODE(T); \
|
||||
struct DBL_NODE(T) { \
|
||||
T *item; \
|
||||
DBL_NODE(T) *prev; \
|
||||
DBL_NODE(T) *next; \
|
||||
}; \
|
||||
\
|
||||
typedef struct DBL_LIST(T) DBL_LIST(T); \
|
||||
struct DBL_LIST(T) { \
|
||||
DBL_NODE(T) *first; \
|
||||
DBL_NODE(T) *last; \
|
||||
u64 node_count; \
|
||||
}
|
||||
|
||||
DBL_LIST_DECL(void);
|
||||
|
||||
#define wapp_dbl_list_node_from_item(T, ITEM_PTR) \
|
||||
((DBL_NODE(T)){ .item = ITEM_PTR })
|
||||
|
||||
#define wapp_dbl_list_get(T, LIST_PTR, INDEX) \
|
||||
(DBL_NODE(T)*)_dbl_list_get(CAST_LIST_PTR(LIST_PTR), INDEX)
|
||||
|
||||
#define wapp_dbl_list_push_front(LIST_PTR, NODE_PTR) \
|
||||
_dbl_list_push_front(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR))
|
||||
|
||||
#define wapp_dbl_list_push_back(LIST_PTR, NODE_PTR) \
|
||||
_dbl_list_push_back(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR))
|
||||
|
||||
#define wapp_dbl_list_insert(LIST_PTR, NODE_PTR, INDEX) \
|
||||
_dbl_list_insert(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR), INDEX)
|
||||
|
||||
#define wapp_dbl_list_pop_front(T, LIST_PTR) \
|
||||
(DBL_NODE(T)*)_dbl_list_pop_front(CAST_LIST_PTR(LIST_PTR))
|
||||
|
||||
#define wapp_dbl_list_pop_back(T, LIST_PTR) \
|
||||
(DBL_NODE(T)*)_dbl_list_pop_back(CAST_LIST_PTR(LIST_PTR))
|
||||
|
||||
#define wapp_dbl_list_remove(T, LIST_PTR, INDEX) \
|
||||
(DBL_NODE(T)*)_dbl_list_remove(CAST_LIST_PTR(LIST_PTR), INDEX)
|
||||
|
||||
#define wapp_dbl_list_empty(LIST_PTR) \
|
||||
_dbl_list_empty(CAST_LIST_PTR(LIST_PTR))
|
||||
|
||||
DBL_NODE(void) *_dbl_list_get(const DBL_LIST(void) *list, u64 index);
|
||||
void _dbl_list_push_front(DBL_LIST(void) *list, DBL_NODE(void) *node);
|
||||
void _dbl_list_push_back(DBL_LIST(void) *list, DBL_NODE(void) *node);
|
||||
void _dbl_list_insert(DBL_LIST(void) *list, DBL_NODE(void) *node, u64 index);
|
||||
DBL_NODE(void) *_dbl_list_pop_front(DBL_LIST(void) *list);
|
||||
DBL_NODE(void) *_dbl_list_pop_back(DBL_LIST(void) *list);
|
||||
DBL_NODE(void) *_dbl_list_remove(DBL_LIST(void) *list, u64 index);
|
||||
void _dbl_list_empty(DBL_LIST(void) *list);
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
#endif // !__cplusplus
|
||||
|
||||
#endif // !DBL_LIST_H
|
6
src/containers/wapp_containers.c
Normal file
6
src/containers/wapp_containers.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef WAPP_CONTAINERS_C
|
||||
#define WAPP_CONTAINERS_C
|
||||
|
||||
#include "dbl_list/dbl_list.c"
|
||||
|
||||
#endif // !WAPP_CONTAINERS_C
|
7
src/containers/wapp_containers.h
Normal file
7
src/containers/wapp_containers.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef WAPP_CONTAINERS_H
|
||||
#define WAPP_CONTAINERS_H
|
||||
|
||||
#include "dbl_list/dbl_list.h"
|
||||
#include "../common/wapp_common.h"
|
||||
|
||||
#endif // !WAPP_CONTAINERS_H
|
@@ -1,4 +1,5 @@
|
||||
#include "mem_allocator.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void *wapp_mem_allocator_alloc(const Allocator *allocator, u64 size) {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef MEM_ALLOCATOR_H
|
||||
#define MEM_ALLOCATOR_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "mem_arena.h"
|
||||
#include "aliases.h"
|
||||
#include "misc_utils.h"
|
||||
#include "mem_os.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
#include "../../os/mem/mem_os.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef MEM_ARENA_H
|
||||
#define MEM_ARENA_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "mem_os.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../os/mem/mem_os.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -1,5 +1,7 @@
|
||||
#include "mem_arena_allocator.h"
|
||||
#include "mem_arena.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../os/mem/mem_os.h"
|
||||
|
||||
internal inline void *mem_arena_alloc(u64 size, void *alloc_obj);
|
||||
internal inline void *mem_arena_alloc_aligned(u64 size, u64 alignment, void *alloc_obj);
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#ifndef MEM_ARENA_ALLOCATOR_H
|
||||
#define MEM_ARENA_ALLOCATOR_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "mem_os.h"
|
||||
#include "mem_allocator.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../allocator/mem_allocator.h"
|
||||
#include "../../os/mem/mem_os.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -1,5 +1,5 @@
|
||||
#include "aliases.h"
|
||||
#include "mem_utils.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef MEM_UTILS_H
|
||||
#define MEM_UTILS_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,15 +1,16 @@
|
||||
#include "cpath.h"
|
||||
#include "aliases.h"
|
||||
#include "mem_allocator.h"
|
||||
#include "mem_arena_allocator.h"
|
||||
#include "misc_utils.h"
|
||||
#include "str8.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/misc/misc_utils.h"
|
||||
#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 <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) {
|
||||
if (!dst || !parts) {
|
||||
return CPATH_JOIN_INVALID_ARGS;
|
||||
}
|
||||
@@ -21,29 +22,29 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
Str8 separator = wapp_str8_buf(4);
|
||||
wapp_str8_push_back(&separator, PATH_SEP);
|
||||
|
||||
u64 required_capacity = parts->node_count * separator.size + parts->total_size;
|
||||
u64 required_capacity = parts->node_count * separator.size + wapp_str8_list_total_size(parts);
|
||||
if (dst->capacity < required_capacity) {
|
||||
return CPATH_JOIN_INSUFFICIENT_DST_CAPACITY;
|
||||
}
|
||||
|
||||
// Handle first node
|
||||
const Str8Node *first_node = wapp_str8_list_get(parts, 0);
|
||||
wapp_str8_copy_str8_capped(dst, first_node->string);
|
||||
const DBL_NODE(Str8) *first_node = wapp_dbl_list_get(Str8, 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 Str8Node *node = first_node;
|
||||
const DBL_NODE(Str8) *node = first_node;
|
||||
u64 node_index = 1;
|
||||
bool running = true;
|
||||
while (running && node->next) {
|
||||
node = node->next;
|
||||
if (node->string->size == 0) {
|
||||
if (node->item->size == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dst->size > 0) {
|
||||
char dst_last = wapp_str8_get(dst, dst->size - 1);
|
||||
char node_start = wapp_str8_get(node->string, 0);
|
||||
char node_start = wapp_str8_get(node->item, 0);
|
||||
bool add_path_sep = dst_last != PATH_SEP && node_start != PATH_SEP;
|
||||
|
||||
if (add_path_sep) {
|
||||
@@ -51,7 +52,7 @@ u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
|
||||
}
|
||||
}
|
||||
|
||||
wapp_str8_concat_capped(dst, node->string);
|
||||
wapp_str8_concat_capped(dst, node->item);
|
||||
|
||||
++node_index;
|
||||
running = node_index < parts->node_count;
|
||||
@@ -90,7 +91,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
|
||||
goto RETURN_DIRUP;
|
||||
}
|
||||
|
||||
Str8List *parts = wapp_str8_split(&tmp_arena, path, &separator);
|
||||
DBL_LIST(Str8) *parts = wapp_str8_split(&tmp_arena, path, &separator);
|
||||
if (!parts) {
|
||||
goto RETURN_DIRUP;
|
||||
}
|
||||
@@ -104,11 +105,11 @@ 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_str8_list_pop_back(parts);
|
||||
wapp_dbl_list_pop_back(Str8, parts);
|
||||
}
|
||||
|
||||
u64 alignment = sizeof(void *) * 2;
|
||||
u64 alloc_size = parts->total_size + parts->node_count * separator.size;
|
||||
u64 alloc_size = wapp_str8_list_total_size(parts) + parts->node_count * separator.size;
|
||||
u64 modulo = alloc_size & (alignment - 1);
|
||||
alloc_size += alignment - modulo;
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#ifndef CPATH_H
|
||||
#define CPATH_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "mem_allocator.h"
|
||||
#include "platform.h"
|
||||
#include "str8.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/platform/platform.h"
|
||||
#include "../../mem/allocator/mem_allocator.h"
|
||||
#include "../../strings/str8/str8.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
@@ -28,7 +28,7 @@ enum {
|
||||
CPATH_JOIN_INSUFFICIENT_DST_CAPACITY,
|
||||
};
|
||||
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
|
||||
u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts);
|
||||
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -1,15 +1,15 @@
|
||||
#include "mem_os.h"
|
||||
#include "mem_os_ops.h"
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/platform/platform.h"
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(WAPP_PLATFORM_WINDOWS)
|
||||
#include "mem_os_win.h"
|
||||
#include "win/mem_os_win.h"
|
||||
#elif defined(WAPP_PLATFORM_POSIX)
|
||||
#include "mem_os_posix.h"
|
||||
#include "posix/mem_os_posix.h"
|
||||
#else
|
||||
#error "Unrecognised platform"
|
||||
#endif
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef MEM_OS_H
|
||||
#define MEM_OS_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "../../../common/aliases/aliases.h"
|
||||
#include "../../../common/platform/platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
@@ -11,9 +11,9 @@ BEGIN_C_LINKAGE
|
||||
#include "mem_os_ops.h"
|
||||
|
||||
#if defined(WAPP_PLATFORM_WINDOWS)
|
||||
#include "mem_os_win.h"
|
||||
#include "win/mem_os_win.h"
|
||||
#elif defined(WAPP_PLATFORM_POSIX)
|
||||
#include "mem_os_posix.h"
|
||||
#include "posix/mem_os_posix.h"
|
||||
#else
|
||||
#error "Unrecognised platform"
|
||||
#endif
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_POSIX
|
||||
|
||||
#include "mem_os_ops.h"
|
||||
#include "mem_os_posix.h"
|
||||
#include "../mem_os_ops.h"
|
||||
#include <sys/mman.h>
|
||||
|
||||
internal const i32 access_types[] = {
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef MEM_OS_POSIX_H
|
||||
#define MEM_OS_POSIX_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
|
||||
#include "mem_os_ops.h"
|
||||
#include "mem_os_win.h"
|
||||
#include "../mem_os_ops.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef MEM_OS_WIN_H
|
||||
#define MEM_OS_WIN_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#include "commander.h"
|
||||
#include "aliases.h"
|
||||
#include "commander_output.h"
|
||||
#include "mem_allocator.h"
|
||||
#include "mem_arena_allocator.h"
|
||||
#include "misc_utils.h"
|
||||
#include "shell_utils.h"
|
||||
#include "str8.h"
|
||||
#include "../utils/shell_utils.h"
|
||||
#include "../../../mem/allocator/mem_allocator.h"
|
||||
#include "../../../mem/arena/mem_arena_allocator.h"
|
||||
#include "../../../strings/str8/str8.h"
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../../common/misc/misc_utils.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@@ -18,7 +18,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 Str8List *cmd) {
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd) {
|
||||
if (!cmd) {
|
||||
return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS);
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#ifndef COMMANDER_H
|
||||
#define COMMANDER_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "commander_output.h"
|
||||
#include "str8.h"
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../strings/str8/str8.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -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 Str8List *cmd);
|
||||
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd);
|
||||
|
||||
external CMDError get_output_status(FILE *fp, i32 *status_out);
|
||||
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef COMMANDER_OUTPUT_H
|
||||
#define COMMANDER_OUTPUT_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../../common/platform/platform.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "../../../../../common/aliases/aliases.h"
|
||||
#include "../../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_POSIX
|
||||
|
||||
#include "commander_output.h"
|
||||
#include "shell_utils.h"
|
||||
#include "../commander_output.h"
|
||||
#include "../../utils/shell_utils.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "../../../../../common/aliases/aliases.h"
|
||||
#include "../../../../../common/platform/platform.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
|
||||
#include "commander_output.h"
|
||||
#include "shell_utils.h"
|
||||
#include "../commander_output.h"
|
||||
#include "../../utils/shell_utils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
CMDError get_output_status(FILE *fp, i32 *status_out) {
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "str8.h"
|
||||
#include "../../../../../common/aliases/aliases.h"
|
||||
#include "../../../../../common/platform/platform.h"
|
||||
#include "../../../../strings/str8/str8.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_POSIX
|
||||
|
||||
#include "terminal_colours.h"
|
||||
#include "../terminal_colours.h"
|
||||
#include <stdio.h>
|
||||
|
||||
internal Str8RO colours[COUNT_TERM_COLOUR] = {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "termcolour.h"
|
||||
#include "terminal_colours.h"
|
||||
#include "../../../strings/str8/str8.h"
|
||||
|
||||
void wapp_shell_termcolour_print_text(Str8RO *text, TerminalColour colour) {
|
||||
if (colour < WAPP_TERM_COLOUR_FG_BLACK || colour > WAPP_TERM_COLOUR_FG_BR_WHITE) {
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#ifndef TERM_COLOUR_H
|
||||
#define TERM_COLOUR_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "terminal_colours.h"
|
||||
#include "str8.h"
|
||||
#include "../../../../common/aliases/aliases.h"
|
||||
#include "../../../strings/str8/str8.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,11 +1,11 @@
|
||||
#include "aliases.h"
|
||||
#include "platform.h"
|
||||
#include "str8.h"
|
||||
#include "../../../../../common/aliases/aliases.h"
|
||||
#include "../../../../../common/platform/platform.h"
|
||||
#include "../../../../strings/str8/str8.h"
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
|
||||
#include "misc_utils.h"
|
||||
#include "terminal_colours.h"
|
||||
#include "../terminal_colours.h"
|
||||
#include "../../../../../common/misc/misc_utils.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef SHELL_UTILS_H
|
||||
#define SHELL_UTILS_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "../../../../common/platform/platform.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef WAPP_PLATFORM_WINDOWS
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#include "str8.h"
|
||||
#include "aliases.h"
|
||||
#include "mem_allocator.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>
|
||||
#include <stdio.h>
|
||||
@@ -9,8 +11,6 @@
|
||||
|
||||
#define STR8_BUF_ALLOC_SIZE(CAPACITY) (sizeof(Str8) + sizeof(c8) * CAPACITY)
|
||||
|
||||
internal Str8List node_to_list(Str8Node *node);
|
||||
|
||||
Str8 *wapp_str8_alloc_buf(const Allocator *allocator, u64 capacity) {
|
||||
Str8 *str = NULL;
|
||||
|
||||
@@ -302,19 +302,19 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
|
||||
if (!allocator || !str || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8)));
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
if (node) {
|
||||
node->string = full;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
node->item = full;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -332,10 +332,10 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
||||
}
|
||||
|
||||
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
if (node) {
|
||||
node->string = before_str;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
node->item = before_str;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
}
|
||||
|
||||
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
|
||||
@@ -346,30 +346,30 @@ Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8
|
||||
}
|
||||
|
||||
// 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);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
if (node) {
|
||||
node->string = rest;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
node->item = rest;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8List *wapp_str8_rsplit_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) {
|
||||
if (!allocator || !str || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
|
||||
DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8)));
|
||||
|
||||
if (delimiter->size > str->size) {
|
||||
Str8 *full = wapp_str8_alloc_str8(allocator, str);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
if (node) {
|
||||
node->string = full;
|
||||
wapp_str8_list_push_back(output, node);
|
||||
node->item = full;
|
||||
wapp_dbl_list_push_back(output, node);
|
||||
}
|
||||
|
||||
goto RETURN_STR8_SPLIT;
|
||||
@@ -386,10 +386,10 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
||||
}
|
||||
|
||||
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
if (node) {
|
||||
node->string = after_str;
|
||||
wapp_str8_list_push_front(output, node);
|
||||
node->item = after_str;
|
||||
wapp_dbl_list_push_front(output, node);
|
||||
}
|
||||
|
||||
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
|
||||
@@ -399,32 +399,32 @@ Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str
|
||||
}
|
||||
|
||||
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
|
||||
Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
|
||||
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8)));
|
||||
if (node) {
|
||||
node->string = rest;
|
||||
wapp_str8_list_push_front(output, node);
|
||||
node->item = rest;
|
||||
wapp_dbl_list_push_front(output, node);
|
||||
}
|
||||
|
||||
RETURN_STR8_SPLIT:
|
||||
return output;
|
||||
}
|
||||
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) {
|
||||
Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str8RO *delimiter) {
|
||||
if (!allocator || !list || !delimiter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
u64 capacity = list->total_size + (delimiter->size * (list->node_count - 1));
|
||||
u64 capacity = wapp_str8_list_total_size(list) + (delimiter->size * (list->node_count - 1));
|
||||
Str8 *output = wapp_str8_alloc_buf(allocator, capacity * 2);
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
Str8Node *node;
|
||||
DBL_NODE(Str8) *node;
|
||||
u64 node_index = 0;
|
||||
bool running = true;
|
||||
while (running) {
|
||||
node = wapp_str8_list_get(list, node_index);
|
||||
wapp_str8_concat_capped(output, node->string);
|
||||
node = wapp_dbl_list_get(Str8, list, node_index);
|
||||
wapp_str8_concat_capped(output, node->item);
|
||||
if (node_index + 1 < list->node_count) {
|
||||
wapp_str8_concat_capped(output, delimiter);
|
||||
}
|
||||
@@ -435,207 +435,3 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *d
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
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->string)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Str8List node_list = node_to_list(node);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
return;
|
||||
}
|
||||
|
||||
list->total_size += node_list.total_size;
|
||||
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->string)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Str8List node_list = node_to_list(node);
|
||||
|
||||
if (list->node_count == 0) {
|
||||
*list = node_list;
|
||||
return;
|
||||
}
|
||||
|
||||
list->total_size += node_list.total_size;
|
||||
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->string)) {
|
||||
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 = node_to_list(node);
|
||||
|
||||
list->total_size += node_list.total_size;
|
||||
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->total_size -= output->string->size;
|
||||
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->total_size -= output->string->size;
|
||||
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);
|
||||
list->total_size -= output->string->size;
|
||||
|
||||
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 node_to_list(Str8Node *node) {
|
||||
Str8List output = {.first = node, .last = node, .total_size = node->string->size, .node_count = 1};
|
||||
|
||||
while (output.first->prev != NULL) {
|
||||
output.total_size += output.first->prev->string->size;
|
||||
output.first = output.first->prev;
|
||||
++(output.node_count);
|
||||
}
|
||||
|
||||
while (output.last->next != NULL) {
|
||||
output.total_size += output.last->next->string->size;
|
||||
output.last = output.last->next;
|
||||
++(output.node_count);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#ifndef STR8_H
|
||||
#define STR8_H
|
||||
|
||||
#include "aliases.h"
|
||||
#include "mem_allocator.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>
|
||||
|
||||
@@ -19,21 +21,6 @@ struct str8 {
|
||||
|
||||
typedef const Str8 Str8RO;
|
||||
|
||||
typedef struct str8_node Str8Node;
|
||||
struct str8_node {
|
||||
Str8 *string;
|
||||
Str8Node *prev;
|
||||
Str8Node *next;
|
||||
};
|
||||
|
||||
typedef struct str8_list Str8List;
|
||||
struct str8_list {
|
||||
Str8Node *first;
|
||||
Str8Node *last;
|
||||
u64 total_size;
|
||||
u64 node_count;
|
||||
};
|
||||
|
||||
/**
|
||||
* Utilities to be used with printf functions
|
||||
*/
|
||||
@@ -98,23 +85,15 @@ 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)
|
||||
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);
|
||||
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);
|
||||
|
||||
/**
|
||||
* Str8 list utilities
|
||||
*/
|
||||
#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.string = &wapp_str8_lit(STRING)})
|
||||
#define wapp_str8_node_from_str8(STRING) ((Str8Node){.string = &(STRING)})
|
||||
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);
|
||||
#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))
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
|
18
src/core/strings/str8/str8_list.c
Normal file
18
src/core/strings/str8/str8_list.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#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;
|
||||
}
|
25
src/core/strings/str8/str8_list.h
Normal file
25
src/core/strings/str8/str8_list.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 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
|
@@ -2,20 +2,21 @@
|
||||
#define WAPP_CORE_C
|
||||
|
||||
#include "wapp_core.h"
|
||||
#include "mem_utils.c"
|
||||
#include "mem_arena.c"
|
||||
#include "mem_arena_allocator.c"
|
||||
#include "mem_allocator.c"
|
||||
#include "str8.c"
|
||||
#include "termcolour_win.c"
|
||||
#include "termcolour_posix.c"
|
||||
#include "termcolour.c"
|
||||
#include "commander_win.c"
|
||||
#include "commander.c"
|
||||
#include "commander_posix.c"
|
||||
#include "mem_os_win.c"
|
||||
#include "mem_os.c"
|
||||
#include "mem_os_posix.c"
|
||||
#include "cpath.c"
|
||||
#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"
|
||||
#include "os/shell/commander/posix/commander_posix.c"
|
||||
#include "os/shell/commander/win/commander_win.c"
|
||||
#include "os/shell/commander/commander.c"
|
||||
#include "os/cpath/cpath.c"
|
||||
#include "os/mem/posix/mem_os_posix.c"
|
||||
#include "os/mem/win/mem_os_win.c"
|
||||
#include "os/mem/mem_os.c"
|
||||
#include "mem/utils/mem_utils.c"
|
||||
#include "mem/allocator/mem_allocator.c"
|
||||
#include "mem/arena/mem_arena.c"
|
||||
#include "mem/arena/mem_arena_allocator.c"
|
||||
|
||||
#endif // !WAPP_CORE_C
|
||||
|
@@ -1,21 +1,22 @@
|
||||
#ifndef WAPP_CORE_H
|
||||
#define WAPP_CORE_H
|
||||
|
||||
#include "mem_arena_allocator.h"
|
||||
#include "mem_arena.h"
|
||||
#include "mem_utils.h"
|
||||
#include "mem_allocator.h"
|
||||
#include "str8.h"
|
||||
#include "termcolour.h"
|
||||
#include "terminal_colours.h"
|
||||
#include "shell_utils.h"
|
||||
#include "commander_output.h"
|
||||
#include "commander.h"
|
||||
#include "mem_os_ops.h"
|
||||
#include "mem_os_win.h"
|
||||
#include "mem_os.h"
|
||||
#include "mem_os_posix.h"
|
||||
#include "cpath.h"
|
||||
#include "wapp_common.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"
|
||||
#include "os/shell/commander/commander_output.h"
|
||||
#include "os/shell/utils/shell_utils.h"
|
||||
#include "os/cpath/cpath.h"
|
||||
#include "os/mem/posix/mem_os_posix.h"
|
||||
#include "os/mem/win/mem_os_win.h"
|
||||
#include "os/mem/mem_os_ops.h"
|
||||
#include "os/mem/mem_os.h"
|
||||
#include "mem/utils/mem_utils.h"
|
||||
#include "mem/allocator/mem_allocator.h"
|
||||
#include "mem/arena/mem_arena_allocator.h"
|
||||
#include "mem/arena/mem_arena.h"
|
||||
#include "../common/wapp_common.h"
|
||||
|
||||
#endif // !WAPP_CORE_H
|
||||
|
6
src/prng/wapp_prng.c
Normal file
6
src/prng/wapp_prng.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef WAPP_PRNG_C
|
||||
#define WAPP_PRNG_C
|
||||
|
||||
#include "xorshift/xorshift.c"
|
||||
|
||||
#endif // !WAPP_PRNG_C
|
7
src/prng/wapp_prng.h
Normal file
7
src/prng/wapp_prng.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef WAPP_PRNG_H
|
||||
#define WAPP_PRNG_H
|
||||
|
||||
#include "xorshift/xorshift.h"
|
||||
#include "../common/wapp_common.h"
|
||||
|
||||
#endif // !WAPP_PRNG_H
|
89
src/prng/xorshift/xorshift.c
Normal file
89
src/prng/xorshift/xorshift.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "xorshift.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
typedef struct split_mix_64_state SplitMix64State;
|
||||
struct split_mix_64_state {
|
||||
u64 seed;
|
||||
};
|
||||
|
||||
internal u64 rol64(u64 x, u64 bits);
|
||||
internal u64 split_mix_64(SplitMix64State *state);
|
||||
|
||||
XOR256State wapp_prng_xorshift_init_state(void) {
|
||||
persistent bool seeded = false;
|
||||
if (!seeded) {
|
||||
seeded = true;
|
||||
|
||||
struct timespec ts = {0};
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||
|
||||
srand48(ts.tv_nsec);
|
||||
}
|
||||
|
||||
SplitMix64State sm64 = {.seed = lrand48()};
|
||||
|
||||
return (XOR256State){
|
||||
.x = split_mix_64(&sm64),
|
||||
.y = split_mix_64(&sm64),
|
||||
.z = split_mix_64(&sm64),
|
||||
.w = split_mix_64(&sm64),
|
||||
};
|
||||
}
|
||||
|
||||
u64 wapp_prng_xorshift_256(XOR256State *state) {
|
||||
u64 t = state->x ^ (state->x << 11);
|
||||
|
||||
state->x = state->y;
|
||||
state->y = state->z;
|
||||
state->z = state->w;
|
||||
state->w = (state->w ^ (state->w >> 19)) ^ (t ^ (t >> 8));
|
||||
|
||||
return state->w;
|
||||
}
|
||||
|
||||
u64 wapp_prng_xorshift_256ss(XOR256State *state) {
|
||||
const u64 result = rol64(state->z * 5, 7) * 9;
|
||||
const u64 t = state->z << 17;
|
||||
|
||||
state->y ^= state->w;
|
||||
state->x ^= state->z;
|
||||
state->z ^= state->y;
|
||||
state->w ^= state->x;
|
||||
|
||||
state->y ^= t;
|
||||
state->x = rol64(state->x, 45);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
u64 wapp_prng_xorshift_256p(XOR256State *state) {
|
||||
const u64 result = state->w + state->x;
|
||||
const u64 t = state->z << 17;
|
||||
|
||||
state->y ^= state->w;
|
||||
state->x ^= state->z;
|
||||
state->z ^= state->y;
|
||||
state->w ^= state->x;
|
||||
|
||||
state->y ^= t;
|
||||
state->x = rol64(state->x, 45);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
internal u64 rol64(u64 x, u64 bits) {
|
||||
return (x << bits) | (x >> (64 - bits));
|
||||
}
|
||||
|
||||
internal u64 split_mix_64(SplitMix64State *state) {
|
||||
state->seed += 0x9E3779B97f4A7C15;
|
||||
|
||||
u64 result = state->seed;
|
||||
result = (result ^ (result >> 30)) * 0xBF58476D1CE4E5B9;
|
||||
result = (result ^ (result >> 27)) * 0x94D049BB133111EB;
|
||||
|
||||
return result ^ (result >> 31);
|
||||
}
|
27
src/prng/xorshift/xorshift.h
Normal file
27
src/prng/xorshift/xorshift.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef XORSHIFT_H
|
||||
#define XORSHIFT_H
|
||||
|
||||
#include "../../common/aliases/aliases.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // __cplusplus
|
||||
|
||||
typedef struct xor_256_state XOR256State;
|
||||
struct xor_256_state {
|
||||
u64 x;
|
||||
u64 y;
|
||||
u64 z;
|
||||
u64 w;
|
||||
};
|
||||
|
||||
XOR256State wapp_prng_xorshift_init_state(void);
|
||||
u64 wapp_prng_xorshift_256(XOR256State *state);
|
||||
u64 wapp_prng_xorshift_256ss(XOR256State *state);
|
||||
u64 wapp_prng_xorshift_256p(XOR256State *state);
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // !XORSHIFT_H
|
@@ -1,7 +1,7 @@
|
||||
#include "tester.h"
|
||||
#include "aliases.h"
|
||||
#include "termcolour.h"
|
||||
#include "str8.h"
|
||||
#include "../../common/aliases/aliases.h"
|
||||
#include "../../core/os/shell/termcolour/termcolour.h"
|
||||
#include "../../core/strings/str8/str8.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@@ -1,9 +1,9 @@
|
||||
#ifndef TESTER_H
|
||||
#define TESTER_H
|
||||
|
||||
#include "misc_utils.h"
|
||||
#include "platform.h"
|
||||
#include "str8.h"
|
||||
#include "../../common/misc/misc_utils.h"
|
||||
#include "../../common/platform/platform.h"
|
||||
#include "../../core/strings/str8/str8.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#define WAPP_TESTING_C
|
||||
|
||||
#include "wapp_testing.h"
|
||||
#include "tester.c"
|
||||
#include "wapp_core.c"
|
||||
#include "tester/tester.c"
|
||||
#include "../core/wapp_core.c"
|
||||
|
||||
#endif // !WAPP_TESTING_C
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef WAPP_TESTING_H
|
||||
#define WAPP_TESTING_H
|
||||
|
||||
#include "tester.h"
|
||||
#include "wapp_common.h"
|
||||
#include "wapp_core.h"
|
||||
#include "tester/tester.h"
|
||||
#include "../common/wapp_common.h"
|
||||
#include "../core/wapp_core.h"
|
||||
|
||||
#endif // !WAPP_TESTING_H
|
||||
|
59
src/uuid/uuid.c
Normal file
59
src/uuid/uuid.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "uuid.h"
|
||||
#include "../common/aliases/aliases.h"
|
||||
#include "../core/strings/str8/str8.h"
|
||||
#include "../prng/xorshift/xorshift.h"
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#define UUID_STR_FORMAT ("%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.12" PRIx64)
|
||||
|
||||
typedef struct uuid4 UUID4;
|
||||
struct uuid4 {
|
||||
u64 high;
|
||||
u64 low;
|
||||
};
|
||||
|
||||
internal UUID4 generate_uuid4(void);
|
||||
internal void uuid4_to_uuid(const UUID4* uuid4, UUID *uuid);
|
||||
|
||||
UUID *wapp_uuid_init_uuid4(UUID *uuid) {
|
||||
if (!uuid) {
|
||||
goto RETURN_INIT_UUID4;
|
||||
}
|
||||
|
||||
UUID4 uuid4 = generate_uuid4();
|
||||
uuid4_to_uuid(&uuid4, uuid);
|
||||
|
||||
RETURN_INIT_UUID4:
|
||||
return uuid;
|
||||
}
|
||||
|
||||
internal UUID4 generate_uuid4(void) {
|
||||
persistent XOR256State state = {0};
|
||||
persistent bool initialised = false;
|
||||
|
||||
if (!initialised) {
|
||||
initialised = true;
|
||||
state = wapp_prng_xorshift_init_state();
|
||||
}
|
||||
|
||||
UUID4 uuid = (UUID4){
|
||||
.high = wapp_prng_xorshift_256(&state),
|
||||
.low = wapp_prng_xorshift_256(&state),
|
||||
};
|
||||
|
||||
uuid.high = (uuid.high & 0xffffffffffff0fff) | 0x0000000000004000;
|
||||
uuid.low = (uuid.low & 0x3fffffffffffffff) | 0x8000000000000000;
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
internal void uuid4_to_uuid(const UUID4* uuid4, UUID *uuid) {
|
||||
u64 grp1 = uuid4->high >> 32;
|
||||
u64 grp2 = (uuid4->high << 32) >> 48;
|
||||
u64 grp3 = (uuid4->high << 48) >> 48;
|
||||
u64 grp4 = uuid4->low >> 48;
|
||||
u64 grp5 = (uuid4->low << 16) >> 16;
|
||||
|
||||
wapp_str8_format(&(uuid->uuid), UUID_STR_FORMAT, grp1, grp2, grp3, grp4, grp5);
|
||||
}
|
34
src/uuid/uuid.h
Normal file
34
src/uuid/uuid.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef UUID_H
|
||||
#define UUID_H
|
||||
|
||||
#include "../common/aliases/aliases.h"
|
||||
#include "../core/strings/str8/str8.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
#endif // __cplusplus
|
||||
|
||||
#define UUID_BUF_LENGTH 48
|
||||
#define WAPP_UUID_SPEC WAPP_STR8_SPEC
|
||||
#define wapp_uuid_varg(UUID) wapp_str8_varg((UUID).uuid)
|
||||
|
||||
typedef struct uuid UUID;
|
||||
struct uuid {
|
||||
Str8 uuid;
|
||||
};
|
||||
|
||||
#define wapp_uuid_gen_uuid4() *(wapp_uuid_init_uuid4(&wapp_uuid_create()))
|
||||
|
||||
/* Low level UUID API */
|
||||
|
||||
#define wapp_uuid_create() ((UUID){.uuid = wapp_str8_buf(UUID_BUF_LENGTH)})
|
||||
|
||||
// Just returns the same pointer that was passed in with the UUID initialised.
|
||||
// If the pointer is NULL, it skips initialisation.
|
||||
UUID *wapp_uuid_init_uuid4(UUID *uuid);
|
||||
|
||||
#ifdef __cplusplus
|
||||
END_C_LINKAGE
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // !UUID_H
|
8
src/uuid/wapp_uuid.c
Normal file
8
src/uuid/wapp_uuid.c
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef WAPP_UUID_C
|
||||
#define WAPP_UUID_C
|
||||
|
||||
#include "uuid.c"
|
||||
#include "../core/wapp_core.c"
|
||||
#include "../prng/wapp_prng.c"
|
||||
|
||||
#endif // !WAPP_UUID_C
|
9
src/uuid/wapp_uuid.h
Normal file
9
src/uuid/wapp_uuid.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef WAPP_UUID_H
|
||||
#define WAPP_UUID_H
|
||||
|
||||
#include "uuid.h"
|
||||
#include "../common/wapp_common.h"
|
||||
#include "../core/wapp_core.h"
|
||||
#include "../prng/wapp_prng.h"
|
||||
|
||||
#endif // !WAPP_UUID_H
|
@@ -2,7 +2,10 @@
|
||||
#define WAPP_C
|
||||
|
||||
#include "wapp.h"
|
||||
#include "wapp_core.c"
|
||||
#include "wapp_testing.c"
|
||||
#include "containers/wapp_containers.c"
|
||||
#include "core/wapp_core.c"
|
||||
#include "prng/wapp_prng.c"
|
||||
#include "uuid/uuid.c"
|
||||
#include "testing/wapp_testing.c"
|
||||
|
||||
#endif // !WAPP_C
|
||||
|
@@ -1,8 +1,11 @@
|
||||
#ifndef WAPP_H
|
||||
#define WAPP_H
|
||||
|
||||
#include "wapp_common.h"
|
||||
#include "wapp_core.h"
|
||||
#include "wapp_testing.h"
|
||||
#include "common/wapp_common.h"
|
||||
#include "containers/wapp_containers.h"
|
||||
#include "core/wapp_core.h"
|
||||
#include "prng/wapp_prng.h"
|
||||
#include "uuid/wapp_uuid.h"
|
||||
#include "testing/wapp_testing.h"
|
||||
|
||||
#endif // !WAPP_H
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#include "test_allocator.h"
|
||||
#include "mem_allocator.h"
|
||||
#include "mem_arena_allocator.h"
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef TEST_ALLOCATOR_H
|
||||
#define TEST_ALLOCATOR_H
|
||||
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,8 +1,5 @@
|
||||
#include "test_arena.h"
|
||||
#include "aliases.h"
|
||||
#include "mem_arena.h"
|
||||
#include "misc_utils.h"
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef TEST_ARENA_H
|
||||
#define TEST_ARENA_H
|
||||
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,10 +1,5 @@
|
||||
#include "test_cpath.h"
|
||||
#include "cpath.h"
|
||||
#include "mem_allocator.h"
|
||||
#include "mem_arena_allocator.h"
|
||||
#include "misc_utils.h"
|
||||
#include "str8.h"
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
@@ -22,16 +17,16 @@ TestFuncResult test_cpath_join_path(void) {
|
||||
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP);
|
||||
wapp_str8_format(&tmp, "%c", PATH_SEP);
|
||||
|
||||
Str8List parts = {0};
|
||||
wapp_str8_list_push_back(&parts, &wapp_str8_node_from_str8(tmp));
|
||||
wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("home"));
|
||||
wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("abdelrahman"));
|
||||
wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("Documents"));
|
||||
DBL_LIST(Str8) parts = {0};
|
||||
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_str8(tmp));
|
||||
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("home"));
|
||||
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("abdelrahman"));
|
||||
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("Documents"));
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = wapp_str8_equal(&out, &expected);
|
||||
|
||||
wapp_str8_list_pop_front(&parts);
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
|
||||
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP);
|
||||
|
||||
@@ -39,8 +34,8 @@ TestFuncResult test_cpath_join_path(void) {
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
|
||||
wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("home"));
|
||||
wapp_str8_list_pop_front(&parts);
|
||||
wapp_str8_list_push_front(&parts, &wapp_str8_node_from_str8(tmp));
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wapp_dbl_list_push_front(&parts, &wapp_str8_node_from_str8(tmp));
|
||||
|
||||
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP);
|
||||
|
||||
@@ -48,35 +43,35 @@ TestFuncResult test_cpath_join_path(void) {
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
|
||||
wapp_str8_format(&tmp, "home%c", PATH_SEP);
|
||||
wapp_str8_list_pop_front(&parts);
|
||||
wapp_str8_list_push_front(&parts, &wapp_str8_node_from_cstr("home"));
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wapp_dbl_list_push_front(&parts, &wapp_str8_node_from_cstr("home"));
|
||||
|
||||
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
|
||||
wapp_str8_list_empty(&parts);
|
||||
wapp_dbl_list_empty(&parts);
|
||||
|
||||
wapp_str8_format(&tmp, "%chome", PATH_SEP);
|
||||
wapp_str8_list_push_back(&parts, &wapp_str8_node_from_str8(tmp));
|
||||
wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr(""));
|
||||
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_str8(tmp));
|
||||
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr(""));
|
||||
|
||||
wapp_str8_format(&expected, "%chome", PATH_SEP);
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
|
||||
wapp_str8_list_pop_front(&parts);
|
||||
wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr(""));
|
||||
wapp_dbl_list_pop_front(Str8, &parts);
|
||||
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr(""));
|
||||
|
||||
wapp_str8_format(&expected, "%s", "");
|
||||
|
||||
wapp_cpath_join_path(&out, &parts);
|
||||
result = result && wapp_str8_equal(&out, &expected);
|
||||
|
||||
wapp_str8_list_pop_back(&parts);
|
||||
wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("home"));
|
||||
wapp_dbl_list_pop_back(Str8, &parts);
|
||||
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("home"));
|
||||
|
||||
wapp_str8_copy_cstr_capped(&expected, "home");
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef TEST_CPATH_H
|
||||
#define TEST_CPATH_H
|
||||
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,16 +1,14 @@
|
||||
#include "test_shell_commander.h"
|
||||
#include "commander.h"
|
||||
#include "str8.h"
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
TestFuncResult test_commander_cmd_success(void) {
|
||||
Str8List cmd = {0};
|
||||
wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
|
||||
wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("hello world"));
|
||||
DBL_LIST(Str8) cmd = {0};
|
||||
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
|
||||
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("hello world"));
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
|
||||
bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
|
||||
@@ -20,8 +18,8 @@ TestFuncResult test_commander_cmd_success(void) {
|
||||
}
|
||||
|
||||
TestFuncResult test_commander_cmd_failure(void) {
|
||||
Str8List cmd = {0};
|
||||
wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("grep"));
|
||||
DBL_LIST(Str8) cmd = {0};
|
||||
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("grep"));
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
|
||||
bool failed = result.exited && result.exit_code != EXIT_SUCCESS &&
|
||||
@@ -36,9 +34,9 @@ TestFuncResult test_commander_cmd_out_buf_success(void) {
|
||||
char msg[] = "hello world";
|
||||
wapp_str8_copy_cstr_capped(&expected, msg);
|
||||
|
||||
Str8List cmd = {0};
|
||||
wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
|
||||
wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg));
|
||||
DBL_LIST(Str8) cmd = {0};
|
||||
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
|
||||
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg));
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
|
||||
@@ -53,9 +51,9 @@ TestFuncResult test_commander_cmd_out_buf_failure(void) {
|
||||
char msg[] = "hello world";
|
||||
wapp_str8_copy_cstr_capped(&expected, msg);
|
||||
|
||||
Str8List cmd = {0};
|
||||
wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
|
||||
wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg));
|
||||
DBL_LIST(Str8) cmd = {0};
|
||||
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
|
||||
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg));
|
||||
|
||||
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
|
||||
bool failed = !result.exited && result.exit_code != EXIT_SUCCESS &&
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef TEST_SHELL_COMMANDER_H
|
||||
#define TEST_SHELL_COMMANDER_H
|
||||
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,9 +1,5 @@
|
||||
#include "test_str8.h"
|
||||
#include "mem_allocator.h"
|
||||
#include "mem_arena_allocator.h"
|
||||
#include "misc_utils.h"
|
||||
#include "str8.h"
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define ARRLEN(ARR) (sizeof(ARR) / sizeof(ARR[0]))
|
||||
@@ -420,8 +416,8 @@ TestFuncResult test_str8_split(void) {
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_split(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_split(&arena, &str, &delim2);
|
||||
DBL_LIST(Str8) *list1 = wapp_str8_split(&arena, &str, &delim1);
|
||||
DBL_LIST(Str8) *list2 = wapp_str8_split(&arena, &str, &delim2);
|
||||
|
||||
Str8RO splits1[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
@@ -442,14 +438,14 @@ TestFuncResult test_str8_split(void) {
|
||||
u64 count2 = ARRLEN(splits2);
|
||||
bool running2 = true;
|
||||
|
||||
result = list1->node_count == count1 && list1->total_size == str.size - 3;
|
||||
result = result && list2->node_count == count2 && list2->total_size == str.size - 4;
|
||||
result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
Str8Node *node = wapp_str8_list_get(list1, index1);
|
||||
result = result && wapp_str8_equal(node->string, &(splits1[index1]));
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list1, index1);
|
||||
result = result && wapp_str8_equal(node->item, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
running1 = index1 < count1;
|
||||
@@ -458,8 +454,8 @@ TestFuncResult test_str8_split(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
Str8Node *node = wapp_str8_list_get(list2, index2);
|
||||
result = result && wapp_str8_equal(node->string, &(splits2[index2]));
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list2, index2);
|
||||
result = result && wapp_str8_equal(node->item, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
@@ -476,7 +472,7 @@ TestFuncResult test_str8_split_with_max(void) {
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim = wapp_str8_lit(" ");
|
||||
Str8List *list = wapp_str8_split_with_max(&arena, &str, &delim, 2);
|
||||
DBL_LIST(Str8) *list = wapp_str8_split_with_max(&arena, &str, &delim, 2);
|
||||
|
||||
Str8RO splits[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
@@ -488,13 +484,13 @@ TestFuncResult test_str8_split_with_max(void) {
|
||||
u64 count = ARRLEN(splits);
|
||||
bool running = true;
|
||||
|
||||
result = list->node_count == count && list->total_size == str.size - 2;
|
||||
result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
Str8Node *node = wapp_str8_list_get(list, index);
|
||||
result = result && wapp_str8_equal(node->string, &(splits[index]));
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list, index);
|
||||
result = result && wapp_str8_equal(node->item, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
@@ -512,8 +508,8 @@ TestFuncResult test_str8_rsplit(void) {
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
|
||||
DBL_LIST(Str8) *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
|
||||
DBL_LIST(Str8) *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
|
||||
|
||||
Str8RO splits1[] = {
|
||||
wapp_str8_slice(&str, 0, 5),
|
||||
@@ -534,14 +530,14 @@ TestFuncResult test_str8_rsplit(void) {
|
||||
u64 count2 = ARRLEN(splits2);
|
||||
bool running2 = true;
|
||||
|
||||
result = list1->node_count == count1 && list1->total_size == str.size - 3;
|
||||
result = result && list2->node_count == count2 && list2->total_size == str.size - 4;
|
||||
result = list1->node_count == count1 && wapp_str8_list_total_size(list1) == str.size - 3;
|
||||
result = result && list2->node_count == count2 && wapp_str8_list_total_size(list2) == str.size - 4;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running1) {
|
||||
Str8Node *node = wapp_str8_list_get(list1, index1);
|
||||
result = result && wapp_str8_equal(node->string, &(splits1[index1]));
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list1, index1);
|
||||
result = result && wapp_str8_equal(node->item, &(splits1[index1]));
|
||||
|
||||
++index1;
|
||||
running1 = index1 < count1;
|
||||
@@ -550,8 +546,8 @@ TestFuncResult test_str8_rsplit(void) {
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running2) {
|
||||
Str8Node *node = wapp_str8_list_get(list2, index2);
|
||||
result = result && wapp_str8_equal(node->string, &(splits2[index2]));
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list2, index2);
|
||||
result = result && wapp_str8_equal(node->item, &(splits2[index2]));
|
||||
|
||||
++index2;
|
||||
running2 = index2 < count2;
|
||||
@@ -568,7 +564,7 @@ TestFuncResult test_str8_rsplit_with_max(void) {
|
||||
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim = wapp_str8_lit(" ");
|
||||
Str8List *list = wapp_str8_rsplit_with_max(&arena, &str, &delim, 2);
|
||||
DBL_LIST(Str8) *list = wapp_str8_rsplit_with_max(&arena, &str, &delim, 2);
|
||||
|
||||
Str8RO splits[] = {
|
||||
wapp_str8_slice(&str, 0, 11),
|
||||
@@ -580,13 +576,13 @@ TestFuncResult test_str8_rsplit_with_max(void) {
|
||||
u64 count = ARRLEN(splits);
|
||||
bool running = true;
|
||||
|
||||
result = list->node_count == count && list->total_size == str.size - 2;
|
||||
result = list->node_count == count && wapp_str8_list_total_size(list) == str.size - 2;
|
||||
|
||||
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
|
||||
// MSVC Spectre mitigation warnings
|
||||
while (running) {
|
||||
Str8Node *node = wapp_str8_list_get(list, index);
|
||||
result = result && wapp_str8_equal(node->string, &(splits[index]));
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list, index);
|
||||
result = result && wapp_str8_equal(node->item, &(splits[index]));
|
||||
|
||||
++index;
|
||||
running = index < count;
|
||||
@@ -604,8 +600,8 @@ TestFuncResult test_str8_join(void) {
|
||||
Str8 str = wapp_str8_lit("hello world from me");
|
||||
Str8 delim1 = wapp_str8_lit(" ");
|
||||
Str8 delim2 = wapp_str8_lit("from");
|
||||
Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
|
||||
Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
|
||||
DBL_LIST(Str8) *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
|
||||
DBL_LIST(Str8) *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
|
||||
Str8 *join1 = wapp_str8_join(&arena, list1, &delim1);
|
||||
Str8 *join2 = wapp_str8_join(&arena, list2, &delim2);
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef TEST_STR8_H
|
||||
#define TEST_STR8_H
|
||||
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#include "test_str8_list.h"
|
||||
#include "str8.h"
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
|
||||
TestFuncResult test_str8_list_get(void) {
|
||||
bool result;
|
||||
@@ -11,33 +10,33 @@ TestFuncResult test_str8_list_get(void) {
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
|
||||
Str8List list = {0};
|
||||
Str8Node n1 = { .string = &s1 };
|
||||
Str8Node n2 = { .string = &s2 };
|
||||
Str8Node n3 = { .string = &s3 };
|
||||
Str8Node n4 = { .string = &s4 };
|
||||
Str8Node n5 = { .string = &s5 };
|
||||
DBL_LIST(Str8) list = {0};
|
||||
DBL_NODE(Str8) n1 = { .item = &s1 };
|
||||
DBL_NODE(Str8) n2 = { .item = &s2 };
|
||||
DBL_NODE(Str8) n3 = { .item = &s3 };
|
||||
DBL_NODE(Str8) n4 = { .item = &s4 };
|
||||
DBL_NODE(Str8) n5 = { .item = &s5 };
|
||||
|
||||
wapp_str8_list_push_back(&list, &n1);
|
||||
wapp_str8_list_push_back(&list, &n2);
|
||||
wapp_str8_list_push_back(&list, &n3);
|
||||
wapp_str8_list_push_back(&list, &n4);
|
||||
wapp_str8_list_push_back(&list, &n5);
|
||||
wapp_dbl_list_push_back(&list, &n1);
|
||||
wapp_dbl_list_push_back(&list, &n2);
|
||||
wapp_dbl_list_push_back(&list, &n3);
|
||||
wapp_dbl_list_push_back(&list, &n4);
|
||||
wapp_dbl_list_push_back(&list, &n5);
|
||||
|
||||
Str8Node *node = wapp_str8_list_get(&list, 0);
|
||||
result = node->string == &s1 && wapp_str8_equal(node->string, &s1);
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, &list, 0);
|
||||
result = node->item == &s1 && wapp_str8_equal(node->item, &s1);
|
||||
|
||||
node = wapp_str8_list_get(&list, 1);
|
||||
result = result && node->string == &s2 && wapp_str8_equal(node->string, &s2);
|
||||
node = wapp_dbl_list_get(Str8, &list, 1);
|
||||
result = result && node->item == &s2 && wapp_str8_equal(node->item, &s2);
|
||||
|
||||
node = wapp_str8_list_get(&list, 2);
|
||||
result = result && node->string == &s3 && wapp_str8_equal(node->string, &s3);
|
||||
node = wapp_dbl_list_get(Str8, &list, 2);
|
||||
result = result && node->item == &s3 && wapp_str8_equal(node->item, &s3);
|
||||
|
||||
node = wapp_str8_list_get(&list, 3);
|
||||
result = result && node->string == &s4 && wapp_str8_equal(node->string, &s4);
|
||||
node = wapp_dbl_list_get(Str8, &list, 3);
|
||||
result = result && node->item == &s4 && wapp_str8_equal(node->item, &s4);
|
||||
|
||||
node = wapp_str8_list_get(&list, 4);
|
||||
result = result && node->string == &s5 && wapp_str8_equal(node->string, &s5);
|
||||
node = wapp_dbl_list_get(Str8, &list, 4);
|
||||
result = result && node->item == &s5 && wapp_str8_equal(node->item, &s5);
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
@@ -49,19 +48,19 @@ TestFuncResult test_str8_list_push_front(void) {
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
|
||||
Str8List list = {0};
|
||||
Str8Node n1 = { .string = &s1 };
|
||||
Str8Node n2 = { .string = &s2 };
|
||||
Str8Node n3 = { .string = &s3 };
|
||||
DBL_LIST(Str8) list = {0};
|
||||
DBL_NODE(Str8) n1 = { .item = &s1 };
|
||||
DBL_NODE(Str8) n2 = { .item = &s2 };
|
||||
DBL_NODE(Str8) n3 = { .item = &s3 };
|
||||
|
||||
wapp_str8_list_push_front(&list, &n1);
|
||||
result = list.first == list.last && list.first == &n1 && list.first->string == &s1 && list.total_size == 1 && list.node_count == 1;
|
||||
wapp_dbl_list_push_front(&list, &n1);
|
||||
result = list.first == list.last && list.first == &n1 && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
|
||||
wapp_str8_list_push_front(&list, &n2);
|
||||
result = result && list.first == &n2 && list.first->string == &s2 && list.total_size == 2 && list.node_count == 2;
|
||||
wapp_dbl_list_push_front(&list, &n2);
|
||||
result = result && list.first == &n2 && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
|
||||
wapp_str8_list_push_front(&list, &n3);
|
||||
result = result && list.first == &n3 && list.first->string == &s3 && list.total_size == 3 && list.node_count == 3;
|
||||
wapp_dbl_list_push_front(&list, &n3);
|
||||
result = result && list.first == &n3 && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
@@ -73,19 +72,19 @@ TestFuncResult test_str8_list_push_back(void) {
|
||||
Str8 s2 = wapp_str8_lit("2");
|
||||
Str8 s3 = wapp_str8_lit("3");
|
||||
|
||||
Str8List list = {0};
|
||||
Str8Node n1 = { .string = &s1 };
|
||||
Str8Node n2 = { .string = &s2 };
|
||||
Str8Node n3 = { .string = &s3 };
|
||||
DBL_LIST(Str8) list = {0};
|
||||
DBL_NODE(Str8) n1 = { .item = &s1 };
|
||||
DBL_NODE(Str8) n2 = { .item = &s2 };
|
||||
DBL_NODE(Str8) n3 = { .item = &s3 };
|
||||
|
||||
wapp_str8_list_push_back(&list, &n1);
|
||||
result = list.first == list.last && list.last == &n1 && list.last->string == &s1 && list.total_size == 1 && list.node_count == 1;
|
||||
wapp_dbl_list_push_back(&list, &n1);
|
||||
result = list.first == list.last && list.last == &n1 && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
|
||||
wapp_str8_list_push_back(&list, &n2);
|
||||
result = result && list.last == &n2 && list.last->string == &s2 && list.total_size == 2 && list.node_count == 2;
|
||||
wapp_dbl_list_push_back(&list, &n2);
|
||||
result = result && list.last == &n2 && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
|
||||
wapp_str8_list_push_back(&list, &n3);
|
||||
result = result && list.last == &n3 && list.last->string == &s3 && list.total_size == 3 && list.node_count == 3;
|
||||
wapp_dbl_list_push_back(&list, &n3);
|
||||
result = result && list.last == &n3 && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
@@ -101,28 +100,28 @@ TestFuncResult test_str8_list_insert(void) {
|
||||
Str8 s6 = wapp_str8_lit("6");
|
||||
Str8 s7 = wapp_str8_lit("7");
|
||||
|
||||
Str8List list = {0};
|
||||
Str8Node n1 = { .string = &s1 };
|
||||
Str8Node n2 = { .string = &s2 };
|
||||
Str8Node n3 = { .string = &s3 };
|
||||
Str8Node n4 = { .string = &s4 };
|
||||
Str8Node n5 = { .string = &s5 };
|
||||
Str8Node n6 = { .string = &s6 };
|
||||
Str8Node n7 = { .string = &s7 };
|
||||
DBL_LIST(Str8) list = {0};
|
||||
DBL_NODE(Str8) n1 = { .item = &s1 };
|
||||
DBL_NODE(Str8) n2 = { .item = &s2 };
|
||||
DBL_NODE(Str8) n3 = { .item = &s3 };
|
||||
DBL_NODE(Str8) n4 = { .item = &s4 };
|
||||
DBL_NODE(Str8) n5 = { .item = &s5 };
|
||||
DBL_NODE(Str8) n6 = { .item = &s6 };
|
||||
DBL_NODE(Str8) n7 = { .item = &s7 };
|
||||
|
||||
wapp_str8_list_push_back(&list, &n1);
|
||||
wapp_str8_list_push_back(&list, &n2);
|
||||
wapp_str8_list_push_back(&list, &n3);
|
||||
wapp_str8_list_push_back(&list, &n4);
|
||||
wapp_str8_list_push_back(&list, &n5);
|
||||
wapp_dbl_list_push_back(&list, &n1);
|
||||
wapp_dbl_list_push_back(&list, &n2);
|
||||
wapp_dbl_list_push_back(&list, &n3);
|
||||
wapp_dbl_list_push_back(&list, &n4);
|
||||
wapp_dbl_list_push_back(&list, &n5);
|
||||
|
||||
Str8Node *node;
|
||||
wapp_str8_list_insert(&list, &n6, 2);
|
||||
node = wapp_str8_list_get(&list, 2);
|
||||
result = node != NULL && node->string == &s6 && list.total_size == 6 && list.node_count == 6;
|
||||
wapp_str8_list_insert(&list, &n7, 5);
|
||||
node = wapp_str8_list_get(&list, 5);
|
||||
result = result && node != NULL && node->string == &s7 && list.total_size == 7 && list.node_count == 7;
|
||||
DBL_NODE(Str8) *node;
|
||||
wapp_dbl_list_insert(&list, &n6, 2);
|
||||
node = wapp_dbl_list_get(Str8, &list, 2);
|
||||
result = node != NULL && node->item == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6;
|
||||
wapp_dbl_list_insert(&list, &n7, 5);
|
||||
node = wapp_dbl_list_get(Str8, &list, 5);
|
||||
result = result && node != NULL && node->item == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
@@ -136,33 +135,33 @@ TestFuncResult test_str8_list_pop_front(void) {
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
|
||||
Str8List list = {0};
|
||||
Str8Node n1 = { .string = &s1 };
|
||||
Str8Node n2 = { .string = &s2 };
|
||||
Str8Node n3 = { .string = &s3 };
|
||||
Str8Node n4 = { .string = &s4 };
|
||||
Str8Node n5 = { .string = &s5 };
|
||||
DBL_LIST(Str8) list = {0};
|
||||
DBL_NODE(Str8) n1 = { .item = &s1 };
|
||||
DBL_NODE(Str8) n2 = { .item = &s2 };
|
||||
DBL_NODE(Str8) n3 = { .item = &s3 };
|
||||
DBL_NODE(Str8) n4 = { .item = &s4 };
|
||||
DBL_NODE(Str8) n5 = { .item = &s5 };
|
||||
|
||||
wapp_str8_list_push_back(&list, &n1);
|
||||
wapp_str8_list_push_back(&list, &n2);
|
||||
wapp_str8_list_push_back(&list, &n3);
|
||||
wapp_str8_list_push_back(&list, &n4);
|
||||
wapp_str8_list_push_back(&list, &n5);
|
||||
wapp_dbl_list_push_back(&list, &n1);
|
||||
wapp_dbl_list_push_back(&list, &n2);
|
||||
wapp_dbl_list_push_back(&list, &n3);
|
||||
wapp_dbl_list_push_back(&list, &n4);
|
||||
wapp_dbl_list_push_back(&list, &n5);
|
||||
|
||||
Str8Node *node = wapp_str8_list_pop_front(&list);
|
||||
result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4;
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_str8_list_pop_front(&list);
|
||||
result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3;
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_str8_list_pop_front(&list);
|
||||
result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2;
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_str8_list_pop_front(&list);
|
||||
result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1;
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_str8_list_pop_front(&list);
|
||||
result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0;
|
||||
node = wapp_dbl_list_pop_front(Str8, &list);
|
||||
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
@@ -176,33 +175,33 @@ TestFuncResult test_str8_list_pop_back(void) {
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
|
||||
Str8List list = {0};
|
||||
Str8Node n1 = { .string = &s1 };
|
||||
Str8Node n2 = { .string = &s2 };
|
||||
Str8Node n3 = { .string = &s3 };
|
||||
Str8Node n4 = { .string = &s4 };
|
||||
Str8Node n5 = { .string = &s5 };
|
||||
DBL_LIST(Str8) list = {0};
|
||||
DBL_NODE(Str8) n1 = { .item = &s1 };
|
||||
DBL_NODE(Str8) n2 = { .item = &s2 };
|
||||
DBL_NODE(Str8) n3 = { .item = &s3 };
|
||||
DBL_NODE(Str8) n4 = { .item = &s4 };
|
||||
DBL_NODE(Str8) n5 = { .item = &s5 };
|
||||
|
||||
wapp_str8_list_push_front(&list, &n1);
|
||||
wapp_str8_list_push_front(&list, &n2);
|
||||
wapp_str8_list_push_front(&list, &n3);
|
||||
wapp_str8_list_push_front(&list, &n4);
|
||||
wapp_str8_list_push_front(&list, &n5);
|
||||
wapp_dbl_list_push_front(&list, &n1);
|
||||
wapp_dbl_list_push_front(&list, &n2);
|
||||
wapp_dbl_list_push_front(&list, &n3);
|
||||
wapp_dbl_list_push_front(&list, &n4);
|
||||
wapp_dbl_list_push_front(&list, &n5);
|
||||
|
||||
Str8Node *node = wapp_str8_list_pop_back(&list);
|
||||
result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4;
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_str8_list_pop_back(&list);
|
||||
result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3;
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_str8_list_pop_back(&list);
|
||||
result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2;
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_str8_list_pop_back(&list);
|
||||
result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1;
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_str8_list_pop_back(&list);
|
||||
result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0;
|
||||
node = wapp_dbl_list_pop_back(Str8, &list);
|
||||
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
@@ -216,33 +215,33 @@ TestFuncResult test_str8_list_remove(void) {
|
||||
Str8 s4 = wapp_str8_lit("4");
|
||||
Str8 s5 = wapp_str8_lit("5");
|
||||
|
||||
Str8List list = {0};
|
||||
Str8Node n1 = { .string = &s1 };
|
||||
Str8Node n2 = { .string = &s2 };
|
||||
Str8Node n3 = { .string = &s3 };
|
||||
Str8Node n4 = { .string = &s4 };
|
||||
Str8Node n5 = { .string = &s5 };
|
||||
DBL_LIST(Str8) list = {0};
|
||||
DBL_NODE(Str8) n1 = { .item = &s1 };
|
||||
DBL_NODE(Str8) n2 = { .item = &s2 };
|
||||
DBL_NODE(Str8) n3 = { .item = &s3 };
|
||||
DBL_NODE(Str8) n4 = { .item = &s4 };
|
||||
DBL_NODE(Str8) n5 = { .item = &s5 };
|
||||
|
||||
wapp_str8_list_push_back(&list, &n1);
|
||||
wapp_str8_list_push_back(&list, &n2);
|
||||
wapp_str8_list_push_back(&list, &n3);
|
||||
wapp_str8_list_push_back(&list, &n4);
|
||||
wapp_str8_list_push_back(&list, &n5);
|
||||
wapp_dbl_list_push_back(&list, &n1);
|
||||
wapp_dbl_list_push_back(&list, &n2);
|
||||
wapp_dbl_list_push_back(&list, &n3);
|
||||
wapp_dbl_list_push_back(&list, &n4);
|
||||
wapp_dbl_list_push_back(&list, &n5);
|
||||
|
||||
Str8Node *node = wapp_str8_list_remove(&list, 0);
|
||||
result = node == &n1 && node->string == &s1 && wapp_str8_equal(node->string, &s1) && list.total_size == 4 && list.node_count == 4;
|
||||
DBL_NODE(Str8) *node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4;
|
||||
|
||||
node = wapp_str8_list_remove(&list, 0);
|
||||
result = result && node == &n2 && node->string == &s2 && wapp_str8_equal(node->string, &s2) && list.total_size == 3 && list.node_count == 3;
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &n2 && node->item == &s2 && wapp_str8_equal(node->item, &s2) && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3;
|
||||
|
||||
node = wapp_str8_list_remove(&list, 0);
|
||||
result = result && node == &n3 && node->string == &s3 && wapp_str8_equal(node->string, &s3) && list.total_size == 2 && list.node_count == 2;
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &n3 && node->item == &s3 && wapp_str8_equal(node->item, &s3) && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
|
||||
|
||||
node = wapp_str8_list_remove(&list, 0);
|
||||
result = result && node == &n4 && node->string == &s4 && wapp_str8_equal(node->string, &s4) && list.total_size == 1 && list.node_count == 1;
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &n4 && node->item == &s4 && wapp_str8_equal(node->item, &s4) && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
|
||||
|
||||
node = wapp_str8_list_remove(&list, 0);
|
||||
result = result && node == &n5 && node->string == &s5 && wapp_str8_equal(node->string, &s5) && list.total_size == 0 && list.node_count == 0;
|
||||
node = wapp_dbl_list_remove(Str8, &list, 0);
|
||||
result = result && node == &n5 && node->item == &s5 && wapp_str8_equal(node->item, &s5) && wapp_str8_list_total_size(&list) == 0 && list.node_count == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
@@ -250,15 +249,15 @@ TestFuncResult test_str8_list_remove(void) {
|
||||
TestFuncResult test_str8_list_empty(void) {
|
||||
bool result;
|
||||
|
||||
Str8List list = {0};
|
||||
wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("Hello"));
|
||||
wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("from"));
|
||||
wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("wizapp"));
|
||||
wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("stdlib"));
|
||||
DBL_LIST(Str8) list = {0};
|
||||
wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("Hello"));
|
||||
wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("from"));
|
||||
wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("wizapp"));
|
||||
wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("stdlib"));
|
||||
|
||||
wapp_str8_list_empty(&list);
|
||||
wapp_dbl_list_empty(&list);
|
||||
|
||||
result = list.first == NULL && list.last == NULL && list.node_count == 0 && list.total_size == 0;
|
||||
result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0;
|
||||
|
||||
return wapp_tester_result(result);
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#ifndef TEST_STR8_LIST_H
|
||||
#define TEST_STR8_LIST_H
|
||||
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
BEGIN_C_LINKAGE
|
||||
|
@@ -4,7 +4,7 @@
|
||||
#include "test_arena.h"
|
||||
#include "test_cpath.h"
|
||||
#include "test_shell_commander.h"
|
||||
#include "tester.h"
|
||||
#include "wapp.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
|
Reference in New Issue
Block a user