diff --git a/codegen/__main__.py b/codegen/__main__.py new file mode 100644 index 0000000..4d833c3 --- /dev/null +++ b/codegen/__main__.py @@ -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() diff --git a/codegen/constants.py b/codegen/constants.py new file mode 100644 index 0000000..ebad100 --- /dev/null +++ b/codegen/constants.py @@ -0,0 +1,5 @@ +from pathlib import Path + + +PACKAGE_DIR = Path(__file__).parent.resolve() +WAPP_SRC_ROOT = PACKAGE_DIR.parent / "src" diff --git a/codegen/datatypes.py b/codegen/datatypes.py new file mode 100644 index 0000000..e28f258 --- /dev/null +++ b/codegen/datatypes.py @@ -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 diff --git a/codegen/dbl_list/make_dbl_list.py b/codegen/dbl_list/make_dbl_list.py new file mode 100644 index 0000000..e7f9111 --- /dev/null +++ b/codegen/dbl_list/make_dbl_list.py @@ -0,0 +1,224 @@ +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: + 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): + return load_func_body_from_file(filename).format( + T=type_string, + Ttitle=type_string.title(), + 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] = [] + 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( + hdr_decl_types=[ + CStruct(name="str8", cargs=[], typedef_name="Str8"), + ], + ), + } + 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) + + node = CStruct( + name=f"{type_string.title()}Node", + 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=f"{type_string.title()}List", + 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(snippets_dir / "list_node", type_string), + ) + + 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(snippets_dir / "list_get", type_string), + 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(snippets_dir / "list_push_front", type_string), + ) + + 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(snippets_dir / "list_push_back", type_string), + ) + + 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(snippets_dir / "list_insert", type_string), + ) + + 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(snippets_dir / "list_pop_front", type_string), + 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(snippets_dir / "list_pop_back", type_string), + 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(snippets_dir / "list_remove", type_string), + 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(snippets_dir / "list_empty", type_string), + ) + + 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(snippets_dir / "node_to_list", type_string), + 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) diff --git a/codegen/dbl_list/snippets/list_empty b/codegen/dbl_list/snippets/list_empty new file mode 100644 index 0000000..a5e2c4a --- /dev/null +++ b/codegen/dbl_list/snippets/list_empty @@ -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); + }} diff --git a/codegen/dbl_list/snippets/list_get b/codegen/dbl_list/snippets/list_get new file mode 100644 index 0000000..0fde3ac --- /dev/null +++ b/codegen/dbl_list/snippets/list_get @@ -0,0 +1,13 @@ + if (index >= list->node_count) {{ + return NULL; + }} + + {Ttitle}Node *output = NULL; + {Ttitle}Node *current = list->first; + for (u64 i = 1; i <= index; ++i) {{ + current = current->next; + }} + + output = current; + + return output; diff --git a/codegen/dbl_list/snippets/list_insert b/codegen/dbl_list/snippets/list_insert new file mode 100644 index 0000000..5ae0d84 --- /dev/null +++ b/codegen/dbl_list/snippets/list_insert @@ -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; + }} + + {Ttitle}Node *dst_node = wapp_{Tlower}_list_get(list, index); + if (!dst_node) {{ + return; + }} + + {Ttitle}List node_list = {Tlower}_node_to_list(node); + + list->node_count += node_list.node_count; + + {Ttitle}Node *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; diff --git a/codegen/dbl_list/snippets/list_node b/codegen/dbl_list/snippets/list_node new file mode 100644 index 0000000..b689b0e --- /dev/null +++ b/codegen/dbl_list/snippets/list_node @@ -0,0 +1 @@ +(({Ttitle}Node){{.item = ITEM_PTR}}) diff --git a/codegen/dbl_list/snippets/list_pop_back b/codegen/dbl_list/snippets/list_pop_back new file mode 100644 index 0000000..849136d --- /dev/null +++ b/codegen/dbl_list/snippets/list_pop_back @@ -0,0 +1,20 @@ + {Ttitle}Node *output = NULL; + + if (!list || list->node_count == 0) {{ + goto RETURN_{Tupper}_LIST_POP_BACK; + }} + + output = list->last; + + if (list->node_count == 1) {{ + *list = ({Ttitle}List){{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; diff --git a/codegen/dbl_list/snippets/list_pop_front b/codegen/dbl_list/snippets/list_pop_front new file mode 100644 index 0000000..8770e3f --- /dev/null +++ b/codegen/dbl_list/snippets/list_pop_front @@ -0,0 +1,20 @@ + {Ttitle}Node *output = NULL; + + if (!list || list->node_count == 0) {{ + goto RETURN_{Tupper}_LIST_POP_FRONT; + }} + + output = list->first; + + if (list->node_count == 1) {{ + *list = ({Ttitle}List){{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; diff --git a/codegen/dbl_list/snippets/list_push_back b/codegen/dbl_list/snippets/list_push_back new file mode 100644 index 0000000..35abf52 --- /dev/null +++ b/codegen/dbl_list/snippets/list_push_back @@ -0,0 +1,20 @@ + if (!list || !node || !(node->item)) {{ + return; + }} + + {Ttitle}List node_list = {Tlower}_node_to_list(node); + + if (list->node_count == 0) {{ + *list = node_list; + return; + }} + + list->node_count += node_list.node_count; + + {Ttitle}Node *last = list->last; + if (last) {{ + last->next = node_list.first; + }} + + list->last = node_list.last; + node_list.first->prev = last; diff --git a/codegen/dbl_list/snippets/list_push_front b/codegen/dbl_list/snippets/list_push_front new file mode 100644 index 0000000..f021cfc --- /dev/null +++ b/codegen/dbl_list/snippets/list_push_front @@ -0,0 +1,20 @@ + if (!list || !node || !(node->item)) {{ + return; + }} + + {Ttitle}List node_list = {Tlower}_node_to_list(node); + + if (list->node_count == 0) {{ + *list = node_list; + return; + }} + + list->node_count += node_list.node_count; + + {Ttitle}Node *first = list->first; + if (first) {{ + first->prev = node_list.last; + }} + + list->first = node_list.first; + node_list.last->next = first; diff --git a/codegen/dbl_list/snippets/list_remove b/codegen/dbl_list/snippets/list_remove new file mode 100644 index 0000000..611729a --- /dev/null +++ b/codegen/dbl_list/snippets/list_remove @@ -0,0 +1,27 @@ + {Ttitle}Node *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; diff --git a/codegen/dbl_list/snippets/node_to_list b/codegen/dbl_list/snippets/node_to_list new file mode 100644 index 0000000..b47d7e5 --- /dev/null +++ b/codegen/dbl_list/snippets/node_to_list @@ -0,0 +1,13 @@ + {Ttitle}List 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; diff --git a/codegen/utils.py b/codegen/utils.py new file mode 100644 index 0000000..8a8c814 --- /dev/null +++ b/codegen/utils.py @@ -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() diff --git a/src/containers/dbl_list/dbl_list.c b/src/containers/dbl_list/dbl_list.c index eede8a7..9ddc08e 100644 --- a/src/containers/dbl_list/dbl_list.c +++ b/src/containers/dbl_list/dbl_list.c @@ -1,16 +1,22 @@ +/** + * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN + */ + #include "./dbl_list.h" #include "../../common/aliases/aliases.h" #include -internal DBL_LIST(void) node_to_list(DBL_NODE(void) *node); +typedef struct str8 Str8; -DBL_NODE(void) *_dbl_list_get(const DBL_LIST(void) *list, u64 index) { +internal Str8List str8_node_to_list(Str8Node *node); + +Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) { if (index >= list->node_count) { return NULL; } - DBL_NODE(void) *output = NULL; - DBL_NODE(void) *current = list->first; + Str8Node *output = NULL; + Str8Node *current = list->first; for (u64 i = 1; i <= index; ++i) { current = current->next; } @@ -18,15 +24,14 @@ DBL_NODE(void) *_dbl_list_get(const DBL_LIST(void) *list, u64 index) { output = current; return output; - } -void _dbl_list_push_front(DBL_LIST(void) *list, DBL_NODE(void) *node) { +void wapp_str8_list_push_front(Str8List *list, Str8Node *node) { if (!list || !node || !(node->item)) { return; } - DBL_LIST(void) node_list = node_to_list(node); + Str8List node_list = str8_node_to_list(node); if (list->node_count == 0) { *list = node_list; @@ -35,22 +40,21 @@ void _dbl_list_push_front(DBL_LIST(void) *list, DBL_NODE(void) *node) { list->node_count += node_list.node_count; - DBL_NODE(void) *first = list->first; + Str8Node *first = list->first; if (first) { first->prev = node_list.last; } - list->first = node_list.first; + list->first = node_list.first; node_list.last->next = first; - } -void _dbl_list_push_back(DBL_LIST(void) *list, DBL_NODE(void) *node) { +void wapp_str8_list_push_back(Str8List *list, Str8Node *node) { if (!list || !node || !(node->item)) { return; } - DBL_LIST(void) node_list = node_to_list(node); + Str8List node_list = str8_node_to_list(node); if (list->node_count == 0) { *list = node_list; @@ -59,50 +63,48 @@ void _dbl_list_push_back(DBL_LIST(void) *list, DBL_NODE(void) *node) { list->node_count += node_list.node_count; - DBL_NODE(void) *last = list->last; + Str8Node *last = list->last; if (last) { last->next = node_list.first; } - list->last = node_list.last; + list->last = node_list.last; node_list.first->prev = last; - } -void _dbl_list_insert(DBL_LIST(void) *list, DBL_NODE(void) *node, u64 index) { +void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index) { if (!list || !node || !(node->item)) { return; } if (index == 0) { - _dbl_list_push_front(list, node); + wapp_str8_list_push_front(list, node); return; } else if (index == list->node_count) { - _dbl_list_push_back(list, node); + wapp_str8_list_push_back(list, node); return; } - DBL_NODE(void) *dst_node = _dbl_list_get(list, index); + Str8Node *dst_node = wapp_str8_list_get(list, index); if (!dst_node) { return; } - DBL_LIST(void) node_list = node_to_list(node); + Str8List node_list = str8_node_to_list(node); list->node_count += node_list.node_count; - DBL_NODE(void) *prev = dst_node->prev; + 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; - } -DBL_NODE(void) *_dbl_list_pop_front(DBL_LIST(void) *list) { - DBL_NODE(void) *output = NULL; +Str8Node *wapp_str8_list_pop_front(Str8List *list) { + Str8Node *output = NULL; if (!list || list->node_count == 0) { goto RETURN_STR8_LIST_POP_FRONT; @@ -111,22 +113,21 @@ DBL_NODE(void) *_dbl_list_pop_front(DBL_LIST(void) *list) { output = list->first; if (list->node_count == 1) { - *list = (DBL_LIST(void)){0}; + *list = (Str8List){0}; goto RETURN_STR8_LIST_POP_FRONT; } --(list->node_count); - list->first = output->next; + 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; +Str8Node *wapp_str8_list_pop_back(Str8List *list) { + Str8Node *output = NULL; if (!list || list->node_count == 0) { goto RETURN_STR8_LIST_POP_BACK; @@ -135,35 +136,34 @@ DBL_NODE(void) *_dbl_list_pop_back(DBL_LIST(void) *list) { output = list->last; if (list->node_count == 1) { - *list = (DBL_LIST(void)){0}; + *list = (Str8List){0}; goto RETURN_STR8_LIST_POP_BACK; } --(list->node_count); - list->last = output->prev; + 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; +Str8Node *wapp_str8_list_remove(Str8List *list, u64 index) { + Str8Node *output = NULL; if (!list) { goto RETURN_STR8_LIST_REMOVE; } if (index == 0) { - output = _dbl_list_pop_front(list); + output = wapp_str8_list_pop_front(list); goto RETURN_STR8_LIST_REMOVE; } else if (index == list->node_count) { - output = _dbl_list_pop_back(list); + output = wapp_str8_list_pop_back(list); goto RETURN_STR8_LIST_REMOVE; } - output = _dbl_list_get(list, index); + output = wapp_str8_list_get(list, index); if (!output) { goto RETURN_STR8_LIST_REMOVE; } @@ -177,23 +177,21 @@ DBL_NODE(void) *_dbl_list_remove(DBL_LIST(void) *list, u64 index) { RETURN_STR8_LIST_REMOVE: return output; - } -void _dbl_list_empty(DBL_LIST(void) *list) { +void wapp_str8_list_empty(Str8List *list) { if (!list) { return; } u64 count = list->node_count; for (u64 i = 0; i < count; ++i) { - _dbl_list_pop_back(list); + wapp_str8_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}; +internal Str8List str8_node_to_list(Str8Node *node) { + Str8List output = {.first = node, .last = node, .node_count = 1}; while (output.first->prev != NULL) { output.first = output.first->prev; @@ -207,3 +205,4 @@ internal DBL_LIST(void) node_to_list(DBL_NODE(void) *node) { return output; } + diff --git a/src/containers/dbl_list/dbl_list.h b/src/containers/dbl_list/dbl_list.h index 9b0a06f..a99121e 100644 --- a/src/containers/dbl_list/dbl_list.h +++ b/src/containers/dbl_list/dbl_list.h @@ -1,3 +1,7 @@ +/** + * THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN + */ + #ifndef DBL_LIST_H #define DBL_LIST_H @@ -7,66 +11,32 @@ BEGIN_C_LINKAGE #endif // !__cplusplus -#define DBL_NODE(T) T##Node -#define DBL_LIST(T) T##List +#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR}) -#define CAST_NODE(NODE) ((DBL_NODE(void))(NODE)) -#define CAST_LIST(LIST) ((DBL_LIST(void))(LIST)) +typedef struct str8 Str8; -#define CAST_NODE_PTR(NODE_PTR) ((DBL_NODE(void)*)(NODE_PTR)) -#define CAST_LIST_PTR(LIST_PTR) ((DBL_LIST(void)*)(LIST_PTR)) +typedef struct Str8Node Str8Node; +struct Str8Node { + Str8 *item; + Str8Node *prev; + Str8Node *next; +}; -#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; \ - } +typedef struct Str8List Str8List; +struct Str8List { + Str8Node *first; + Str8Node *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); +Str8Node *wapp_str8_list_get(const Str8List *list, u64 index); +void wapp_str8_list_push_front(Str8List *list, Str8Node *node); +void wapp_str8_list_push_back(Str8List *list, Str8Node *node); +void wapp_str8_list_insert(Str8List *list, Str8Node *node, u64 index); +Str8Node *wapp_str8_list_pop_front(Str8List *list); +Str8Node *wapp_str8_list_pop_back(Str8List *list); +Str8Node *wapp_str8_list_remove(Str8List *list, u64 index); +void wapp_str8_list_empty(Str8List *list); #ifdef __cplusplus END_C_LINKAGE diff --git a/src/core/os/cpath/cpath.c b/src/core/os/cpath/cpath.c index 8175871..d385cc1 100644 --- a/src/core/os/cpath/cpath.c +++ b/src/core/os/cpath/cpath.c @@ -4,13 +4,13 @@ #include "../../mem/allocator/mem_allocator.h" #include "../../mem/arena/mem_arena_allocator.h" #include "../../strings/str8/str8.h" -#include "../../strings/str8/str8_list.h" +#include "../../../containers/dbl_list/dbl_list.h" #include #include #include #include -u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) { +u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts) { if (!dst || !parts) { return CPATH_JOIN_INVALID_ARGS; } @@ -28,12 +28,12 @@ u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts) { } // Handle first node - const DBL_NODE(Str8) *first_node = wapp_dbl_list_get(Str8, parts, 0); + const Str8Node *first_node = wapp_str8_list_get(parts, 0); wapp_str8_copy_str8_capped(dst, first_node->item); // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings - const DBL_NODE(Str8) *node = first_node; + const Str8Node *node = first_node; u64 node_index = 1; bool running = true; while (running && node->next) { @@ -91,7 +91,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) { goto RETURN_DIRUP; } - DBL_LIST(Str8) *parts = wapp_str8_split(&tmp_arena, path, &separator); + Str8List *parts = wapp_str8_split(&tmp_arena, path, &separator); if (!parts) { goto RETURN_DIRUP; } @@ -105,7 +105,7 @@ Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels) { wapp_str8_push_back(output, absolute ? PATH_SEP : '.'); } else { for (u64 i = 0; i < levels; ++i) { - wapp_dbl_list_pop_back(Str8, parts); + wapp_str8_list_pop_back(parts); } u64 alignment = sizeof(void *) * 2; diff --git a/src/core/os/cpath/cpath.h b/src/core/os/cpath/cpath.h index 5b21e5a..61808df 100644 --- a/src/core/os/cpath/cpath.h +++ b/src/core/os/cpath/cpath.h @@ -28,7 +28,7 @@ enum { CPATH_JOIN_INSUFFICIENT_DST_CAPACITY, }; -u32 wapp_cpath_join_path(Str8 *dst, const DBL_LIST(Str8) *parts); +u32 wapp_cpath_join_path(Str8 *dst, const Str8List *parts); Str8 *dirup(const Allocator *allocator, Str8RO *path, u64 levels); #ifdef __cplusplus diff --git a/src/core/os/shell/commander/commander.c b/src/core/os/shell/commander/commander.c index a030f3e..e2ff715 100644 --- a/src/core/os/shell/commander/commander.c +++ b/src/core/os/shell/commander/commander.c @@ -4,6 +4,7 @@ #include "../../../mem/allocator/mem_allocator.h" #include "../../../mem/arena/mem_arena_allocator.h" #include "../../../strings/str8/str8.h" +#include "../../../../containers/dbl_list/dbl_list.h" #include "../../../../common/aliases/aliases.h" #include "../../../../common/misc/misc_utils.h" #include @@ -18,7 +19,7 @@ internal inline CMDResult execute_command(Str8RO *cmd, CMDOutHandling out_handling, Str8 *out_buf); internal inline CMDError get_command_output(FILE *fp, CMDOutHandling out_handling, Str8 *out_buf); -CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const DBL_LIST(Str8) *cmd) { +CMDResult wapp_shell_commander_execute(CMDOutHandling out_handling, Str8 *out_buf, const Str8List *cmd) { if (!cmd) { return CMD_NO_EXIT(SHELL_ERR_INVALID_ARGS); } diff --git a/src/core/os/shell/commander/commander.h b/src/core/os/shell/commander/commander.h index b219c29..c82269c 100644 --- a/src/core/os/shell/commander/commander.h +++ b/src/core/os/shell/commander/commander.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 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); diff --git a/src/core/strings/str8/str8.c b/src/core/strings/str8/str8.c index f6f60b8..fb6900b 100644 --- a/src/core/strings/str8/str8.c +++ b/src/core/strings/str8/str8.c @@ -1,7 +1,5 @@ #include "str8.h" -#include "str8_list.h" #include "../../../common/aliases/aliases.h" -#include "../../../containers/dbl_list/dbl_list.h" #include "../../mem/allocator/mem_allocator.h" #include #include @@ -302,19 +300,19 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr) { return -1; } -DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { +Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { if (!allocator || !str || !delimiter) { return NULL; } - DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8))); + Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List)); if (delimiter->size > str->size) { Str8 *full = wapp_str8_alloc_str8(allocator, str); - DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); + Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { node->item = full; - wapp_dbl_list_push_back(output, node); + wapp_str8_list_push_back(output, node); } goto RETURN_STR8_SPLIT; @@ -332,10 +330,10 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str } before_str = wapp_str8_alloc_substr(allocator, str, start, start + end); - DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); + Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { node->item = before_str; - wapp_dbl_list_push_back(output, node); + wapp_str8_list_push_back(output, node); } wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8)); @@ -346,30 +344,30 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str } // Ensure the last part of the string after the delimiter is added to the list - rest = wapp_str8_alloc_substr(allocator, str, start, str->size); - DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); + rest = wapp_str8_alloc_substr(allocator, str, start, str->size); + Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { node->item = rest; - wapp_dbl_list_push_back(output, node); + wapp_str8_list_push_back(output, node); } RETURN_STR8_SPLIT: return output; } -DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { +Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits) { if (!allocator || !str || !delimiter) { return NULL; } - DBL_LIST(Str8) *output = wapp_mem_allocator_alloc(allocator, sizeof(DBL_LIST(Str8))); + Str8List *output = wapp_mem_allocator_alloc(allocator, sizeof(Str8List)); if (delimiter->size > str->size) { Str8 *full = wapp_str8_alloc_str8(allocator, str); - DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); + Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { node->item = full; - wapp_dbl_list_push_back(output, node); + wapp_str8_list_push_back(output, node); } goto RETURN_STR8_SPLIT; @@ -386,10 +384,10 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st } after_str = wapp_str8_alloc_substr(allocator, rest, end + delimiter->size, str->size); - DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); + Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { node->item = after_str; - wapp_dbl_list_push_front(output, node); + wapp_str8_list_push_front(output, node); } wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8)); @@ -399,17 +397,17 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st } rest = wapp_str8_alloc_substr(allocator, str, 0, rest->size); - DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); + Str8Node *node = wapp_mem_allocator_alloc(allocator, sizeof(Str8Node)); if (node) { node->item = rest; - wapp_dbl_list_push_front(output, node); + wapp_str8_list_push_front(output, node); } RETURN_STR8_SPLIT: return output; } -Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str8RO *delimiter) { +Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter) { if (!allocator || !list || !delimiter) { return NULL; } @@ -419,11 +417,11 @@ Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str // NOTE (Abdelrahman): Uses a while loop instead of a for loop to get rid of // MSVC Spectre mitigation warnings - DBL_NODE(Str8) *node; + Str8Node *node; u64 node_index = 0; bool running = true; while (running) { - node = wapp_dbl_list_get(Str8, list, node_index); + node = wapp_str8_list_get(list, node_index); wapp_str8_concat_capped(output, node->item); if (node_index + 1 < list->node_count) { wapp_str8_concat_capped(output, delimiter); @@ -435,3 +433,17 @@ Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str return output; } + +u64 wapp_str8_list_total_size(const Str8List *list) { + if (!list) { + return 0; + } + + u64 output = 0; + for (u64 i = 0; i < list->node_count; ++i) { + Str8Node *node = wapp_str8_list_get(list, i); + output += node->item->size; + } + + return output; +} diff --git a/src/core/strings/str8/str8.h b/src/core/strings/str8/str8.h index 7626bf1..647b795 100644 --- a/src/core/strings/str8/str8.h +++ b/src/core/strings/str8/str8.h @@ -1,7 +1,6 @@ #ifndef STR8_H #define STR8_H -#include "./str8_list.h" #include "../../../common/aliases/aliases.h" #include "../../../containers/dbl_list/dbl_list.h" #include "../../mem/allocator/mem_allocator.h" @@ -85,15 +84,16 @@ i64 wapp_str8_rfind(Str8RO *str, Str8RO substr); */ #define wapp_str8_split(ALLOCATOR, STR, DELIMITER) wapp_str8_split_with_max(ALLOCATOR, STR, DELIMITER, -1) #define wapp_str8_rsplit(ALLOCATOR, STR, DELIMITER) wapp_str8_rsplit_with_max(ALLOCATOR, STR, DELIMITER, -1) -DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits); -DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits); -Str8 *wapp_str8_join(const Allocator *allocator, const DBL_LIST(Str8) *list, Str8RO *delimiter); +Str8List *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits); +Str8List *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *str, Str8RO *delimiter, i64 max_splits); +Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8RO *delimiter); /** * Str8 list utilities */ -#define wapp_str8_node_from_cstr(STRING) wapp_dbl_list_node_from_item(Str8, &wapp_str8_lit(STRING)) -#define wapp_str8_node_from_str8(STRING) wapp_dbl_list_node_from_item(Str8, &(STRING)) +#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node(&wapp_str8_lit(STRING)) +#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING)) +u64 wapp_str8_list_total_size(const Str8List *list); #ifdef __cplusplus END_C_LINKAGE diff --git a/src/core/strings/str8/str8_list.c b/src/core/strings/str8/str8_list.c deleted file mode 100644 index ea4418d..0000000 --- a/src/core/strings/str8/str8_list.c +++ /dev/null @@ -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; -} diff --git a/src/core/strings/str8/str8_list.h b/src/core/strings/str8/str8_list.h deleted file mode 100644 index 8a2e62f..0000000 --- a/src/core/strings/str8/str8_list.h +++ /dev/null @@ -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 diff --git a/src/core/wapp_core.c b/src/core/wapp_core.c index d41bc27..dfab160 100644 --- a/src/core/wapp_core.c +++ b/src/core/wapp_core.c @@ -3,7 +3,6 @@ #include "wapp_core.h" #include "strings/str8/str8.c" -#include "strings/str8/str8_list.c" #include "os/shell/termcolour/posix/termcolour_posix.c" #include "os/shell/termcolour/win/termcolour_win.c" #include "os/shell/termcolour/termcolour.c" @@ -18,5 +17,6 @@ #include "mem/allocator/mem_allocator.c" #include "mem/arena/mem_arena.c" #include "mem/arena/mem_arena_allocator.c" +#include "../containers/wapp_containers.c" #endif // !WAPP_CORE_C diff --git a/src/core/wapp_core.h b/src/core/wapp_core.h index d698b47..e1903a9 100644 --- a/src/core/wapp_core.h +++ b/src/core/wapp_core.h @@ -2,7 +2,6 @@ #define WAPP_CORE_H #include "strings/str8/str8.h" -#include "strings/str8/str8_list.h" #include "os/shell/termcolour/termcolour.h" #include "os/shell/termcolour/terminal_colours.h" #include "os/shell/commander/commander.h" @@ -18,5 +17,6 @@ #include "mem/arena/mem_arena_allocator.h" #include "mem/arena/mem_arena.h" #include "../common/wapp_common.h" +#include "../containers/wapp_containers.h" #endif // !WAPP_CORE_H diff --git a/tests/cpath/test_cpath.c b/tests/cpath/test_cpath.c index 40f5d28..003d740 100644 --- a/tests/cpath/test_cpath.c +++ b/tests/cpath/test_cpath.c @@ -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(&tmp, "%c", PATH_SEP); - 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")); + 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")); wapp_cpath_join_path(&out, &parts); 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); @@ -34,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_dbl_list_pop_front(Str8, &parts); - wapp_dbl_list_push_front(&parts, &wapp_str8_node_from_str8(tmp)); + wapp_str8_list_pop_front(&parts); + 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); @@ -43,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_dbl_list_pop_front(Str8, &parts); - wapp_dbl_list_push_front(&parts, &wapp_str8_node_from_cstr("home")); + wapp_str8_list_pop_front(&parts); + wapp_str8_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_dbl_list_empty(&parts); + wapp_str8_list_empty(&parts); wapp_str8_format(&tmp, "%chome", PATH_SEP); - 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_list_push_back(&parts, &wapp_str8_node_from_str8(tmp)); + wapp_str8_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_dbl_list_pop_front(Str8, &parts); - wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("")); + wapp_str8_list_pop_front(&parts); + wapp_str8_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_dbl_list_pop_back(Str8, &parts); - wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("home")); + wapp_str8_list_pop_back(&parts); + wapp_str8_list_push_back(&parts, &wapp_str8_node_from_cstr("home")); wapp_str8_copy_cstr_capped(&expected, "home"); diff --git a/tests/shell_commander/test_shell_commander.c b/tests/shell_commander/test_shell_commander.c index a119329..3682320 100644 --- a/tests/shell_commander/test_shell_commander.c +++ b/tests/shell_commander/test_shell_commander.c @@ -6,9 +6,9 @@ #include TestFuncResult test_commander_cmd_success(void) { - 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")); + 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")); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); 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) { - DBL_LIST(Str8) cmd = {0}; - wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("grep")); + Str8List cmd = {0}; + wapp_str8_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 && @@ -34,9 +34,9 @@ TestFuncResult test_commander_cmd_out_buf_success(void) { char msg[] = "hello world"; wapp_str8_copy_cstr_capped(&expected, 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)); + 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)); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); 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"; wapp_str8_copy_cstr_capped(&expected, 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)); + 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)); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); bool failed = !result.exited && result.exit_code != EXIT_SUCCESS && diff --git a/tests/str8/test_str8.c b/tests/str8/test_str8.c index f0289a2..053c1da 100644 --- a/tests/str8/test_str8.c +++ b/tests/str8/test_str8.c @@ -416,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"); - DBL_LIST(Str8) *list1 = wapp_str8_split(&arena, &str, &delim1); - DBL_LIST(Str8) *list2 = wapp_str8_split(&arena, &str, &delim2); + Str8List *list1 = wapp_str8_split(&arena, &str, &delim1); + Str8List *list2 = wapp_str8_split(&arena, &str, &delim2); Str8RO splits1[] = { 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 // MSVC Spectre mitigation warnings 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])); ++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 // MSVC Spectre mitigation warnings 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])); ++index2; @@ -472,7 +472,7 @@ TestFuncResult test_str8_split_with_max(void) { Str8 str = wapp_str8_lit("hello world from me"); 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[] = { 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 // MSVC Spectre mitigation warnings 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])); ++index; @@ -508,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"); - DBL_LIST(Str8) *list1 = wapp_str8_rsplit(&arena, &str, &delim1); - DBL_LIST(Str8) *list2 = wapp_str8_rsplit(&arena, &str, &delim2); + Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1); + Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2); Str8RO splits1[] = { 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 // MSVC Spectre mitigation warnings 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])); ++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 // MSVC Spectre mitigation warnings 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])); ++index2; @@ -564,7 +564,7 @@ TestFuncResult test_str8_rsplit_with_max(void) { Str8 str = wapp_str8_lit("hello world from me"); 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[] = { 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 // MSVC Spectre mitigation warnings 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])); ++index; @@ -600,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"); - DBL_LIST(Str8) *list1 = wapp_str8_rsplit(&arena, &str, &delim1); - DBL_LIST(Str8) *list2 = wapp_str8_rsplit(&arena, &str, &delim2); + Str8List *list1 = wapp_str8_rsplit(&arena, &str, &delim1); + Str8List *list2 = wapp_str8_rsplit(&arena, &str, &delim2); Str8 *join1 = wapp_str8_join(&arena, list1, &delim1); Str8 *join2 = wapp_str8_join(&arena, list2, &delim2); diff --git a/tests/str8/test_str8_list.c b/tests/str8/test_str8_list.c index ccc1be2..d47e55c 100644 --- a/tests/str8/test_str8_list.c +++ b/tests/str8/test_str8_list.c @@ -10,32 +10,32 @@ TestFuncResult test_str8_list_get(void) { Str8 s4 = wapp_str8_lit("4"); Str8 s5 = wapp_str8_lit("5"); - 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 }; + Str8List list = {0}; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; - 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); + 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); - 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); - 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); - 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); - 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); - 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); return wapp_tester_result(result); @@ -48,18 +48,18 @@ TestFuncResult test_str8_list_push_front(void) { Str8 s2 = wapp_str8_lit("2"); Str8 s3 = wapp_str8_lit("3"); - DBL_LIST(Str8) list = {0}; - DBL_NODE(Str8) n1 = { .item = &s1 }; - DBL_NODE(Str8) n2 = { .item = &s2 }; - DBL_NODE(Str8) n3 = { .item = &s3 }; + Str8List list = {0}; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + 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; - 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; - 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; return wapp_tester_result(result); @@ -72,18 +72,18 @@ TestFuncResult test_str8_list_push_back(void) { Str8 s2 = wapp_str8_lit("2"); Str8 s3 = wapp_str8_lit("3"); - DBL_LIST(Str8) list = {0}; - DBL_NODE(Str8) n1 = { .item = &s1 }; - DBL_NODE(Str8) n2 = { .item = &s2 }; - DBL_NODE(Str8) n3 = { .item = &s3 }; + Str8List list = {0}; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + 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; - 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; - 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; return wapp_tester_result(result); @@ -100,27 +100,27 @@ TestFuncResult test_str8_list_insert(void) { Str8 s6 = wapp_str8_lit("6"); Str8 s7 = wapp_str8_lit("7"); - 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 }; + Str8List list = {0}; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; + Str8Node n6 = { .item = &s6 }; + Str8Node n7 = { .item = &s7 }; - 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); + 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); - DBL_NODE(Str8) *node; - wapp_dbl_list_insert(&list, &n6, 2); - node = wapp_dbl_list_get(Str8, &list, 2); + Str8Node *node; + wapp_str8_list_insert(&list, &n6, 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; - wapp_dbl_list_insert(&list, &n7, 5); - node = wapp_dbl_list_get(Str8, &list, 5); + wapp_str8_list_insert(&list, &n7, 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; return wapp_tester_result(result); @@ -135,32 +135,32 @@ TestFuncResult test_str8_list_pop_front(void) { Str8 s4 = wapp_str8_lit("4"); Str8 s5 = wapp_str8_lit("5"); - 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 }; + Str8List list = {0}; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; - 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); + 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); - 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; - 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; - 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; - 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; - 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; return wapp_tester_result(result); @@ -175,32 +175,32 @@ TestFuncResult test_str8_list_pop_back(void) { Str8 s4 = wapp_str8_lit("4"); Str8 s5 = wapp_str8_lit("5"); - 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 }; + Str8List list = {0}; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; - 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); + 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); - 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; - 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; - 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; - 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; - 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; return wapp_tester_result(result); @@ -215,32 +215,32 @@ TestFuncResult test_str8_list_remove(void) { Str8 s4 = wapp_str8_lit("4"); Str8 s5 = wapp_str8_lit("5"); - 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 }; + Str8List list = {0}; + Str8Node n1 = { .item = &s1 }; + Str8Node n2 = { .item = &s2 }; + Str8Node n3 = { .item = &s3 }; + Str8Node n4 = { .item = &s4 }; + Str8Node n5 = { .item = &s5 }; - 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); + 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); - 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; - 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; - 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; - 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; - 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; return wapp_tester_result(result); @@ -249,13 +249,13 @@ TestFuncResult test_str8_list_remove(void) { TestFuncResult test_str8_list_empty(void) { bool result; - 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")); + 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")); - 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;