Преглед изворни кода

[nob] introduce nob_shift and semi-deprecate nob_shift_args

rexim пре 1 година
родитељ
комит
4ac7cce987
1 измењених фајлова са 6 додато и 10 уклоњено
  1. 6 10
      nob.h

+ 6 - 10
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) {