diff --git a/src/containers/dbl_list/dbl_list.h b/src/containers/dbl_list/dbl_list.h index b06c675..9b0a06f 100644 --- a/src/containers/dbl_list/dbl_list.h +++ b/src/containers/dbl_list/dbl_list.h @@ -32,18 +32,19 @@ BEGIN_C_LINKAGE DBL_LIST_DECL(void); -#define wapp_dbl_list_node_from_item(T, ITEM_PTR) ((DBL_NODE(T)){ .item = ITEM_PTR }) +#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(T, LIST_PTR, NODE_PTR) \ +#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(T, LIST_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(T, LIST_PTR, NODE_PTR, INDEX) \ +#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) \ @@ -55,7 +56,7 @@ DBL_LIST_DECL(void); #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(T, LIST_PTR) \ +#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); diff --git a/src/core/strings/str8/str8.c b/src/core/strings/str8/str8.c index 2a04b55..f6f60b8 100644 --- a/src/core/strings/str8/str8.c +++ b/src/core/strings/str8/str8.c @@ -314,7 +314,7 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); if (node) { node->item = full; - wapp_dbl_list_push_back(Str8, output, node); + wapp_dbl_list_push_back(output, node); } goto RETURN_STR8_SPLIT; @@ -335,7 +335,7 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); if (node) { node->item = before_str; - wapp_dbl_list_push_back(Str8, output, node); + wapp_dbl_list_push_back(output, node); } wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8)); @@ -350,7 +350,7 @@ DBL_LIST(Str8) *wapp_str8_split_with_max(const Allocator *allocator, Str8RO *str DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); if (node) { node->item = rest; - wapp_dbl_list_push_back(Str8, output, node); + wapp_dbl_list_push_back(output, node); } RETURN_STR8_SPLIT: @@ -369,7 +369,7 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); if (node) { node->item = full; - wapp_dbl_list_push_back(Str8, output, node); + wapp_dbl_list_push_back(output, node); } goto RETURN_STR8_SPLIT; @@ -389,7 +389,7 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); if (node) { node->item = after_str; - wapp_dbl_list_push_front(Str8, output, node); + wapp_dbl_list_push_front(output, node); } wapp_mem_allocator_free(allocator, (void **)&rest, sizeof(Str8)); @@ -402,7 +402,7 @@ DBL_LIST(Str8) *wapp_str8_rsplit_with_max(const Allocator *allocator, Str8RO *st DBL_NODE(Str8) *node = wapp_mem_allocator_alloc(allocator, sizeof(DBL_NODE(Str8))); if (node) { node->item = rest; - wapp_dbl_list_push_front(Str8, output, node); + wapp_dbl_list_push_front(output, node); } RETURN_STR8_SPLIT: diff --git a/tests/cpath/test_cpath.c b/tests/cpath/test_cpath.c index 065067f..40f5d28 100644 --- a/tests/cpath/test_cpath.c +++ b/tests/cpath/test_cpath.c @@ -18,10 +18,10 @@ TestFuncResult test_cpath_join_path(void) { wapp_str8_format(&tmp, "%c", PATH_SEP); DBL_LIST(Str8) parts = {0}; - wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_str8(tmp)); - wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("home")); - wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("abdelrahman")); - wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("Documents")); + wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_str8(tmp)); + wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("home")); + wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("abdelrahman")); + wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("Documents")); wapp_cpath_join_path(&out, &parts); result = wapp_str8_equal(&out, &expected); @@ -35,7 +35,7 @@ TestFuncResult test_cpath_join_path(void) { wapp_str8_concat_capped(&tmp, &wapp_str8_lit_ro("home")); wapp_dbl_list_pop_front(Str8, &parts); - wapp_dbl_list_push_front(Str8, &parts, &wapp_str8_node_from_str8(tmp)); + wapp_dbl_list_push_front(&parts, &wapp_str8_node_from_str8(tmp)); wapp_str8_format(&expected, "%chome%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP, PATH_SEP); @@ -44,18 +44,18 @@ TestFuncResult test_cpath_join_path(void) { wapp_str8_format(&tmp, "home%c", PATH_SEP); wapp_dbl_list_pop_front(Str8, &parts); - wapp_dbl_list_push_front(Str8, &parts, &wapp_str8_node_from_cstr("home")); + wapp_dbl_list_push_front(&parts, &wapp_str8_node_from_cstr("home")); wapp_str8_format(&expected, "home%cabdelrahman%cDocuments", PATH_SEP, PATH_SEP); wapp_cpath_join_path(&out, &parts); result = result && wapp_str8_equal(&out, &expected); - wapp_dbl_list_empty(Str8, &parts); + wapp_dbl_list_empty(&parts); wapp_str8_format(&tmp, "%chome", PATH_SEP); - wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_str8(tmp)); - wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("")); + wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_str8(tmp)); + wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("")); wapp_str8_format(&expected, "%chome", PATH_SEP); @@ -63,7 +63,7 @@ TestFuncResult test_cpath_join_path(void) { result = result && wapp_str8_equal(&out, &expected); wapp_dbl_list_pop_front(Str8, &parts); - wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("")); + wapp_dbl_list_push_back(&parts, &wapp_str8_node_from_cstr("")); wapp_str8_format(&expected, "%s", ""); @@ -71,7 +71,7 @@ TestFuncResult test_cpath_join_path(void) { result = result && wapp_str8_equal(&out, &expected); wapp_dbl_list_pop_back(Str8, &parts); - wapp_dbl_list_push_back(Str8, &parts, &wapp_str8_node_from_cstr("home")); + wapp_dbl_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 8f5d083..a119329 100644 --- a/tests/shell_commander/test_shell_commander.c +++ b/tests/shell_commander/test_shell_commander.c @@ -7,8 +7,8 @@ TestFuncResult test_commander_cmd_success(void) { DBL_LIST(Str8) cmd = {0}; - wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("echo")); - wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("hello world")); + wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo")); + wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("hello world")); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS && @@ -19,7 +19,7 @@ TestFuncResult test_commander_cmd_success(void) { TestFuncResult test_commander_cmd_failure(void) { DBL_LIST(Str8) cmd = {0}; - wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("grep")); + wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("grep")); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_DISCARD, NULL, &cmd); bool failed = result.exited && result.exit_code != EXIT_SUCCESS && @@ -35,8 +35,8 @@ TestFuncResult test_commander_cmd_out_buf_success(void) { wapp_str8_copy_cstr_capped(&expected, msg); DBL_LIST(Str8) cmd = {0}; - wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("echo")); - wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr(msg)); + wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo")); + wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg)); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); bool succeeded = result.exited && result.exit_code == EXIT_SUCCESS && @@ -52,8 +52,8 @@ TestFuncResult test_commander_cmd_out_buf_failure(void) { wapp_str8_copy_cstr_capped(&expected, msg); DBL_LIST(Str8) cmd = {0}; - wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr("echo")); - wapp_dbl_list_push_back(Str8, &cmd, &wapp_str8_node_from_cstr(msg)); + wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr("echo")); + wapp_dbl_list_push_back(&cmd, &wapp_str8_node_from_cstr(msg)); CMDResult result = wapp_shell_commander_execute(SHELL_OUTPUT_CAPTURE, &buf, &cmd); bool failed = !result.exited && result.exit_code != EXIT_SUCCESS && diff --git a/tests/str8/test_str8_list.c b/tests/str8/test_str8_list.c index 7d5d2fa..ccc1be2 100644 --- a/tests/str8/test_str8_list.c +++ b/tests/str8/test_str8_list.c @@ -17,11 +17,11 @@ TestFuncResult test_str8_list_get(void) { DBL_NODE(Str8) n4 = { .item = &s4 }; DBL_NODE(Str8) n5 = { .item = &s5 }; - wapp_dbl_list_push_back(Str8, &list, &n1); - wapp_dbl_list_push_back(Str8, &list, &n2); - wapp_dbl_list_push_back(Str8, &list, &n3); - wapp_dbl_list_push_back(Str8, &list, &n4); - wapp_dbl_list_push_back(Str8, &list, &n5); + wapp_dbl_list_push_back(&list, &n1); + wapp_dbl_list_push_back(&list, &n2); + wapp_dbl_list_push_back(&list, &n3); + wapp_dbl_list_push_back(&list, &n4); + wapp_dbl_list_push_back(&list, &n5); DBL_NODE(Str8) *node = wapp_dbl_list_get(Str8, &list, 0); result = node->item == &s1 && wapp_str8_equal(node->item, &s1); @@ -53,13 +53,13 @@ TestFuncResult test_str8_list_push_front(void) { DBL_NODE(Str8) n2 = { .item = &s2 }; DBL_NODE(Str8) n3 = { .item = &s3 }; - wapp_dbl_list_push_front(Str8, &list, &n1); + wapp_dbl_list_push_front(&list, &n1); result = list.first == list.last && list.first == &n1 && list.first->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; - wapp_dbl_list_push_front(Str8, &list, &n2); + wapp_dbl_list_push_front(&list, &n2); result = result && list.first == &n2 && list.first->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; - wapp_dbl_list_push_front(Str8, &list, &n3); + wapp_dbl_list_push_front(&list, &n3); result = result && list.first == &n3 && list.first->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; return wapp_tester_result(result); @@ -77,13 +77,13 @@ TestFuncResult test_str8_list_push_back(void) { DBL_NODE(Str8) n2 = { .item = &s2 }; DBL_NODE(Str8) n3 = { .item = &s3 }; - wapp_dbl_list_push_back(Str8, &list, &n1); + wapp_dbl_list_push_back(&list, &n1); result = list.first == list.last && list.last == &n1 && list.last->item == &s1 && wapp_str8_list_total_size(&list) == 1 && list.node_count == 1; - wapp_dbl_list_push_back(Str8, &list, &n2); + wapp_dbl_list_push_back(&list, &n2); result = result && list.last == &n2 && list.last->item == &s2 && wapp_str8_list_total_size(&list) == 2 && list.node_count == 2; - wapp_dbl_list_push_back(Str8, &list, &n3); + wapp_dbl_list_push_back(&list, &n3); result = result && list.last == &n3 && list.last->item == &s3 && wapp_str8_list_total_size(&list) == 3 && list.node_count == 3; return wapp_tester_result(result); @@ -109,17 +109,17 @@ TestFuncResult test_str8_list_insert(void) { DBL_NODE(Str8) n6 = { .item = &s6 }; DBL_NODE(Str8) n7 = { .item = &s7 }; - wapp_dbl_list_push_back(Str8, &list, &n1); - wapp_dbl_list_push_back(Str8, &list, &n2); - wapp_dbl_list_push_back(Str8, &list, &n3); - wapp_dbl_list_push_back(Str8, &list, &n4); - wapp_dbl_list_push_back(Str8, &list, &n5); + wapp_dbl_list_push_back(&list, &n1); + wapp_dbl_list_push_back(&list, &n2); + wapp_dbl_list_push_back(&list, &n3); + wapp_dbl_list_push_back(&list, &n4); + wapp_dbl_list_push_back(&list, &n5); DBL_NODE(Str8) *node; - wapp_dbl_list_insert(Str8, &list, &n6, 2); + wapp_dbl_list_insert(&list, &n6, 2); node = wapp_dbl_list_get(Str8, &list, 2); result = node != NULL && node->item == &s6 && wapp_str8_list_total_size(&list) == 6 && list.node_count == 6; - wapp_dbl_list_insert(Str8, &list, &n7, 5); + wapp_dbl_list_insert(&list, &n7, 5); node = wapp_dbl_list_get(Str8, &list, 5); result = result && node != NULL && node->item == &s7 && wapp_str8_list_total_size(&list) == 7 && list.node_count == 7; @@ -142,11 +142,11 @@ TestFuncResult test_str8_list_pop_front(void) { DBL_NODE(Str8) n4 = { .item = &s4 }; DBL_NODE(Str8) n5 = { .item = &s5 }; - wapp_dbl_list_push_back(Str8, &list, &n1); - wapp_dbl_list_push_back(Str8, &list, &n2); - wapp_dbl_list_push_back(Str8, &list, &n3); - wapp_dbl_list_push_back(Str8, &list, &n4); - wapp_dbl_list_push_back(Str8, &list, &n5); + wapp_dbl_list_push_back(&list, &n1); + wapp_dbl_list_push_back(&list, &n2); + wapp_dbl_list_push_back(&list, &n3); + wapp_dbl_list_push_back(&list, &n4); + wapp_dbl_list_push_back(&list, &n5); DBL_NODE(Str8) *node = wapp_dbl_list_pop_front(Str8, &list); result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; @@ -182,11 +182,11 @@ TestFuncResult test_str8_list_pop_back(void) { DBL_NODE(Str8) n4 = { .item = &s4 }; DBL_NODE(Str8) n5 = { .item = &s5 }; - wapp_dbl_list_push_front(Str8, &list, &n1); - wapp_dbl_list_push_front(Str8, &list, &n2); - wapp_dbl_list_push_front(Str8, &list, &n3); - wapp_dbl_list_push_front(Str8, &list, &n4); - wapp_dbl_list_push_front(Str8, &list, &n5); + wapp_dbl_list_push_front(&list, &n1); + wapp_dbl_list_push_front(&list, &n2); + wapp_dbl_list_push_front(&list, &n3); + wapp_dbl_list_push_front(&list, &n4); + wapp_dbl_list_push_front(&list, &n5); DBL_NODE(Str8) *node = wapp_dbl_list_pop_back(Str8, &list); result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; @@ -222,11 +222,11 @@ TestFuncResult test_str8_list_remove(void) { DBL_NODE(Str8) n4 = { .item = &s4 }; DBL_NODE(Str8) n5 = { .item = &s5 }; - wapp_dbl_list_push_back(Str8, &list, &n1); - wapp_dbl_list_push_back(Str8, &list, &n2); - wapp_dbl_list_push_back(Str8, &list, &n3); - wapp_dbl_list_push_back(Str8, &list, &n4); - wapp_dbl_list_push_back(Str8, &list, &n5); + wapp_dbl_list_push_back(&list, &n1); + wapp_dbl_list_push_back(&list, &n2); + wapp_dbl_list_push_back(&list, &n3); + wapp_dbl_list_push_back(&list, &n4); + wapp_dbl_list_push_back(&list, &n5); DBL_NODE(Str8) *node = wapp_dbl_list_remove(Str8, &list, 0); result = node == &n1 && node->item == &s1 && wapp_str8_equal(node->item, &s1) && wapp_str8_list_total_size(&list) == 4 && list.node_count == 4; @@ -250,12 +250,12 @@ TestFuncResult test_str8_list_empty(void) { bool result; DBL_LIST(Str8) list = {0}; - wapp_dbl_list_push_back(Str8, &list, &wapp_str8_node_from_cstr("Hello")); - wapp_dbl_list_push_back(Str8, &list, &wapp_str8_node_from_cstr("from")); - wapp_dbl_list_push_back(Str8, &list, &wapp_str8_node_from_cstr("wizapp")); - wapp_dbl_list_push_back(Str8, &list, &wapp_str8_node_from_cstr("stdlib")); + wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("Hello")); + wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("from")); + wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("wizapp")); + wapp_dbl_list_push_back(&list, &wapp_str8_node_from_cstr("stdlib")); - wapp_dbl_list_empty(Str8, &list); + wapp_dbl_list_empty(&list); result = list.first == NULL && list.last == NULL && list.node_count == 0 && wapp_str8_list_total_size(&list) == 0;