Skip to content

Commit

Permalink
[nob] introduce nob_shift and semi-deprecate nob_shift_args
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim committed Oct 14, 2024
1 parent f106c92 commit 4ac7cce
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions nob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 4ac7cce

Please sign in to comment.