From 242b87209b778d033d1da828ae9ec47170c17f38 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Fri, 22 Sep 2023 20:23:05 +0200 Subject: fix single header --- .gitignore | 1 + gen_gl.c | 11 +++++++++++ gen_inl.c | 5 +++-- include/kit.inl.h | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 gen_gl.c diff --git a/.gitignore b/.gitignore index b846915..3a26fa3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /*build*/ *.swp gen_inl +gen_gl diff --git a/gen_gl.c b/gen_gl.c new file mode 100644 index 0000000..117d9bc --- /dev/null +++ b/gen_gl.c @@ -0,0 +1,11 @@ +#if 0 +gcc -fsanitize=address,undefined,leak gen_gl.c -o gen_gl && ./gen_gl +exit +#endif + +#define KIT_IMPLEMENTATION +#include "include/kit.inl.h" + +int main(int argc, char **argv) { + return 0; +} diff --git a/gen_inl.c b/gen_inl.c index c6f5d3c..1e99058 100644 --- a/gen_inl.c +++ b/gen_inl.c @@ -36,6 +36,7 @@ char *IMPL[] = { "source/kit/allocator.c", "source/kit/atomic.win32.c", "source/kit/threads.posix.c", "source/kit/threads.win32.c", + "source/kit/array_ref.c", "source/kit/dynamic_array.c", "source/kit/string_builder.c", "source/kit/input_stream.c", @@ -144,9 +145,9 @@ int main(int argc, char **argv) { "===========\n"); fprintf(out, "//\n"); fprintf(out, "// kit.inl.h\n"); - fprintf(out, "// https://guattari.tech/git/?p=kit.git;a=tree\n"); + fprintf(out, "// https://guattari.tech/kit.git\n"); fprintf(out, "//\n"); - fprintf(out, "// Header-only utility library for C.\n"); + fprintf(out, "// Single header-only utility library for C.\n"); fprintf(out, "//\n"); fprintf(out, "// " "=====================================================" diff --git a/include/kit.inl.h b/include/kit.inl.h index 1b66297..9752919 100644 --- a/include/kit.inl.h +++ b/include/kit.inl.h @@ -1,9 +1,9 @@ // ================================================================ // // kit.inl.h -// https://guattari.tech/git/?p=kit.git;a=tree +// https://guattari.tech/kit.git // -// Header-only utility library for C. +// Single header-only utility library for C. // // ================================================================ // @@ -2867,6 +2867,48 @@ void thrd_yield(void) { } # endif #endif +/********************************************************************* + * * + * File: source/kit/array_ref.c * + * * + *********************************************************************/ +#include +i8 kit_ar_equal_bytes(i64 left_element_size, i64 left_size, + void *left_data, i64 right_element_size, + i64 right_size, void *right_data) { + i64 i; + if (left_element_size != right_element_size) + return 0; + if (left_size != right_size) + return 0; + for (i = 0; i < left_size; i++) + if (memcmp((u8 *) left_data + i * left_element_size, + (u8 *) right_data + i * left_element_size, + left_element_size) != 0) + return 0; + return 1; +} +i8 kit_ar_compare(i64 left_element_size, i64 left_size, + void *left_data, i64 right_element_size, + i64 right_size, void *right_data, + kit_ar_compare_fn compare) { + i64 i; + if (left_element_size < right_element_size) + return -1; + if (left_element_size > right_element_size) + return 1; + for (i = 0; i < left_size && i < right_size; i++) { + i8 c = compare((u8 *) left_data + i * left_element_size, + (u8 *) right_data + i * left_element_size); + if (c != 0) + return c; + } + if (left_size < right_size) + return -1; + if (left_size > right_size) + return 1; + return 0; +} /********************************************************************* * * * File: source/kit/dynamic_array.c * -- cgit v1.2.3