Compare commits

..

13 Commits

Author SHA1 Message Date
50e23d8a13 Testing ideas for array implementation 2025-04-20 00:21:22 +01:00
3a49dba366 Generate dbl_list for default C types 2025-04-19 22:17:26 +01:00
1cfc52b35e Handle pointer types properly in dbl_list codegen 2025-04-19 21:27:00 +01:00
25395553d7 Fix codegen hidden bugs 2025-04-19 21:11:10 +01:00
9a651665ba Remove forward declaration from dbl_list source 2025-04-19 20:56:15 +01:00
8dbdfa2094 Update dbl_list codegen 2025-04-19 20:54:04 +01:00
add2ba541d Merge branch 'codegen' 2025-04-19 13:52:27 +01:00
63ed2633ea Update code generation to create one file for dbl_list 2025-04-19 13:33:09 +01:00
Abdelrahman Said
3c32b247c0 Upgrade codegen 2025-04-17 09:03:30 +01:00
Abdelrahman Said
aa04fab6ea Update codegen 2025-04-16 10:05:42 +01:00
Abdelrahman Said
2017f6de79 Start updating code for new Str8List 2025-04-16 08:14:02 +01:00
Abdelrahman Said
63acdd1336 Fix codegen bugs 2025-04-16 08:13:31 +01:00
Abdelrahman Said
cfa8094260 Fix codegen hidden bugs 2025-04-16 08:06:05 +01:00
34 changed files with 5363 additions and 317 deletions

View File

@ -24,9 +24,9 @@ ifeq ($(CC),gcc)
export ASAN_OPTIONS=verify_asan_link_order=0 export ASAN_OPTIONS=verify_asan_link_order=0
endif endif
.PHONY: all clean builddir build-test run-test build-lib full prng testing uuid core containers .PHONY: all clean builddir build-test run-test codegen build-lib full prng testing uuid core containers
all: clean builddir run-test full all: clean builddir codegen run-test full
clean: clean:
@rm -rf $(BUILD_DIR) @rm -rf $(BUILD_DIR)
@ -41,6 +41,9 @@ run-test: build-test
@$(TEST_OUT) @$(TEST_OUT)
@rm $(TEST_OUT) @rm $(TEST_OUT)
codegen:
python3 -m codegen
build-lib: build-lib:
$(CC) $(CFLAGS) $(LIBFLAGS) $(LIB_SRC) -o $(LIB_OUT) $(CC) $(CFLAGS) $(LIBFLAGS) $(LIB_SRC) -o $(LIB_OUT)

15
codegen/__main__.py Normal file
View File

@ -0,0 +1,15 @@
from codegen.datatypes import CDataType
from codegen.dbl_list.make_dbl_list import DblListData, make_dbl_list
def main():
gen_dbl_list()
def gen_dbl_list():
datatypes: dict[CDataType, DblListData] = {}
make_dbl_list(datatypes)
if __name__ == "__main__":
main()

5
codegen/constants.py Normal file
View File

@ -0,0 +1,5 @@
from pathlib import Path
PACKAGE_DIR = Path(__file__).parent.resolve()
WAPP_SRC_ROOT = PACKAGE_DIR.parent / "src"

343
codegen/datatypes.py Normal file
View File

@ -0,0 +1,343 @@
from enum import Enum
from pathlib import Path
from typing import Optional, Union
from dataclasses import dataclass, field
class CType(Enum):
VOID = "void"
BOOL = "bool"
CHAR = "char"
C8 = "c8"
C16 = "c16"
C32 = "c32"
I8 = "i8"
I16 = "i16"
I32 = "i32"
I64 = "i64"
U8 = "u8"
U16 = "u16"
U32 = "u32"
U64 = "u64"
F32 = "f32"
F64 = "f64"
F128 = "f128"
IPTR = "iptr"
UPTR = "uptr"
def __str__(self) -> str:
return self.value
class CQualifier(Enum):
NONE = ""
CONST = "const "
EXTERNAL = "external "
INTERNAL = "internal "
PERSISTENT = "persistent "
def __str__(self) -> str:
return self.value
class CPointerType(Enum):
NONE = ""
SINGLE = "*"
DOUBLE = "**"
def __str__(self) -> str:
return self.value
@dataclass
class CPointer:
_type: CPointerType = CPointerType.NONE
qualifier: CQualifier = CQualifier.NONE
def __str__(self) -> str:
return str(self._type) + str(self.qualifier)
@dataclass
class CEnumVal:
name: str
value: Optional[int] = None
def __str__(self) -> str:
return self.name + "" if self.value is None else f" = {self.value}"
@dataclass
class CEnum:
name: str
values: list[CEnumVal]
typedef: bool = False
def __str__(self) -> str:
if self.typedef:
header = "typedef enum {\n"
footer = f"}} {self.name};\n"
else:
header = f"enum {self.name} {{\n"
footer = "};\n"
values = ""
for value in self.values:
values += f" {str(value)},\n"
return header + values + footer
@dataclass
class CMacro:
name: str
value: str
def __str__(self) -> str:
return f"#define {self.name} {self.value}\n"
@dataclass
class CStruct:
name: str
cargs: list["CArg"]
typedef_name: str | None = None
def __str__(self) -> str:
return self.declare() + self.define()
def declare(self) -> str:
declaration = f"typedef struct {self.name} {self.typedef_name if self.typedef_name is not None else self.name};\n"
return declaration
def define(self):
definition = f"struct {self.name} {{\n"
args = ""
for arg in self.cargs:
args += f" {str(arg)};\n"
footer = "};\n"
return definition + args + footer;
CUserType = Union[CStruct, CEnum]
CDataType = Union[CType, CUserType, str]
@dataclass
class CArg:
name: str
_type: CDataType
array: bool = False
pointer: CPointer = field(default_factory=CPointer)
qualifier: CQualifier = CQualifier.NONE
def __str__(self) -> str:
qualifier = str(self.qualifier)
_type = get_datatype_string(self._type) + " "
pointer = str(self.pointer)
array = "[]" if self.array else ""
return qualifier + _type + pointer + self.name + array
@dataclass
class CFunc:
name: str
ret_type: CDataType
args: list[CArg]
body: str
pointer: CPointer = field(default_factory=CPointer)
qualifiers: list[CQualifier] = field(default_factory=list)
def __str__(self) -> str:
qualifiers = ""
for qualifier in self.qualifiers:
if qualifier == CQualifier.NONE:
continue
if len(qualifiers) > 0:
qualifiers += " "
qualifiers += f"{str(qualifier)}"
args = ""
for i, arg in enumerate(self.args):
args += f"{str(arg)}"
if i + 1 < len(self.args):
args += ", "
return qualifiers + get_datatype_string(self.ret_type) + " " + str(self.pointer) + self.name + f"({args})"
def declare(self) -> str:
return f"{str(self)};\n"
def define(self) -> str:
return f"{str(self)} {{\n{self.body}\n}}\n\n"
@dataclass
class CInclude:
header: Union[str, "CHeader"]
local: bool = False
same_dir: bool = False
def __str__(self) -> str:
if isinstance(self.header, CHeader):
name = f"{self.header.name}.{self.header.extension}"
else:
name = self.header
if self.local:
open_symbol = '"'
close_symbol = '"'
if self.same_dir:
name = f"./{name}"
else:
open_symbol = '<'
close_symbol = '>'
return f"#include {open_symbol}{name}{close_symbol}\n"
@dataclass
class CFile:
name: str
extension: str
decl_types: list[CStruct] = field(default_factory=list)
macros: list[CMacro] = field(default_factory=list)
def save(self, output_dir: Path):
output_file = output_dir / f"{self.name}.{self.extension}"
with open(output_file, "w+") as outfile:
outfile.write(str(self))
def __str__(self) -> str:
return """\
/**
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
*/
"""
@dataclass
class CHeader(CFile):
extension: str = "h"
includes: list[CInclude] = field(default_factory=list)
types: list[CUserType] = field(default_factory=list)
funcs: list[CFunc] = field(default_factory=list)
def __str__(self) -> str:
name_upper = self.name.upper()
header_guard_name = f"{name_upper}_H"
header_guard_open = f"#ifndef {header_guard_name}\n#define {header_guard_name}\n\n"
header_guard_close = f"#endif // !{header_guard_name}\n"
c_linkage_open = "#ifdef __cplusplus\nBEGIN_C_LINKAGE\n#endif // !__cplusplus\n\n"
c_linkage_close = "\n#ifdef __cplusplus\nEND_C_LINKAGE\n#endif // !__cplusplus\n\n"
includes = _get_includes_string(self.includes)
macros = ""
for macro in self.macros:
macros += str(macro)
if len(macros) > 0:
macros += "\n"
forward_declarations = ""
for _type in self.decl_types:
forward_declarations += _type.declare()
if len(forward_declarations) > 0:
forward_declarations += "\n"
types = ""
for _type in self.types:
types += str(_type) + "\n"
funcs = ""
for func in self.funcs:
funcs += func.declare()
return (
super().__str__() +
header_guard_open +
includes +
c_linkage_open +
macros +
forward_declarations +
types +
funcs +
c_linkage_close +
header_guard_close
)
@dataclass
class CSource(CFile):
extension: str = "c"
includes: list[CInclude] = field(default_factory=list)
types: list[CUserType] = field(default_factory=list)
internal_funcs: list[CFunc] = field(default_factory=list)
funcs: list[CFunc] = field(default_factory=list)
def __str__(self) -> str:
includes = _get_includes_string(self.includes)
macros = ""
for macro in self.macros:
macros += str(macro)
if len(macros) > 0:
macros += "\n"
forward_declarations = ""
for _type in self.decl_types:
forward_declarations += _type.declare()
if len(forward_declarations) > 0:
forward_declarations += "\n"
types = ""
for _type in self.types:
types += str(_type) + "\n"
internal_funcs_decl = ""
internal_funcs_def = ""
for func in self.internal_funcs:
internal_funcs_decl += func.declare()
internal_funcs_def += func.define()
if len(internal_funcs_decl) > 0:
internal_funcs_decl += "\n"
funcs = ""
for func in self.funcs:
funcs += func.define()
return (
super().__str__() +
includes +
macros +
forward_declarations +
types +
internal_funcs_decl +
funcs +
internal_funcs_def
)
def get_datatype_string(_type: CDataType) -> str:
if isinstance(_type, CType):
return str(_type)
elif isinstance(_type, CStruct) or isinstance(_type, CEnum):
return _type.name
elif isinstance(_type, str):
return _type
def _get_includes_string(includes: list[CInclude]) -> str:
output = ""
for include in sorted(includes, key=lambda inc: inc.local, reverse=True):
output += str(include)
if len(output) > 0:
output += "\n"
return output

View File

@ -0,0 +1,332 @@
from pathlib import Path
from dataclasses import dataclass, field
from codegen.constants import WAPP_SRC_ROOT
from codegen.utils import load_func_body_from_file
from codegen.datatypes import (
CDataType,
CMacro,
CStruct,
CFunc,
CHeader,
CSource,
CArg,
CType,
CPointer,
CPointerType,
CQualifier,
CInclude,
get_datatype_string,
)
@dataclass
class DblListData:
node_typename: str
list_typename: str
hdr_decl_types: list[CStruct] = field(default_factory=list)
src_decl_types: list[CStruct] = field(default_factory=list)
def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}):
def __format_func_body(
filename: Path,
type_string: str,
type_string_upper: str,
type_string_lower: str,
node_typename: str,
list_typename: str
):
return load_func_body_from_file(filename).format(
T=type_string,
NodeType=node_typename,
ListType=list_typename,
Tupper=type_string_upper,
Tlower=type_string_lower,
)
out_dir = WAPP_SRC_ROOT / "containers" / "dbl_list"
out_dir.mkdir(parents=True, exist_ok=True)
common_local_include_files = [
(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h")
]
common_includes: list[CInclude] = [
CInclude(header="stdbool.h")
]
for local_file in common_local_include_files:
common_includes.append(
CInclude(
header=str(local_file.relative_to(out_dir, walk_up=True)),
local=True,
)
)
common_decl_types: list[CStruct] = []
datatypes: dict[CDataType, DblListData] = {
"Str8": DblListData(
node_typename="Str8Node",
list_typename="Str8List",
hdr_decl_types=[
CStruct(name="str8", cargs=[], typedef_name="Str8"),
],
),
}
for _type in CType:
if _type == CType.VOID:
datatypes["void *"] = DblListData(
node_typename="VoidPNode",
list_typename="VoidPList",
)
continue
elif _type == CType.BOOL:
datatypes[_type.value] = DblListData(
node_typename="BoolNode",
list_typename="BoolList",
)
continue
type_title = _type.value.title()
datatypes[_type.value] = DblListData(
node_typename=f"{type_title}Node",
list_typename=f"{type_title}List",
)
datatypes.update(user_datatypes)
snippets_dir = Path(__file__).parent / "snippets"
header = CHeader(
name="dbl_list",
decl_types=[*common_decl_types],
includes=[],
types=[],
funcs=[]
)
source = CSource(
name=header.name,
decl_types=[*common_decl_types],
includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")],
internal_funcs=[],
funcs=header.funcs
)
if len(common_includes) > 0:
header.includes.extend(common_includes)
source.includes.extend(common_includes)
for _type, dbl_list_data in datatypes.items():
type_string = get_datatype_string(_type)
clean_type_string = type_string.replace(" ", "").replace("*", "_ptr")
type_string_upper = clean_type_string.upper()
type_string_lower = clean_type_string.lower()
node = CStruct(
name=dbl_list_data.node_typename,
cargs=[
CArg(name="item", _type=type_string, pointer=CPointer(_type=CPointerType.SINGLE)),
],
)
node.cargs.extend([
CArg(name="prev", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
CArg(name="next", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
])
dl_list = CStruct(
name=dbl_list_data.list_typename,
cargs=[
CArg(name="first", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
CArg(name="last", _type=node, pointer=CPointer(_type=CPointerType.SINGLE)),
CArg(name="node_count", _type=CType.U64),
],
)
node_macro = CMacro(
name=f"wapp_{type_string_lower}_list_node(ITEM_PTR)",
value=__format_func_body(
filename=snippets_dir / "list_node",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
)
get_func = CFunc(
name=f"wapp_{type_string_lower}_list_get",
ret_type=node,
args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE), qualifier=CQualifier.CONST),
CArg(name="index", _type=CType.U64),
],
body=__format_func_body(
filename=snippets_dir / "list_get",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
pointer=CPointer(CPointerType.SINGLE),
)
push_front_func = CFunc(
name=f"wapp_{type_string_lower}_list_push_front",
ret_type=CType.VOID,
args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)),
],
body=__format_func_body(
filename=snippets_dir / "list_push_front",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
)
push_back_func = CFunc(
name=f"wapp_{type_string_lower}_list_push_back",
ret_type=CType.VOID,
args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)),
],
body=__format_func_body(
filename=snippets_dir / "list_push_back",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
)
insert_func = CFunc(
name=f"wapp_{type_string_lower}_list_insert",
ret_type=CType.VOID,
args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="index", _type=CType.U64),
],
body=__format_func_body(
filename=snippets_dir / "list_insert",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
)
pop_front_func = CFunc(
name=f"wapp_{type_string_lower}_list_pop_front",
ret_type=node,
args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
],
body=__format_func_body(
filename=snippets_dir / "list_pop_front",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
pointer=CPointer(CPointerType.SINGLE),
)
pop_back_func = CFunc(
name=f"wapp_{type_string_lower}_list_pop_back",
ret_type=node,
args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
],
body=__format_func_body(
filename=snippets_dir / "list_pop_back",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
pointer=CPointer(CPointerType.SINGLE),
)
remove_func = CFunc(
name=f"wapp_{type_string_lower}_list_remove",
ret_type=node,
args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
CArg(name="index", _type=CType.U64),
],
body=__format_func_body(
filename=snippets_dir / "list_remove",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
pointer=CPointer(CPointerType.SINGLE),
)
empty_func = CFunc(
name=f"wapp_{type_string_lower}_list_empty",
ret_type=CType.VOID,
args=[
CArg(name="list", _type=dl_list, pointer=CPointer(CPointerType.SINGLE)),
],
body=__format_func_body(
filename=snippets_dir / "list_empty",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
)
node_to_list_func = CFunc(
name=f"{type_string_lower}_node_to_list",
ret_type=dl_list,
args=[
CArg(name="node", _type=node, pointer=CPointer(CPointerType.SINGLE)),
],
body=__format_func_body(
filename=snippets_dir / "node_to_list",
type_string=type_string,
type_string_upper=type_string_upper,
type_string_lower=type_string_lower,
node_typename=dbl_list_data.node_typename,
list_typename=dbl_list_data.list_typename
),
qualifiers=[CQualifier.INTERNAL],
)
header.decl_types.extend(dbl_list_data.hdr_decl_types)
header.macros.append(node_macro)
header.types.extend([node, dl_list])
header.funcs.extend([
get_func,
push_front_func,
push_back_func,
insert_func,
pop_front_func,
pop_back_func,
remove_func,
empty_func,
])
source.decl_types.extend(dbl_list_data.src_decl_types)
source.internal_funcs.append(node_to_list_func)
source.funcs = header.funcs
header.save(out_dir)
source.save(out_dir)

View File

@ -0,0 +1,8 @@
if (!list) {{
return;
}}
u64 count = list->node_count;
for (u64 i = 0; i < count; ++i) {{
wapp_{Tlower}_list_pop_back(list);
}}

View File

@ -0,0 +1,13 @@
if (index >= list->node_count) {{
return NULL;
}}
{NodeType} *output = NULL;
{NodeType} *current = list->first;
for (u64 i = 1; i <= index; ++i) {{
current = current->next;
}}
output = current;
return output;

View File

@ -0,0 +1,28 @@
if (!list || !node || !(node->item)) {{
return;
}}
if (index == 0) {{
wapp_{Tlower}_list_push_front(list, node);
return;
}} else if (index == list->node_count) {{
wapp_{Tlower}_list_push_back(list, node);
return;
}}
{NodeType} *dst_node = wapp_{Tlower}_list_get(list, index);
if (!dst_node) {{
return;
}}
{ListType} node_list = {Tlower}_node_to_list(node);
list->node_count += node_list.node_count;
{NodeType} *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;

View File

@ -0,0 +1 @@
(({NodeType}){{.item = ITEM_PTR}})

View File

@ -0,0 +1,20 @@
{NodeType} *output = NULL;
if (!list || list->node_count == 0) {{
goto RETURN_{Tupper}_LIST_POP_BACK;
}}
output = list->last;
if (list->node_count == 1) {{
*list = ({ListType}){{0}};
goto RETURN_{Tupper}_LIST_POP_BACK;
}}
--(list->node_count);
list->last = output->prev;
output->prev = output->next = NULL;
RETURN_{Tupper}_LIST_POP_BACK:
return output;

View File

@ -0,0 +1,20 @@
{NodeType} *output = NULL;
if (!list || list->node_count == 0) {{
goto RETURN_{Tupper}_LIST_POP_FRONT;
}}
output = list->first;
if (list->node_count == 1) {{
*list = ({ListType}){{0}};
goto RETURN_{Tupper}_LIST_POP_FRONT;
}}
--(list->node_count);
list->first = output->next;
output->prev = output->next = NULL;
RETURN_{Tupper}_LIST_POP_FRONT:
return output;

View File

@ -0,0 +1,20 @@
if (!list || !node || !(node->item)) {{
return;
}}
{ListType} node_list = {Tlower}_node_to_list(node);
if (list->node_count == 0) {{
*list = node_list;
return;
}}
list->node_count += node_list.node_count;
{NodeType} *last = list->last;
if (last) {{
last->next = node_list.first;
}}
list->last = node_list.last;
node_list.first->prev = last;

View File

@ -0,0 +1,20 @@
if (!list || !node || !(node->item)) {{
return;
}}
{ListType} node_list = {Tlower}_node_to_list(node);
if (list->node_count == 0) {{
*list = node_list;
return;
}}
list->node_count += node_list.node_count;
{NodeType} *first = list->first;
if (first) {{
first->prev = node_list.last;
}}
list->first = node_list.first;
node_list.last->next = first;

View File

@ -0,0 +1,27 @@
{NodeType} *output = NULL;
if (!list) {{
goto RETURN_{Tupper}_LIST_REMOVE;
}}
if (index == 0) {{
output = wapp_{Tlower}_list_pop_front(list);
goto RETURN_{Tupper}_LIST_REMOVE;
}} else if (index == list->node_count) {{
output = wapp_{Tlower}_list_pop_back(list);
goto RETURN_{Tupper}_LIST_REMOVE;
}}
output = wapp_{Tlower}_list_get(list, index);
if (!output) {{
goto RETURN_{Tupper}_LIST_REMOVE;
}}
output->prev->next = output->next;
output->next->prev = output->prev;
--(list->node_count);
output->prev = output->next = NULL;
RETURN_{Tupper}_LIST_REMOVE:
return output;

View File

@ -0,0 +1,13 @@
{ListType} 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;

6
codegen/utils.py Normal file
View File

@ -0,0 +1,6 @@
from pathlib import Path
def load_func_body_from_file(filename: Path) -> str:
with open(filename, "r") as infile:
return infile.read().rstrip()

View File

@ -0,0 +1,52 @@
#ifndef ARRAY_H
#define ARRAY_H
#include "../../common/aliases/aliases.h"
#ifdef __cplusplus
BEGIN_C_LINKAGE
#endif // !__cplusplus
typedef struct int_array IntArray;
struct int_array {
int *items;
u64 count;
u64 capacity;
};
#define U64_RSHIFT_OR_1(X) (((u64)X) | (((u64)X) >> 1))
#define U64_RSHIFT_OR_2(X) (((u64)X) | (((u64)X) >> 2))
#define U64_RSHIFT_OR_4(X) (((u64)X) | (((u64)X) >> 4))
#define U64_RSHIFT_OR_8(X) (((u64)X) | (((u64)X) >> 8))
#define U64_RSHIFT_OR_16(X) (((u64)X) | (((u64)X) >> 16))
#define U64_RSHIFT_OR_32(X) (((u64)X) | (((u64)X) >> 32))
#define U64_ROUND_UP_POW2(X) ( \
( \
U64_RSHIFT_OR_32( \
U64_RSHIFT_OR_16( \
U64_RSHIFT_OR_8( \
U64_RSHIFT_OR_4( \
U64_RSHIFT_OR_2( \
U64_RSHIFT_OR_1(X - 1) \
) \
) \
) \
) \
) \
) + 1 \
)
#define INT_ARRAY_COUNT_ARGS(...) (sizeof((int[]){__VA_ARGS__})/sizeof(int))
#define wapp_int_array(...) ((IntArray){ \
.items = (int[U64_ROUND_UP_POW2(INT_ARRAY_COUNT_ARGS(__VA_ARGS__) * 2)]){__VA_ARGS__}, \
.count = INT_ARRAY_COUNT_ARGS(__VA_ARGS__), \
.capacity = U64_ROUND_UP_POW2(INT_ARRAY_COUNT_ARGS(__VA_ARGS__) * 2) \
})
#define wapp_int_array_with_capacity(CAPACITY) ((IntArray){.items = (int[CAPACITY]){0}, .count = 0, .capacity = CAPACITY})
#ifdef __cplusplus
END_C_LINKAGE
#endif // !__cplusplus
#endif // !ARRAY_H

File diff suppressed because it is too large Load Diff

View File

@ -1,72 +1,480 @@
/**
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
*/
#ifndef DBL_LIST_H #ifndef DBL_LIST_H
#define DBL_LIST_H #define DBL_LIST_H
#include "../../common/aliases/aliases.h" #include "../../common/aliases/aliases.h"
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
BEGIN_C_LINKAGE BEGIN_C_LINKAGE
#endif // !__cplusplus #endif // !__cplusplus
#define DBL_NODE(T) T##Node #define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
#define DBL_LIST(T) T##List #define wapp_void_ptr_list_node(ITEM_PTR) ((VoidPNode){.item = ITEM_PTR})
#define wapp_bool_list_node(ITEM_PTR) ((BoolNode){.item = ITEM_PTR})
#define wapp_char_list_node(ITEM_PTR) ((CharNode){.item = ITEM_PTR})
#define wapp_c8_list_node(ITEM_PTR) ((C8Node){.item = ITEM_PTR})
#define wapp_c16_list_node(ITEM_PTR) ((C16Node){.item = ITEM_PTR})
#define wapp_c32_list_node(ITEM_PTR) ((C32Node){.item = ITEM_PTR})
#define wapp_i8_list_node(ITEM_PTR) ((I8Node){.item = ITEM_PTR})
#define wapp_i16_list_node(ITEM_PTR) ((I16Node){.item = ITEM_PTR})
#define wapp_i32_list_node(ITEM_PTR) ((I32Node){.item = ITEM_PTR})
#define wapp_i64_list_node(ITEM_PTR) ((I64Node){.item = ITEM_PTR})
#define wapp_u8_list_node(ITEM_PTR) ((U8Node){.item = ITEM_PTR})
#define wapp_u16_list_node(ITEM_PTR) ((U16Node){.item = ITEM_PTR})
#define wapp_u32_list_node(ITEM_PTR) ((U32Node){.item = ITEM_PTR})
#define wapp_u64_list_node(ITEM_PTR) ((U64Node){.item = ITEM_PTR})
#define wapp_f32_list_node(ITEM_PTR) ((F32Node){.item = ITEM_PTR})
#define wapp_f64_list_node(ITEM_PTR) ((F64Node){.item = ITEM_PTR})
#define wapp_f128_list_node(ITEM_PTR) ((F128Node){.item = ITEM_PTR})
#define wapp_iptr_list_node(ITEM_PTR) ((IptrNode){.item = ITEM_PTR})
#define wapp_uptr_list_node(ITEM_PTR) ((UptrNode){.item = ITEM_PTR})
#define CAST_NODE(NODE) ((DBL_NODE(void))(NODE)) typedef struct str8 Str8;
#define CAST_LIST(LIST) ((DBL_LIST(void))(LIST))
#define CAST_NODE_PTR(NODE_PTR) ((DBL_NODE(void)*)(NODE_PTR)) typedef struct Str8Node Str8Node;
#define CAST_LIST_PTR(LIST_PTR) ((DBL_LIST(void)*)(LIST_PTR)) struct Str8Node {
Str8 *item;
Str8Node *prev;
Str8Node *next;
};
#define DBL_LIST_DECL(T) typedef struct DBL_NODE(T) DBL_NODE(T); \ typedef struct Str8List Str8List;
struct DBL_NODE(T) { \ struct Str8List {
T *item; \ Str8Node *first;
DBL_NODE(T) *prev; \ Str8Node *last;
DBL_NODE(T) *next; \ u64 node_count;
}; \ };
\
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); typedef struct VoidPNode VoidPNode;
struct VoidPNode {
void * *item;
VoidPNode *prev;
VoidPNode *next;
};
#define wapp_dbl_list_node_from_item(T, ITEM_PTR) \ typedef struct VoidPList VoidPList;
((DBL_NODE(T)){ .item = ITEM_PTR }) struct VoidPList {
VoidPNode *first;
VoidPNode *last;
u64 node_count;
};
#define wapp_dbl_list_get(T, LIST_PTR, INDEX) \ typedef struct BoolNode BoolNode;
(DBL_NODE(T)*)_dbl_list_get(CAST_LIST_PTR(LIST_PTR), INDEX) struct BoolNode {
bool *item;
BoolNode *prev;
BoolNode *next;
};
#define wapp_dbl_list_push_front(LIST_PTR, NODE_PTR) \ typedef struct BoolList BoolList;
_dbl_list_push_front(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR)) struct BoolList {
BoolNode *first;
BoolNode *last;
u64 node_count;
};
#define wapp_dbl_list_push_back(LIST_PTR, NODE_PTR) \ typedef struct CharNode CharNode;
_dbl_list_push_back(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR)) struct CharNode {
char *item;
CharNode *prev;
CharNode *next;
};
#define wapp_dbl_list_insert(LIST_PTR, NODE_PTR, INDEX) \ typedef struct CharList CharList;
_dbl_list_insert(CAST_LIST_PTR(LIST_PTR), CAST_NODE_PTR(NODE_PTR), INDEX) struct CharList {
CharNode *first;
CharNode *last;
u64 node_count;
};
#define wapp_dbl_list_pop_front(T, LIST_PTR) \ typedef struct C8Node C8Node;
(DBL_NODE(T)*)_dbl_list_pop_front(CAST_LIST_PTR(LIST_PTR)) struct C8Node {
c8 *item;
C8Node *prev;
C8Node *next;
};
#define wapp_dbl_list_pop_back(T, LIST_PTR) \ typedef struct C8List C8List;
(DBL_NODE(T)*)_dbl_list_pop_back(CAST_LIST_PTR(LIST_PTR)) struct C8List {
C8Node *first;
C8Node *last;
u64 node_count;
};
#define wapp_dbl_list_remove(T, LIST_PTR, INDEX) \ typedef struct C16Node C16Node;
(DBL_NODE(T)*)_dbl_list_remove(CAST_LIST_PTR(LIST_PTR), INDEX) struct C16Node {
c16 *item;
C16Node *prev;
C16Node *next;
};
#define wapp_dbl_list_empty(LIST_PTR) \ typedef struct C16List C16List;
_dbl_list_empty(CAST_LIST_PTR(LIST_PTR)) struct C16List {
C16Node *first;
C16Node *last;
u64 node_count;
};
DBL_NODE(void) *_dbl_list_get(const DBL_LIST(void) *list, u64 index); typedef struct C32Node C32Node;
void _dbl_list_push_front(DBL_LIST(void) *list, DBL_NODE(void) *node); struct C32Node {
void _dbl_list_push_back(DBL_LIST(void) *list, DBL_NODE(void) *node); c32 *item;
void _dbl_list_insert(DBL_LIST(void) *list, DBL_NODE(void) *node, u64 index); C32Node *prev;
DBL_NODE(void) *_dbl_list_pop_front(DBL_LIST(void) *list); C32Node *next;
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); typedef struct C32List C32List;
struct C32List {
C32Node *first;
C32Node *last;
u64 node_count;
};
typedef struct I8Node I8Node;
struct I8Node {
i8 *item;
I8Node *prev;
I8Node *next;
};
typedef struct I8List I8List;
struct I8List {
I8Node *first;
I8Node *last;
u64 node_count;
};
typedef struct I16Node I16Node;
struct I16Node {
i16 *item;
I16Node *prev;
I16Node *next;
};
typedef struct I16List I16List;
struct I16List {
I16Node *first;
I16Node *last;
u64 node_count;
};
typedef struct I32Node I32Node;
struct I32Node {
i32 *item;
I32Node *prev;
I32Node *next;
};
typedef struct I32List I32List;
struct I32List {
I32Node *first;
I32Node *last;
u64 node_count;
};
typedef struct I64Node I64Node;
struct I64Node {
i64 *item;
I64Node *prev;
I64Node *next;
};
typedef struct I64List I64List;
struct I64List {
I64Node *first;
I64Node *last;
u64 node_count;
};
typedef struct U8Node U8Node;
struct U8Node {
u8 *item;
U8Node *prev;
U8Node *next;
};
typedef struct U8List U8List;
struct U8List {
U8Node *first;
U8Node *last;
u64 node_count;
};
typedef struct U16Node U16Node;
struct U16Node {
u16 *item;
U16Node *prev;
U16Node *next;
};
typedef struct U16List U16List;
struct U16List {
U16Node *first;
U16Node *last;
u64 node_count;
};
typedef struct U32Node U32Node;
struct U32Node {
u32 *item;
U32Node *prev;
U32Node *next;
};
typedef struct U32List U32List;
struct U32List {
U32Node *first;
U32Node *last;
u64 node_count;
};
typedef struct U64Node U64Node;
struct U64Node {
u64 *item;
U64Node *prev;
U64Node *next;
};
typedef struct U64List U64List;
struct U64List {
U64Node *first;
U64Node *last;
u64 node_count;
};
typedef struct F32Node F32Node;
struct F32Node {
f32 *item;
F32Node *prev;
F32Node *next;
};
typedef struct F32List F32List;
struct F32List {
F32Node *first;
F32Node *last;
u64 node_count;
};
typedef struct F64Node F64Node;
struct F64Node {
f64 *item;
F64Node *prev;
F64Node *next;
};
typedef struct F64List F64List;
struct F64List {
F64Node *first;
F64Node *last;
u64 node_count;
};
typedef struct F128Node F128Node;
struct F128Node {
f128 *item;
F128Node *prev;
F128Node *next;
};
typedef struct F128List F128List;
struct F128List {
F128Node *first;
F128Node *last;
u64 node_count;
};
typedef struct IptrNode IptrNode;
struct IptrNode {
iptr *item;
IptrNode *prev;
IptrNode *next;
};
typedef struct IptrList IptrList;
struct IptrList {
IptrNode *first;
IptrNode *last;
u64 node_count;
};
typedef struct UptrNode UptrNode;
struct UptrNode {
uptr *item;
UptrNode *prev;
UptrNode *next;
};
typedef struct UptrList UptrList;
struct UptrList {
UptrNode *first;
UptrNode *last;
u64 node_count;
};
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);
VoidPNode *wapp_void_ptr_list_get(const VoidPList *list, u64 index);
void wapp_void_ptr_list_push_front(VoidPList *list, VoidPNode *node);
void wapp_void_ptr_list_push_back(VoidPList *list, VoidPNode *node);
void wapp_void_ptr_list_insert(VoidPList *list, VoidPNode *node, u64 index);
VoidPNode *wapp_void_ptr_list_pop_front(VoidPList *list);
VoidPNode *wapp_void_ptr_list_pop_back(VoidPList *list);
VoidPNode *wapp_void_ptr_list_remove(VoidPList *list, u64 index);
void wapp_void_ptr_list_empty(VoidPList *list);
BoolNode *wapp_bool_list_get(const BoolList *list, u64 index);
void wapp_bool_list_push_front(BoolList *list, BoolNode *node);
void wapp_bool_list_push_back(BoolList *list, BoolNode *node);
void wapp_bool_list_insert(BoolList *list, BoolNode *node, u64 index);
BoolNode *wapp_bool_list_pop_front(BoolList *list);
BoolNode *wapp_bool_list_pop_back(BoolList *list);
BoolNode *wapp_bool_list_remove(BoolList *list, u64 index);
void wapp_bool_list_empty(BoolList *list);
CharNode *wapp_char_list_get(const CharList *list, u64 index);
void wapp_char_list_push_front(CharList *list, CharNode *node);
void wapp_char_list_push_back(CharList *list, CharNode *node);
void wapp_char_list_insert(CharList *list, CharNode *node, u64 index);
CharNode *wapp_char_list_pop_front(CharList *list);
CharNode *wapp_char_list_pop_back(CharList *list);
CharNode *wapp_char_list_remove(CharList *list, u64 index);
void wapp_char_list_empty(CharList *list);
C8Node *wapp_c8_list_get(const C8List *list, u64 index);
void wapp_c8_list_push_front(C8List *list, C8Node *node);
void wapp_c8_list_push_back(C8List *list, C8Node *node);
void wapp_c8_list_insert(C8List *list, C8Node *node, u64 index);
C8Node *wapp_c8_list_pop_front(C8List *list);
C8Node *wapp_c8_list_pop_back(C8List *list);
C8Node *wapp_c8_list_remove(C8List *list, u64 index);
void wapp_c8_list_empty(C8List *list);
C16Node *wapp_c16_list_get(const C16List *list, u64 index);
void wapp_c16_list_push_front(C16List *list, C16Node *node);
void wapp_c16_list_push_back(C16List *list, C16Node *node);
void wapp_c16_list_insert(C16List *list, C16Node *node, u64 index);
C16Node *wapp_c16_list_pop_front(C16List *list);
C16Node *wapp_c16_list_pop_back(C16List *list);
C16Node *wapp_c16_list_remove(C16List *list, u64 index);
void wapp_c16_list_empty(C16List *list);
C32Node *wapp_c32_list_get(const C32List *list, u64 index);
void wapp_c32_list_push_front(C32List *list, C32Node *node);
void wapp_c32_list_push_back(C32List *list, C32Node *node);
void wapp_c32_list_insert(C32List *list, C32Node *node, u64 index);
C32Node *wapp_c32_list_pop_front(C32List *list);
C32Node *wapp_c32_list_pop_back(C32List *list);
C32Node *wapp_c32_list_remove(C32List *list, u64 index);
void wapp_c32_list_empty(C32List *list);
I8Node *wapp_i8_list_get(const I8List *list, u64 index);
void wapp_i8_list_push_front(I8List *list, I8Node *node);
void wapp_i8_list_push_back(I8List *list, I8Node *node);
void wapp_i8_list_insert(I8List *list, I8Node *node, u64 index);
I8Node *wapp_i8_list_pop_front(I8List *list);
I8Node *wapp_i8_list_pop_back(I8List *list);
I8Node *wapp_i8_list_remove(I8List *list, u64 index);
void wapp_i8_list_empty(I8List *list);
I16Node *wapp_i16_list_get(const I16List *list, u64 index);
void wapp_i16_list_push_front(I16List *list, I16Node *node);
void wapp_i16_list_push_back(I16List *list, I16Node *node);
void wapp_i16_list_insert(I16List *list, I16Node *node, u64 index);
I16Node *wapp_i16_list_pop_front(I16List *list);
I16Node *wapp_i16_list_pop_back(I16List *list);
I16Node *wapp_i16_list_remove(I16List *list, u64 index);
void wapp_i16_list_empty(I16List *list);
I32Node *wapp_i32_list_get(const I32List *list, u64 index);
void wapp_i32_list_push_front(I32List *list, I32Node *node);
void wapp_i32_list_push_back(I32List *list, I32Node *node);
void wapp_i32_list_insert(I32List *list, I32Node *node, u64 index);
I32Node *wapp_i32_list_pop_front(I32List *list);
I32Node *wapp_i32_list_pop_back(I32List *list);
I32Node *wapp_i32_list_remove(I32List *list, u64 index);
void wapp_i32_list_empty(I32List *list);
I64Node *wapp_i64_list_get(const I64List *list, u64 index);
void wapp_i64_list_push_front(I64List *list, I64Node *node);
void wapp_i64_list_push_back(I64List *list, I64Node *node);
void wapp_i64_list_insert(I64List *list, I64Node *node, u64 index);
I64Node *wapp_i64_list_pop_front(I64List *list);
I64Node *wapp_i64_list_pop_back(I64List *list);
I64Node *wapp_i64_list_remove(I64List *list, u64 index);
void wapp_i64_list_empty(I64List *list);
U8Node *wapp_u8_list_get(const U8List *list, u64 index);
void wapp_u8_list_push_front(U8List *list, U8Node *node);
void wapp_u8_list_push_back(U8List *list, U8Node *node);
void wapp_u8_list_insert(U8List *list, U8Node *node, u64 index);
U8Node *wapp_u8_list_pop_front(U8List *list);
U8Node *wapp_u8_list_pop_back(U8List *list);
U8Node *wapp_u8_list_remove(U8List *list, u64 index);
void wapp_u8_list_empty(U8List *list);
U16Node *wapp_u16_list_get(const U16List *list, u64 index);
void wapp_u16_list_push_front(U16List *list, U16Node *node);
void wapp_u16_list_push_back(U16List *list, U16Node *node);
void wapp_u16_list_insert(U16List *list, U16Node *node, u64 index);
U16Node *wapp_u16_list_pop_front(U16List *list);
U16Node *wapp_u16_list_pop_back(U16List *list);
U16Node *wapp_u16_list_remove(U16List *list, u64 index);
void wapp_u16_list_empty(U16List *list);
U32Node *wapp_u32_list_get(const U32List *list, u64 index);
void wapp_u32_list_push_front(U32List *list, U32Node *node);
void wapp_u32_list_push_back(U32List *list, U32Node *node);
void wapp_u32_list_insert(U32List *list, U32Node *node, u64 index);
U32Node *wapp_u32_list_pop_front(U32List *list);
U32Node *wapp_u32_list_pop_back(U32List *list);
U32Node *wapp_u32_list_remove(U32List *list, u64 index);
void wapp_u32_list_empty(U32List *list);
U64Node *wapp_u64_list_get(const U64List *list, u64 index);
void wapp_u64_list_push_front(U64List *list, U64Node *node);
void wapp_u64_list_push_back(U64List *list, U64Node *node);
void wapp_u64_list_insert(U64List *list, U64Node *node, u64 index);
U64Node *wapp_u64_list_pop_front(U64List *list);
U64Node *wapp_u64_list_pop_back(U64List *list);
U64Node *wapp_u64_list_remove(U64List *list, u64 index);
void wapp_u64_list_empty(U64List *list);
F32Node *wapp_f32_list_get(const F32List *list, u64 index);
void wapp_f32_list_push_front(F32List *list, F32Node *node);
void wapp_f32_list_push_back(F32List *list, F32Node *node);
void wapp_f32_list_insert(F32List *list, F32Node *node, u64 index);
F32Node *wapp_f32_list_pop_front(F32List *list);
F32Node *wapp_f32_list_pop_back(F32List *list);
F32Node *wapp_f32_list_remove(F32List *list, u64 index);
void wapp_f32_list_empty(F32List *list);
F64Node *wapp_f64_list_get(const F64List *list, u64 index);
void wapp_f64_list_push_front(F64List *list, F64Node *node);
void wapp_f64_list_push_back(F64List *list, F64Node *node);
void wapp_f64_list_insert(F64List *list, F64Node *node, u64 index);
F64Node *wapp_f64_list_pop_front(F64List *list);
F64Node *wapp_f64_list_pop_back(F64List *list);
F64Node *wapp_f64_list_remove(F64List *list, u64 index);
void wapp_f64_list_empty(F64List *list);
F128Node *wapp_f128_list_get(const F128List *list, u64 index);
void wapp_f128_list_push_front(F128List *list, F128Node *node);
void wapp_f128_list_push_back(F128List *list, F128Node *node);
void wapp_f128_list_insert(F128List *list, F128Node *node, u64 index);
F128Node *wapp_f128_list_pop_front(F128List *list);
F128Node *wapp_f128_list_pop_back(F128List *list);
F128Node *wapp_f128_list_remove(F128List *list, u64 index);
void wapp_f128_list_empty(F128List *list);
IptrNode *wapp_iptr_list_get(const IptrList *list, u64 index);
void wapp_iptr_list_push_front(IptrList *list, IptrNode *node);
void wapp_iptr_list_push_back(IptrList *list, IptrNode *node);
void wapp_iptr_list_insert(IptrList *list, IptrNode *node, u64 index);
IptrNode *wapp_iptr_list_pop_front(IptrList *list);
IptrNode *wapp_iptr_list_pop_back(IptrList *list);
IptrNode *wapp_iptr_list_remove(IptrList *list, u64 index);
void wapp_iptr_list_empty(IptrList *list);
UptrNode *wapp_uptr_list_get(const UptrList *list, u64 index);
void wapp_uptr_list_push_front(UptrList *list, UptrNode *node);
void wapp_uptr_list_push_back(UptrList *list, UptrNode *node);
void wapp_uptr_list_insert(UptrList *list, UptrNode *node, u64 index);
UptrNode *wapp_uptr_list_pop_front(UptrList *list);
UptrNode *wapp_uptr_list_pop_back(UptrList *list);
UptrNode *wapp_uptr_list_remove(UptrList *list, u64 index);
void wapp_uptr_list_empty(UptrList *list);
#ifdef __cplusplus #ifdef __cplusplus
END_C_LINKAGE END_C_LINKAGE

View File

@ -2,6 +2,7 @@
#define WAPP_CONTAINERS_H #define WAPP_CONTAINERS_H
#include "dbl_list/dbl_list.h" #include "dbl_list/dbl_list.h"
#include "array/array.h"
#include "../common/wapp_common.h" #include "../common/wapp_common.h"
#endif // !WAPP_CONTAINERS_H #endif // !WAPP_CONTAINERS_H

View File

@ -4,13 +4,13 @@
#include "../../mem/allocator/mem_allocator.h" #include "../../mem/allocator/mem_allocator.h"
#include "../../mem/arena/mem_arena_allocator.h" #include "../../mem/arena/mem_arena_allocator.h"
#include "../../strings/str8/str8.h" #include "../../strings/str8/str8.h"
#include "../../strings/str8/str8_list.h" #include "../../../containers/dbl_list/dbl_list.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) { u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) {
if (!dst || !parts) { if (!dst || !parts) {
return CPATH_JOIN_INVALID_ARGS; return CPATH_JOIN_INVALID_ARGS;
} }
@ -28,12 +28,12 @@ u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) {
} }
// Handle first node // Handle first node
const DBL_NODE(Str8) *first_node = wapp_dbl_list_get(Str8, parts, 0); const Str8Node *first_node = wapp_str8_list_get(parts, 0);
wapp_str8_copy_str8_capped(dst, first_node->item); wapp_str8_copy_str8_capped(dst, first_node->item);
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
const DBL_NODE(Str8) *node = first_node; const Str8Node *node = first_node;
u64 node_index = 1; u64 node_index = 1;
bool running = true; bool running = true;
while (running && node->next) { while (running && node->next) {
@ -91,7 +91,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
goto RETURN_DIRUP; goto RETURN_DIRUP;
} }
DBL_LIST(Str8) *parts = wapp_str8_split(&tmp_arena, path, &separator); Str8List *parts = wapp_str8_split(&tmp_arena, path, &separator);
if (!parts) { if (!parts) {
goto RETURN_DIRUP; goto RETURN_DIRUP;
} }
@ -105,7 +105,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) {
wapp_str8_push_back(output, absolute ? PATH_SEP : '.'); wapp_str8_push_back(output, absolute ? PATH_SEP : '.');
} else { } else {
for (u64 i = 0; i < levels; ++i) { for (u64 i = 0; i < levels; ++i) {
wapp_dbl_list_pop_back(Str8, parts); wapp_str8_list_pop_back(parts);
} }
u64 alignment = sizeof(void *) * 2; u64 alignment = sizeof(void *) * 2;

View File

@ -28,7 +28,7 @@ enum {
CPATH_JOIN_INSUFFICIENT_DST_CAPACITY, CPATH_JOIN_INSUFFICIENT_DST_CAPACITY,
}; };
u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts); u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts);
Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels); Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -4,6 +4,7 @@
#include "../../../mem/allocator/mem_allocator.h" #include "../../../mem/allocator/mem_allocator.h"
#include "../../../mem/arena/mem_arena_allocator.h" #include "../../../mem/arena/mem_arena_allocator.h"
#include "../../../strings/str8/str8.h" #include "../../../strings/str8/str8.h"
#include "../../../../containers/dbl_list/dbl_list.h"
#include "../../../../common/aliases/aliases.h" #include "../../../../common/aliases/aliases.h"
#include "../../../../common/misc/misc_utils.h" #include "../../../../common/misc/misc_utils.h"
#include <stdarg.h> #include <stdarg.h>
@ -18,7 +19,7 @@
internal inline CMDResult execute_command(Str8RO *cmd, CMDOutHandling out_handling, Str8 *out_buf); 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); internal inline CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str8 *out_buf);
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd) { CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd) {
if (!cmd) { if (!cmd) {
return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS); return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS);
} }

View File

@ -14,7 +14,7 @@ BEGIN_C_LINKAGE
#define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR}) #define CMD_NO_EXIT(ERR) ((CMDResult){.exited = false, .exit_code = EXIT_FAILURE, .error = ERR})
CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd); CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd);
external CMDError get_output_status(FILE *fp, i32 *status_out); external CMDError get_output_status(FILE *fp, i32 *status_out);

View File

@ -1,7 +1,5 @@
#include "str8.h" #include "str8.h"
#include "str8_list.h"
#include "../../../common/aliases/aliases.h" #include "../../../common/aliases/aliases.h"
#include "../../../containers/dbl_list/dbl_list.h"
#include "../../mem/allocator/mem_allocator.h" #include "../../mem/allocator/mem_allocator.h"
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
@ -302,19 +300,19 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) {
return -1; return -1;
} }
DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
if (!allocator || !str || !delimiter) { if (!allocator || !str || !delimiter) {
return NULL; return NULL;
} }
DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8))); Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
if (delimiter->size > str->size) { if (delimiter->size > str->size) {
Str8 *full = wapp_str8_alloc_str8(allocator, str); Str8 *full = wapp_str8_alloc_str8(allocator, str);
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node) { if (node) {
node->item = full; node->item = full;
wapp_dbl_list_push_back(output, node); wapp_str8_list_push_back(output, node);
} }
goto RETURN_STR8_SPLIT; goto RETURN_STR8_SPLIT;
@ -332,10 +330,10 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str
} }
before_str = wapp_str8_alloc_substr(allocator, str, start, start + end); before_str = wapp_str8_alloc_substr(allocator, str, start, start + end);
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node) { if (node) {
node->item = before_str; node->item = before_str;
wapp_dbl_list_push_back(output, node); wapp_str8_list_push_back(output, node);
} }
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8)); wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
@ -346,30 +344,30 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str
} }
// Ensure the last part of the string after the delimiter is added to the list // 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); rest = wapp_str8_alloc_substr(allocator, str, start, str->size);
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node) { if (node) {
node->item = rest; node->item = rest;
wapp_dbl_list_push_back(output, node); wapp_str8_list_push_back(output, node);
} }
RETURN_STR8_SPLIT: RETURN_STR8_SPLIT:
return output; return output;
} }
DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) {
if (!allocator || !str || !delimiter) { if (!allocator || !str || !delimiter) {
return NULL; return NULL;
} }
DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8))); Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List));
if (delimiter->size > str->size) { if (delimiter->size > str->size) {
Str8 *full = wapp_str8_alloc_str8(allocator, str); Str8 *full = wapp_str8_alloc_str8(allocator, str);
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node) { if (node) {
node->item = full; node->item = full;
wapp_dbl_list_push_back(output, node); wapp_str8_list_push_back(output, node);
} }
goto RETURN_STR8_SPLIT; goto RETURN_STR8_SPLIT;
@ -386,10 +384,10 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st
} }
after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size); after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size);
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node) { if (node) {
node->item = after_str; node->item = after_str;
wapp_dbl_list_push_front(output, node); wapp_str8_list_push_front(output, node);
} }
wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8)); wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8));
@ -399,17 +397,17 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st
} }
rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size); rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size);
DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node));
if (node) { if (node) {
node->item = rest; node->item = rest;
wapp_dbl_list_push_front(output, node); wapp_str8_list_push_front(output, node);
} }
RETURN_STR8_SPLIT: RETURN_STR8_SPLIT:
return output; return output;
} }
Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str8RO *delimiter) { Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) {
if (!allocator || !list || !delimiter) { if (!allocator || !list || !delimiter) {
return NULL; return NULL;
} }
@ -419,11 +417,11 @@ Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
DBL_NODE(Str8) *node; Str8Node *node;
u64 node_index = 0; u64 node_index = 0;
bool running = true; bool running = true;
while (running) { while (running) {
node = wapp_dbl_list_get(Str8, list, node_index); node = wapp_str8_list_get(list, node_index);
wapp_str8_concat_capped(output, node->item); wapp_str8_concat_capped(output, node->item);
if (node_index + 1 < list->node_count) { if (node_index + 1 < list->node_count) {
wapp_str8_concat_capped(output, delimiter); wapp_str8_concat_capped(output, delimiter);
@ -435,3 +433,17 @@ Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str
return output; return output;
} }
u64 wapp_str8_list_total_size(const Str8List *list) {
if (!list) {
return 0;
}
u64 output = 0;
for (u64 i = 0; i < list->node_count; ++i) {
Str8Node *node = wapp_str8_list_get(list, i);
output += node->item->size;
}
return output;
}

View File

@ -1,7 +1,6 @@
#ifndef STR8_H #ifndef STR8_H
#define STR8_H #define STR8_H
#include "./str8_list.h"
#include "../../../common/aliases/aliases.h" #include "../../../common/aliases/aliases.h"
#include "../../../containers/dbl_list/dbl_list.h" #include "../../../containers/dbl_list/dbl_list.h"
#include "../../mem/allocator/mem_allocator.h" #include "../../mem/allocator/mem_allocator.h"
@ -85,15 +84,16 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr);
*/ */
#define wapp_str8_split(ALLOCATOR, STR, DELIMITER) wapp_str8_split_with_max(ALLOCATOR, STR, DELIMITER, -1) #define wapp_str8_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) #define wapp_str8_rsplit(ALLOCATOR, STR, DELIMITER) wapp_str8_rsplit_with_max(ALLOCATOR, STR, DELIMITER, -1)
DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits); Str8List *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); Str8List *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 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter);
/** /**
* Str8 list utilities * Str8 list utilities
*/ */
#define wapp_str8_node_from_cstr(STRING) wapp_dbl_list_node_from_item(Str8, &wapp_str8_lit(STRING)) #define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node(&wapp_str8_lit(STRING))
#define wapp_str8_node_from_str8(STRING) wapp_dbl_list_node_from_item(Str8, &(STRING)) #define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
u64 wapp_str8_list_total_size(const Str8List *list);
#ifdef __cplusplus #ifdef __cplusplus
END_C_LINKAGE END_C_LINKAGE

View File

@ -1,18 +0,0 @@
#include "./str8_list.h"
#include "./str8.h"
#include "../../../common/aliases/aliases.h"
#include "../../../containers/dbl_list/dbl_list.h"
u64 wapp_str8_list_total_size(const DBL_LIST(Str8) *list) {
if (!list) {
return 0;
}
u64 output = 0;
for (u64 i = 0; i < list->node_count; ++i) {
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list, i);
output += node->item->size;
}
return output;
}

View File

@ -1,25 +0,0 @@
/**
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
*/
#ifndef STR8_LIST_H
#define STR8_LIST_H
#include "../../../common/aliases/aliases.h"
#include "../../../containers/dbl_list/dbl_list.h"
#ifdef __cplusplus
BEGIN_C_LINKAGE
#endif // !__cplusplus
typedef struct str8 Str8;
DBL_LIST_DECL(Str8);
u64 wapp_str8_list_total_size(const DBL_LIST(Str8) *list);
#ifdef __cplusplus
END_C_LINKAGE
#endif // !__cplusplus
#endif // !STR8_LIST_H

View File

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

View File

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

View File

@ -17,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(&expected, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP);
wapp_str8_format(&tmp, "%c", PATH_SEP); wapp_str8_format(&tmp, "%c", PATH_SEP);
DBL_LIST(Str8) parts = {0}; Str8List parts = {0};
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_str8(tmp)); wapp_str8_list_push_back(&parts, &wapp_str8_node_from_str8(tmp));
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("home")); wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("home"));
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("abdelrahman")); wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("abdelrahman"));
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("Documents")); wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("Documents"));
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = wapp_str8_equal(&out, &expected); result = wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_front(Str8, &parts); wapp_str8_list_pop_front(&parts);
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP); wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP);
@ -34,8 +34,8 @@ TestFuncResult test_cpath_join_path(void) {
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("home")); wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("home"));
wapp_dbl_list_pop_front(Str8, &parts); wapp_str8_list_pop_front(&parts);
wapp_dbl_list_push_front(&parts, &wapp_str8_node_from_str8(tmp)); wapp_str8_list_push_front(&parts, &wapp_str8_node_from_str8(tmp));
wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP); wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP);
@ -43,35 +43,35 @@ TestFuncResult test_cpath_join_path(void) {
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_str8_format(&tmp, "home%c", PATH_SEP); wapp_str8_format(&tmp, "home%c", PATH_SEP);
wapp_dbl_list_pop_front(Str8, &parts); wapp_str8_list_pop_front(&parts);
wapp_dbl_list_push_front(&parts, &wapp_str8_node_from_cstr("home")); wapp_str8_list_push_front(&parts, &wapp_str8_node_from_cstr("home"));
wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP); wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP);
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_dbl_list_empty(&parts); wapp_str8_list_empty(&parts);
wapp_str8_format(&tmp, "%chome", PATH_SEP); wapp_str8_format(&tmp, "%chome", PATH_SEP);
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_str8(tmp)); wapp_str8_list_push_back(&parts, &wapp_str8_node_from_str8(tmp));
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("")); wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr(""));
wapp_str8_format(&expected, "%chome", PATH_SEP); wapp_str8_format(&expected, "%chome", PATH_SEP);
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_front(Str8, &parts); wapp_str8_list_pop_front(&parts);
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("")); wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr(""));
wapp_str8_format(&expected, "%s", ""); wapp_str8_format(&expected, "%s", "");
wapp_cpath_join_path(&out, &parts); wapp_cpath_join_path(&out, &parts);
result = result && wapp_str8_equal(&out, &expected); result = result && wapp_str8_equal(&out, &expected);
wapp_dbl_list_pop_back(Str8, &parts); wapp_str8_list_pop_back(&parts);
wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("home")); wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("home"));
wapp_str8_copy_cstr_capped(&expected, "home"); wapp_str8_copy_cstr_capped(&expected, "home");

View File

@ -6,9 +6,9 @@
#include <string.h> #include <string.h>
TestFuncResult test_commander_cmd_success(void) { TestFuncResult test_commander_cmd_success(void) {
DBL_LIST(Str8) cmd = {0}; Str8List cmd = {0};
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo")); wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("hello world")); wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("hello world"));
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS && bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
@ -18,8 +18,8 @@ TestFuncResult test_commander_cmd_success(void) {
} }
TestFuncResult test_commander_cmd_failure(void) { TestFuncResult test_commander_cmd_failure(void) {
DBL_LIST(Str8) cmd = {0}; Str8List cmd = {0};
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("grep")); wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("grep"));
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd);
bool failed = result.exited && result.exit_code != EXIT_SUCCESS && bool failed = result.exited && result.exit_code != EXIT_SUCCESS &&
@ -34,9 +34,9 @@ TestFuncResult test_commander_cmd_out_buf_success(void) {
char msg[] = "hello world"; char msg[] = "hello world";
wapp_str8_copy_cstr_capped(&expected, msg); wapp_str8_copy_cstr_capped(&expected, msg);
DBL_LIST(Str8) cmd = {0}; Str8List cmd = {0};
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo")); wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg)); wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg));
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS && bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS &&
@ -51,9 +51,9 @@ TestFuncResult test_commander_cmd_out_buf_failure(void) {
char msg[] = "hello world"; char msg[] = "hello world";
wapp_str8_copy_cstr_capped(&expected, msg); wapp_str8_copy_cstr_capped(&expected, msg);
DBL_LIST(Str8) cmd = {0}; Str8List cmd = {0};
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo")); wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo"));
wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg)); wapp_str8_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg));
CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd);
bool failed = !result.exited && result.exit_code != EXIT_SUCCESS && bool failed = !result.exited && result.exit_code != EXIT_SUCCESS &&

View File

@ -416,8 +416,8 @@ TestFuncResult test_str8_split(void) {
Str8 str = wapp_str8_lit("hello world from me"); Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" "); Str8 delim1 = wapp_str8_lit(" ");
Str8 delim2 = wapp_str8_lit("from"); Str8 delim2 = wapp_str8_lit("from");
DBL_LIST(Str8) *list1 = wapp_str8_split(&arena, &str, &delim1); Str8List *list1 = wapp_str8_split(&arena, &str, &delim1);
DBL_LIST(Str8) *list2 = wapp_str8_split(&arena, &str, &delim2); Str8List *list2 = wapp_str8_split(&arena, &str, &delim2);
Str8RO splits1[] = { Str8RO splits1[] = {
wapp_str8_slice(&str, 0, 5), wapp_str8_slice(&str, 0, 5),
@ -444,7 +444,7 @@ TestFuncResult test_str8_split(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running1) { while (running1) {
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list1, index1); Str8Node *node = wapp_str8_list_get(list1, index1);
result = result && wapp_str8_equal(node->item, &(splits1[index1])); result = result && wapp_str8_equal(node->item, &(splits1[index1]));
++index1; ++index1;
@ -454,7 +454,7 @@ TestFuncResult test_str8_split(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running2) { while (running2) {
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list2, index2); Str8Node *node = wapp_str8_list_get(list2, index2);
result = result && wapp_str8_equal(node->item, &(splits2[index2])); result = result && wapp_str8_equal(node->item, &(splits2[index2]));
++index2; ++index2;
@ -472,7 +472,7 @@ TestFuncResult test_str8_split_with_max(void) {
Str8 str = wapp_str8_lit("hello world from me"); Str8 str = wapp_str8_lit("hello world from me");
Str8 delim = wapp_str8_lit(" "); Str8 delim = wapp_str8_lit(" ");
DBL_LIST(Str8) *list = wapp_str8_split_with_max(&arena, &str, &delim, 2); Str8List *list = wapp_str8_split_with_max(&arena, &str, &delim, 2);
Str8RO splits[] = { Str8RO splits[] = {
wapp_str8_slice(&str, 0, 5), wapp_str8_slice(&str, 0, 5),
@ -489,7 +489,7 @@ TestFuncResult test_str8_split_with_max(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running) { while (running) {
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list, index); Str8Node *node = wapp_str8_list_get(list, index);
result = result && wapp_str8_equal(node->item, &(splits[index])); result = result && wapp_str8_equal(node->item, &(splits[index]));
++index; ++index;
@ -508,8 +508,8 @@ TestFuncResult test_str8_rsplit(void) {
Str8 str = wapp_str8_lit("hello world from me"); Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" "); Str8 delim1 = wapp_str8_lit(" ");
Str8 delim2 = wapp_str8_lit("from"); Str8 delim2 = wapp_str8_lit("from");
DBL_LIST(Str8) *list1 = wapp_str8_rsplit(&arena, &str, &delim1); Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
DBL_LIST(Str8) *list2 = wapp_str8_rsplit(&arena, &str, &delim2); Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
Str8RO splits1[] = { Str8RO splits1[] = {
wapp_str8_slice(&str, 0, 5), wapp_str8_slice(&str, 0, 5),
@ -536,7 +536,7 @@ TestFuncResult test_str8_rsplit(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running1) { while (running1) {
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list1, index1); Str8Node *node = wapp_str8_list_get(list1, index1);
result = result && wapp_str8_equal(node->item, &(splits1[index1])); result = result && wapp_str8_equal(node->item, &(splits1[index1]));
++index1; ++index1;
@ -546,7 +546,7 @@ TestFuncResult test_str8_rsplit(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running2) { while (running2) {
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list2, index2); Str8Node *node = wapp_str8_list_get(list2, index2);
result = result && wapp_str8_equal(node->item, &(splits2[index2])); result = result && wapp_str8_equal(node->item, &(splits2[index2]));
++index2; ++index2;
@ -564,7 +564,7 @@ TestFuncResult test_str8_rsplit_with_max(void) {
Str8 str = wapp_str8_lit("hello world from me"); Str8 str = wapp_str8_lit("hello world from me");
Str8 delim = wapp_str8_lit(" "); Str8 delim = wapp_str8_lit(" ");
DBL_LIST(Str8) *list = wapp_str8_rsplit_with_max(&arena, &str, &delim, 2); Str8List *list = wapp_str8_rsplit_with_max(&arena, &str, &delim, 2);
Str8RO splits[] = { Str8RO splits[] = {
wapp_str8_slice(&str, 0, 11), wapp_str8_slice(&str, 0, 11),
@ -581,7 +581,7 @@ TestFuncResult test_str8_rsplit_with_max(void) {
// NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of
// MSVC Spectre mitigation warnings // MSVC Spectre mitigation warnings
while (running) { while (running) {
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, list, index); Str8Node *node = wapp_str8_list_get(list, index);
result = result && wapp_str8_equal(node->item, &(splits[index])); result = result && wapp_str8_equal(node->item, &(splits[index]));
++index; ++index;
@ -600,8 +600,8 @@ TestFuncResult test_str8_join(void) {
Str8 str = wapp_str8_lit("hello world from me"); Str8 str = wapp_str8_lit("hello world from me");
Str8 delim1 = wapp_str8_lit(" "); Str8 delim1 = wapp_str8_lit(" ");
Str8 delim2 = wapp_str8_lit("from"); Str8 delim2 = wapp_str8_lit("from");
DBL_LIST(Str8) *list1 = wapp_str8_rsplit(&arena, &str, &delim1); Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1);
DBL_LIST(Str8) *list2 = wapp_str8_rsplit(&arena, &str, &delim2); Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2);
Str8 *join1 = wapp_str8_join(&arena, list1, &delim1); Str8 *join1 = wapp_str8_join(&arena, list1, &delim1);
Str8 *join2 = wapp_str8_join(&arena, list2, &delim2); Str8 *join2 = wapp_str8_join(&arena, list2, &delim2);

View File

@ -10,32 +10,32 @@ TestFuncResult test_str8_list_get(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
DBL_LIST(Str8) list = {0}; Str8List list = {0};
DBL_NODE(Str8) n1 = { .item = &s1 }; Str8Node n1 = { .item = &s1 };
DBL_NODE(Str8) n2 = { .item = &s2 }; Str8Node n2 = { .item = &s2 };
DBL_NODE(Str8) n3 = { .item = &s3 }; Str8Node n3 = { .item = &s3 };
DBL_NODE(Str8) n4 = { .item = &s4 }; Str8Node n4 = { .item = &s4 };
DBL_NODE(Str8) n5 = { .item = &s5 }; Str8Node n5 = { .item = &s5 };
wapp_dbl_list_push_back(&list, &n1); wapp_str8_list_push_back(&list, &n1);
wapp_dbl_list_push_back(&list, &n2); wapp_str8_list_push_back(&list, &n2);
wapp_dbl_list_push_back(&list, &n3); wapp_str8_list_push_back(&list, &n3);
wapp_dbl_list_push_back(&list, &n4); wapp_str8_list_push_back(&list, &n4);
wapp_dbl_list_push_back(&list, &n5); wapp_str8_list_push_back(&list, &n5);
DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, &list, 0); Str8Node *node = wapp_str8_list_get(&list, 0);
result = node->item == &s1 && wapp_str8_equal(node->item, &s1); result = node->item == &s1 && wapp_str8_equal(node->item, &s1);
node = wapp_dbl_list_get(Str8, &list, 1); node = wapp_str8_list_get(&list, 1);
result = result && node->item == &s2 && wapp_str8_equal(node->item, &s2); result = result && node->item == &s2 && wapp_str8_equal(node->item, &s2);
node = wapp_dbl_list_get(Str8, &list, 2); node = wapp_str8_list_get(&list, 2);
result = result && node->item == &s3 && wapp_str8_equal(node->item, &s3); result = result && node->item == &s3 && wapp_str8_equal(node->item, &s3);
node = wapp_dbl_list_get(Str8, &list, 3); node = wapp_str8_list_get(&list, 3);
result = result && node->item == &s4 && wapp_str8_equal(node->item, &s4); result = result && node->item == &s4 && wapp_str8_equal(node->item, &s4);
node = wapp_dbl_list_get(Str8, &list, 4); node = wapp_str8_list_get(&list, 4);
result = result && node->item == &s5 && wapp_str8_equal(node->item, &s5); result = result && node->item == &s5 && wapp_str8_equal(node->item, &s5);
return wapp_tester_result(result); return wapp_tester_result(result);
@ -48,18 +48,18 @@ TestFuncResult test_str8_list_push_front(void) {
Str8 s2 = wapp_str8_lit("2"); Str8 s2 = wapp_str8_lit("2");
Str8 s3 = wapp_str8_lit("3"); Str8 s3 = wapp_str8_lit("3");
DBL_LIST(Str8) list = {0}; Str8List list = {0};
DBL_NODE(Str8) n1 = { .item = &s1 }; Str8Node n1 = { .item = &s1 };
DBL_NODE(Str8) n2 = { .item = &s2 }; Str8Node n2 = { .item = &s2 };
DBL_NODE(Str8) n3 = { .item = &s3 }; Str8Node n3 = { .item = &s3 };
wapp_dbl_list_push_front(&list, &n1); wapp_str8_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; result = list.first == list.last && list.first == &n1 && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
wapp_dbl_list_push_front(&list, &n2); wapp_str8_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; result = result && list.first == &n2 && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
wapp_dbl_list_push_front(&list, &n3); wapp_str8_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; 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); return wapp_tester_result(result);
@ -72,18 +72,18 @@ TestFuncResult test_str8_list_push_back(void) {
Str8 s2 = wapp_str8_lit("2"); Str8 s2 = wapp_str8_lit("2");
Str8 s3 = wapp_str8_lit("3"); Str8 s3 = wapp_str8_lit("3");
DBL_LIST(Str8) list = {0}; Str8List list = {0};
DBL_NODE(Str8) n1 = { .item = &s1 }; Str8Node n1 = { .item = &s1 };
DBL_NODE(Str8) n2 = { .item = &s2 }; Str8Node n2 = { .item = &s2 };
DBL_NODE(Str8) n3 = { .item = &s3 }; Str8Node n3 = { .item = &s3 };
wapp_dbl_list_push_back(&list, &n1); wapp_str8_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; result = list.first == list.last && list.last == &n1 && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1;
wapp_dbl_list_push_back(&list, &n2); wapp_str8_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; result = result && list.last == &n2 && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2;
wapp_dbl_list_push_back(&list, &n3); wapp_str8_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; 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); return wapp_tester_result(result);
@ -100,27 +100,27 @@ TestFuncResult test_str8_list_insert(void) {
Str8 s6 = wapp_str8_lit("6"); Str8 s6 = wapp_str8_lit("6");
Str8 s7 = wapp_str8_lit("7"); Str8 s7 = wapp_str8_lit("7");
DBL_LIST(Str8) list = {0}; Str8List list = {0};
DBL_NODE(Str8) n1 = { .item = &s1 }; Str8Node n1 = { .item = &s1 };
DBL_NODE(Str8) n2 = { .item = &s2 }; Str8Node n2 = { .item = &s2 };
DBL_NODE(Str8) n3 = { .item = &s3 }; Str8Node n3 = { .item = &s3 };
DBL_NODE(Str8) n4 = { .item = &s4 }; Str8Node n4 = { .item = &s4 };
DBL_NODE(Str8) n5 = { .item = &s5 }; Str8Node n5 = { .item = &s5 };
DBL_NODE(Str8) n6 = { .item = &s6 }; Str8Node n6 = { .item = &s6 };
DBL_NODE(Str8) n7 = { .item = &s7 }; Str8Node n7 = { .item = &s7 };
wapp_dbl_list_push_back(&list, &n1); wapp_str8_list_push_back(&list, &n1);
wapp_dbl_list_push_back(&list, &n2); wapp_str8_list_push_back(&list, &n2);
wapp_dbl_list_push_back(&list, &n3); wapp_str8_list_push_back(&list, &n3);
wapp_dbl_list_push_back(&list, &n4); wapp_str8_list_push_back(&list, &n4);
wapp_dbl_list_push_back(&list, &n5); wapp_str8_list_push_back(&list, &n5);
DBL_NODE(Str8) *node; Str8Node *node;
wapp_dbl_list_insert(&list, &n6, 2); wapp_str8_list_insert(&list, &n6, 2);
node = wapp_dbl_list_get(Str8, &list, 2); node = wapp_str8_list_get(&list, 2);
result = node != NULL && node->item == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6; result = node != NULL && node->item == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6;
wapp_dbl_list_insert(&list, &n7, 5); wapp_str8_list_insert(&list, &n7, 5);
node = wapp_dbl_list_get(Str8, &list, 5); node = wapp_str8_list_get(&list, 5);
result = result && node != NULL && node->item == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7; result = result && node != NULL && node->item == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7;
return wapp_tester_result(result); return wapp_tester_result(result);
@ -135,32 +135,32 @@ TestFuncResult test_str8_list_pop_front(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
DBL_LIST(Str8) list = {0}; Str8List list = {0};
DBL_NODE(Str8) n1 = { .item = &s1 }; Str8Node n1 = { .item = &s1 };
DBL_NODE(Str8) n2 = { .item = &s2 }; Str8Node n2 = { .item = &s2 };
DBL_NODE(Str8) n3 = { .item = &s3 }; Str8Node n3 = { .item = &s3 };
DBL_NODE(Str8) n4 = { .item = &s4 }; Str8Node n4 = { .item = &s4 };
DBL_NODE(Str8) n5 = { .item = &s5 }; Str8Node n5 = { .item = &s5 };
wapp_dbl_list_push_back(&list, &n1); wapp_str8_list_push_back(&list, &n1);
wapp_dbl_list_push_back(&list, &n2); wapp_str8_list_push_back(&list, &n2);
wapp_dbl_list_push_back(&list, &n3); wapp_str8_list_push_back(&list, &n3);
wapp_dbl_list_push_back(&list, &n4); wapp_str8_list_push_back(&list, &n4);
wapp_dbl_list_push_back(&list, &n5); wapp_str8_list_push_back(&list, &n5);
DBL_NODE(Str8) *node = wapp_dbl_list_pop_front(Str8, &list); Str8Node *node = wapp_str8_list_pop_front(&list);
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; 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_dbl_list_pop_front(Str8, &list); node = wapp_str8_list_pop_front(&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; 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_dbl_list_pop_front(Str8, &list); node = wapp_str8_list_pop_front(&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; 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_dbl_list_pop_front(Str8, &list); node = wapp_str8_list_pop_front(&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; 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_dbl_list_pop_front(Str8, &list); node = wapp_str8_list_pop_front(&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; 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); return wapp_tester_result(result);
@ -175,32 +175,32 @@ TestFuncResult test_str8_list_pop_back(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
DBL_LIST(Str8) list = {0}; Str8List list = {0};
DBL_NODE(Str8) n1 = { .item = &s1 }; Str8Node n1 = { .item = &s1 };
DBL_NODE(Str8) n2 = { .item = &s2 }; Str8Node n2 = { .item = &s2 };
DBL_NODE(Str8) n3 = { .item = &s3 }; Str8Node n3 = { .item = &s3 };
DBL_NODE(Str8) n4 = { .item = &s4 }; Str8Node n4 = { .item = &s4 };
DBL_NODE(Str8) n5 = { .item = &s5 }; Str8Node n5 = { .item = &s5 };
wapp_dbl_list_push_front(&list, &n1); wapp_str8_list_push_front(&list, &n1);
wapp_dbl_list_push_front(&list, &n2); wapp_str8_list_push_front(&list, &n2);
wapp_dbl_list_push_front(&list, &n3); wapp_str8_list_push_front(&list, &n3);
wapp_dbl_list_push_front(&list, &n4); wapp_str8_list_push_front(&list, &n4);
wapp_dbl_list_push_front(&list, &n5); wapp_str8_list_push_front(&list, &n5);
DBL_NODE(Str8) *node = wapp_dbl_list_pop_back(Str8, &list); Str8Node *node = wapp_str8_list_pop_back(&list);
result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; 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_dbl_list_pop_back(Str8, &list); node = wapp_str8_list_pop_back(&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; 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_dbl_list_pop_back(Str8, &list); node = wapp_str8_list_pop_back(&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; 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_dbl_list_pop_back(Str8, &list); node = wapp_str8_list_pop_back(&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; 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_dbl_list_pop_back(Str8, &list); node = wapp_str8_list_pop_back(&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; 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); return wapp_tester_result(result);
@ -215,32 +215,32 @@ TestFuncResult test_str8_list_remove(void) {
Str8 s4 = wapp_str8_lit("4"); Str8 s4 = wapp_str8_lit("4");
Str8 s5 = wapp_str8_lit("5"); Str8 s5 = wapp_str8_lit("5");
DBL_LIST(Str8) list = {0}; Str8List list = {0};
DBL_NODE(Str8) n1 = { .item = &s1 }; Str8Node n1 = { .item = &s1 };
DBL_NODE(Str8) n2 = { .item = &s2 }; Str8Node n2 = { .item = &s2 };
DBL_NODE(Str8) n3 = { .item = &s3 }; Str8Node n3 = { .item = &s3 };
DBL_NODE(Str8) n4 = { .item = &s4 }; Str8Node n4 = { .item = &s4 };
DBL_NODE(Str8) n5 = { .item = &s5 }; Str8Node n5 = { .item = &s5 };
wapp_dbl_list_push_back(&list, &n1); wapp_str8_list_push_back(&list, &n1);
wapp_dbl_list_push_back(&list, &n2); wapp_str8_list_push_back(&list, &n2);
wapp_dbl_list_push_back(&list, &n3); wapp_str8_list_push_back(&list, &n3);
wapp_dbl_list_push_back(&list, &n4); wapp_str8_list_push_back(&list, &n4);
wapp_dbl_list_push_back(&list, &n5); wapp_str8_list_push_back(&list, &n5);
DBL_NODE(Str8) *node = wapp_dbl_list_remove(Str8, &list, 0); Str8Node *node = wapp_str8_list_remove(&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; 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_dbl_list_remove(Str8, &list, 0); node = wapp_str8_list_remove(&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; 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_dbl_list_remove(Str8, &list, 0); node = wapp_str8_list_remove(&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; 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_dbl_list_remove(Str8, &list, 0); node = wapp_str8_list_remove(&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; 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_dbl_list_remove(Str8, &list, 0); node = wapp_str8_list_remove(&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; 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); return wapp_tester_result(result);
@ -249,13 +249,13 @@ TestFuncResult test_str8_list_remove(void) {
TestFuncResult test_str8_list_empty(void) { TestFuncResult test_str8_list_empty(void) {
bool result; bool result;
DBL_LIST(Str8) list = {0}; Str8List list = {0};
wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("Hello")); wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("Hello"));
wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("from")); wapp_str8_list_push_back(&list, &wapp_str8_node_from_cstr("from"));
wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("wizapp")); wapp_str8_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_push_back(&list, &wapp_str8_node_from_cstr("stdlib"));
wapp_dbl_list_empty(&list); wapp_str8_list_empty(&list);
result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0; result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0;