From 9e6b763fb28c783b8d856442a6929026257bff92 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 20 Jan 2023 10:00:29 +0100 Subject: Renamed macro function c_initialize() to c_init(). Minor internal improvements. --- README.md | 2 +- include/stc/ccommon.h | 4 ++-- include/stc/priv/altnames.h | 56 +++++++++++++++++++++++++++++++++++++++++++++ include/stc/priv/lowcase.h | 56 --------------------------------------------- misc/examples/printspan.c | 41 ++++++++++++++++++--------------- 5 files changed, 81 insertions(+), 78 deletions(-) create mode 100644 include/stc/priv/altnames.h delete mode 100644 include/stc/priv/lowcase.h diff --git a/README.md b/README.md index f184e597..2ba88048 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ STC - Smart Template Containers for C News: Version 4.1 Beta (Dec 2022) ------------------------------------------------ -- Major change is uppercase macros in ccommon.h. Lowercase macros are [still supported](include/stc/priv/lowcase.h). +- Major change is uppercase macros in ccommon.h. Lowercase macros are [still supported](include/stc/priv/altnames.h). - [See detailed changes for version 4](#version-4). Introduction diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 09befa56..35bc9335 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -29,7 +29,7 @@ #include #include #include -#include "priv/lowcase.h" +#include "priv/altnames.h" #if SIZE_MAX == UINT32_MAX #define c_ZU PRIu32 @@ -112,7 +112,7 @@ #define c_no_hash (1<<6) #define c_no_lookup (c_no_cmp|c_no_eq|c_no_hash) -#define c_initialize(C, ...) \ +#define c_init(C, ...) \ C##_from_n((C##_raw[])__VA_ARGS__, sizeof((C##_raw[])__VA_ARGS__)/sizeof(C##_raw)) /* Function macros and various others */ diff --git a/include/stc/priv/altnames.h b/include/stc/priv/altnames.h new file mode 100644 index 00000000..7f58384c --- /dev/null +++ b/include/stc/priv/altnames.h @@ -0,0 +1,56 @@ +/* MIT License + * + * Copyright (c) 2023 Tyge Løvset + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#define c_alloc c_ALLOC +#define c_alloc_n c_ALLOC_N +#define c_new c_NEW +#define c_malloc c_MALLOC +#define c_calloc c_CALLOC +#define c_realloc c_REALLOC +#define c_free c_FREE +#define c_arraylen c_ARRAYLEN +#define c_forlist c_FORLIST +#define c_forrange c_FORRANGE +#define c_foreach c_FOREACH +#define c_forwhile c_FORWHILE +#define c_forpair c_FORPAIR +#define c_forfilter c_FORFILTER +#define c_formatch c_FORMATCH +#define c_fortoken c_FORTOKEN +#define c_fortoken_sv c_FORTOKEN_SV +#define c_auto c_AUTO +#define c_with c_WITH +#define c_scope c_SCOPE +#define c_defer c_DEFER +#define c_sv c_SV + +#define c_DROP c_drop +#define c_DELETE c_delete +#define c_SWAP c_swap +#define c_FIND_IF c_find_if +#define c_ERASE_IF c_erase_if +#define c_FLT_TAKE c_flt_take +#define c_FLT_SKIP c_flt_skip +#define c_FLT_SKIPWHILE c_flt_skipwhile +#define c_FLT_TAKEWHILE c_flt_takewhile +#define c_CONTAINER_OF c_container_of +#define c_STATIC_ASSERT c_static_assert diff --git a/include/stc/priv/lowcase.h b/include/stc/priv/lowcase.h deleted file mode 100644 index cb6ed991..00000000 --- a/include/stc/priv/lowcase.h +++ /dev/null @@ -1,56 +0,0 @@ -/* MIT License - * - * Copyright (c) 2023 Tyge Løvset - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -#define c_alloc c_ALLOC -#define c_alloc_n c_ALLOC_N -#define c_new c_NEW -#define c_malloc c_MALLOC -#define c_calloc c_CALLOC -#define c_realloc c_REALLOC -#define c_free c_FREE -#define c_arraylen c_ARRAYLEN -#define c_forlist c_FORLIST -#define c_forrange c_FORRANGE -#define c_foreach c_FOREACH -#define c_forwhile c_FORWHILE -#define c_forpair c_FORPAIR -#define c_forfilter c_FORFILTER -#define c_formatch c_FORMATCH -#define c_fortoken c_FORTOKEN -#define c_fortoken_sv c_FORTOKEN_SV -#define c_auto c_AUTO -#define c_with c_WITH -#define c_scope c_SCOPE -#define c_defer c_DEFER -#define c_sv c_SV - -#define c_DROP c_drop -#define c_FIND_IF c_find_if -#define c_ERASE_IF c_erase_if -#define c_FLT_TAKE c_flt_take -#define c_FLT_SKIP c_flt_skip -#define c_FLT_SKIPWHILE c_flt_skipwhile -#define c_FLT_TAKEWHILE c_flt_takewhile -#define c_DELETE c_delete -#define c_SWAP c_swap -#define c_CONTAINER_OF c_container_of -#define c_STATIC_ASSERT c_static_assert diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c index 6292cecf..8d0b0321 100644 --- a/misc/examples/printspan.c +++ b/misc/examples/printspan.c @@ -12,40 +12,43 @@ #include #include -using_cspan(ispan, int, 1); +using_cspan(intspan, int, 1); -void printMe(ispan container) { - printf("%d\n", (int)cspan_size(&container)); - c_FOREACH (e, ispan, container) printf("%d ", *e.ref); +void printMe(intspan container) { + printf("%d:", (int)cspan_size(&container)); + c_FOREACH (e, intspan, container) printf(" %d", *e.ref); puts(""); } -int main() { +int main() +{ c_AUTO (cvec_int, vec) c_AUTO (cstack_int, stk) c_AUTO (cdeq_int, deq) c_AUTO (cset_str, set) { - int arr[] = {1, 2, 3, 4, 5}; - ispan sp = cspan_from_array(arr); - printMe((ispan)cspan_subspan(&sp, 1, 3)); + printMe( c_init(intspan, {1, 2, 3}) ); - printMe(c_initialize(ispan, {1, 2, 3, 4})); + int arr[] = {1, 2, 3, 4, 5, 6}; + intspan span = cspan_from_array(arr); + printMe( (intspan)cspan_subspan(&span, 1, 4) ); - printMe((ispan)cspan_from_array(arr)); + c_FORLIST (i, int, {1, 2, 3, 4, 5}) + cvec_int_push(&vec, *i.ref); + printMe( (intspan)cspan_from(&vec) ); - c_FORLIST (i, int, {1, 2, 3, 4, 5, 6}) cvec_int_push(&vec, *i.ref); - printMe((ispan)cspan_from(&vec)); + printMe( span ); - stk = c_initialize(cstack_int, {1, 2, 3, 4, 5, 6, 7}); - printMe((ispan)cspan_from(&stk)); + stk = c_init(cstack_int, {1, 2, 3, 4, 5, 6, 7}); + printMe( (intspan)cspan_from(&stk) ); - deq = c_initialize(cdeq_int, {1, 2, 3, 4, 5, 6, 7, 8}); - printMe((ispan)cspan_from(&deq)); + deq = c_init(cdeq_int, {1, 2, 3, 4, 5, 6, 7, 8}); + printMe( (intspan)cspan_from(&deq) ); - set = c_initialize(cset_str, {"1", "2", "3", "4", "5", "6", "7", "8", "9"}); - printf("%d\n", (int)cset_str_size(&set)); - c_FOREACH (e, cset_str, set) printf("%s ", cstr_str(e.ref)); + set = c_init(cset_str, {"1", "2", "3", "4", "5", "6", "7", "8", "9"}); + printf("%d:", (int)cset_str_size(&set)); + c_FOREACH (e, cset_str, set) + printf(" %s", cstr_str(e.ref)); puts(""); } } -- cgit v1.2.3