From 9c457247f6b0d5b0b9fbfe1a2b5713e1341b806b Mon Sep 17 00:00:00 2001 From: ahmedsamyh Date: Tue, 25 Feb 2025 15:30:12 +0500 Subject: [PATCH] [commonlib.h] Implemented c_pop_front... - Make c_shift_args -> c_pop_front. --- commonlib.h | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/commonlib.h b/commonlib.h index 08f889a..b147ffb 100644 --- a/commonlib.h +++ b/commonlib.h @@ -7,6 +7,7 @@ #include #include #include +#include // Memory allocation #define C_MALLOC malloc @@ -67,6 +68,8 @@ typedef wchar_t wchar; typedef const char* cstr; typedef const wchar* wstr; + +// Macros #define c_ASSERT(condition, msg) do {\ if (!(condition)) {\ fprintf(stderr, "%s:%d:0 [ASSERTION FAILED] %s: %s", __FILE__, __LINE__, #condition, msg);\ @@ -76,6 +79,9 @@ typedef const wchar* wstr; #define c_ARRAY_LEN(arr) (sizeof(arr) / sizeof(arr[0])) +#define c_pop_front(xs, xsz) (assert(xsz > 0 && "Array is empty"), xsz--, *xs++) +#define c_shift_args c_pop_front + // // Struct pre-decls // @@ -125,6 +131,8 @@ typedef struct c_Arena c_Arena; (da).items[(da).count++] = elm;\ } while (0) +#define c_da_pop_front(da) (c_ASSERT(da.count > 0, "Array is empty"), da.count--, *da.items++) + // // OS // @@ -235,12 +243,6 @@ bool c_sv_contains_char(c_String_view sv, char ch); bool c_sv_is_hex_numbers(c_String_view sv); bool c_sv_equals(c_String_view sv1, c_String_view sv2); -// -// Args -// - -cstr c_shift_args(int* argc, char*** argv); - #endif /* _COMMONLIB_H_ */ ////////////////////////////////////////////////// @@ -617,18 +619,4 @@ bool c_sv_equals(c_String_view sv1, c_String_view sv2) { return true; } - -// -// Args -// - -cstr c_shift_args(int* argc, char*** argv) { - if (*argc <= 0) return NULL; - - cstr res = *(argv)[0]; - *argv = (*argv) + 1; - *argc = (*argc) - 1; - return res; -} - #endif -- 2.39.5