From 4ac7cce9874bc19e02d8c160c8c6229de8919401 Mon Sep 17 00:00:00 2001 From: rexim Date: Tue, 15 Oct 2024 05:28:43 +0700 Subject: [PATCH] [nob] introduce nob_shift and semi-deprecate nob_shift_args --- nob.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/nob.h b/nob.h index 108b597..43a974a 100644 --- a/nob.h +++ b/nob.h @@ -76,7 +76,12 @@ void nob_log(Nob_Log_Level level, const char *fmt, ...); // It is an equivalent of shift command from bash. It basically pops a command line // argument from the beginning. -char *nob_shift_args(int *argc, char ***argv); +#define nob_shift(xs, xs_sz) (NOB_ASSERT((xs_sz) > 0), (xs_sz)--, *(xs)++) +// NOTE: nob_shift_args() is an alias for an old variant of nob_shift that only worked with +// the command line arguments passed to the main() function. nob_shift() is more generic. +// So nob_shift_args() is semi-deprecated, but I don't see much reason to urgently +// remove it. This alias does not hurt anybody. +#define nob_shift_args(argc, argv) nob_shift(*argv, *argc) typedef struct { const char **items; @@ -621,15 +626,6 @@ bool nob_cmd_run_sync(Nob_Cmd cmd) return nob_proc_wait(p); } -char *nob_shift_args(int *argc, char ***argv) -{ - NOB_ASSERT(*argc > 0); - char *result = **argv; - (*argv) += 1; - (*argc) -= 1; - return result; -} - void nob_log(Nob_Log_Level level, const char *fmt, ...) { switch (level) {