[Bf-blender-cvs] [6ac46c9708f] master: BLI_args: refactor argument passes
Campbell Barton
noreply at git.blender.org
Wed Oct 28 04:05:33 CET 2020
Commit: 6ac46c9708f46f9dd83dd36008d6f7c9569b74eb
Author: Campbell Barton
Date: Wed Oct 28 12:34:33 2020 +1100
Branches: master
https://developer.blender.org/rB6ac46c9708f46f9dd83dd36008d6f7c9569b74eb
BLI_args: refactor argument passes
Avoid passing the pass argument to BLI_argsAdd, instead set this
once for each group of passes.
This means we can add new passes without having to bump the arguments
to BLI_argsAdd.
===================================================================
M source/blender/blenlib/BLI_args.h
M source/blender/blenlib/intern/BLI_args.c
M source/creator/creator_args.c
===================================================================
diff --git a/source/blender/blenlib/BLI_args.h b/source/blender/blenlib/BLI_args.h
index 54b5161f15a..2bd0e7b9019 100644
--- a/source/blender/blenlib/BLI_args.h
+++ b/source/blender/blenlib/BLI_args.h
@@ -41,12 +41,14 @@ typedef int (*BA_ArgCallback)(int argc, const char **argv, void *data);
struct bArgs *BLI_argsInit(int argc, const char **argv);
void BLI_argsFree(struct bArgs *ba);
+/** The pass to use for #BLI_argsAdd. */
+void BLI_argsPassSet(struct bArgs *ba, int current_pass);
+
/**
* Pass starts at 1, -1 means valid all the time
* short_arg or long_arg can be null to specify no short or long versions
*/
void BLI_argsAdd(struct bArgs *ba,
- int pass,
const char *short_arg,
const char *long_arg,
const char *doc,
@@ -57,7 +59,6 @@ void BLI_argsAdd(struct bArgs *ba,
* Short_case and long_case specify if those arguments are case specific
*/
void BLI_argsAddCase(struct bArgs *ba,
- int pass,
const char *short_arg,
int short_case,
const char *long_arg,
diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c
index 91aabca7747..4a46bf73f78 100644
--- a/source/blender/blenlib/intern/BLI_args.c
+++ b/source/blender/blenlib/intern/BLI_args.c
@@ -63,6 +63,9 @@ struct bArgs {
int argc;
const char **argv;
int *passes;
+
+ /* Only use when initializing arguments. */
+ int current_pass;
};
static uint case_strhash(const void *ptr)
@@ -128,6 +131,11 @@ void BLI_argsFree(struct bArgs *ba)
MEM_freeN(ba);
}
+void BLI_argsPassSet(struct bArgs *ba, int current_pass)
+{
+ ba->current_pass = current_pass;
+}
+
void BLI_argsPrint(struct bArgs *ba)
{
int i;
@@ -163,14 +171,10 @@ static bArgDoc *internalDocs(struct bArgs *ba,
return d;
}
-static void internalAdd(struct bArgs *ba,
- const char *arg,
- int pass,
- int case_str,
- BA_ArgCallback cb,
- void *data,
- bArgDoc *d)
+static void internalAdd(
+ struct bArgs *ba, const char *arg, int case_str, BA_ArgCallback cb, void *data, bArgDoc *d)
{
+ const int pass = ba->current_pass;
bArgument *a;
bAKey *key;
@@ -204,7 +208,6 @@ static void internalAdd(struct bArgs *ba,
}
void BLI_argsAddCase(struct bArgs *ba,
- int pass,
const char *short_arg,
int short_case,
const char *long_arg,
@@ -216,23 +219,22 @@ void BLI_argsAddCase(struct bArgs *ba,
bArgDoc *d = internalDocs(ba, short_arg, long_arg, doc);
if (short_arg) {
- internalAdd(ba, short_arg, pass, short_case, cb, data, d);
+ internalAdd(ba, short_arg, short_case, cb, data, d);
}
if (long_arg) {
- internalAdd(ba, long_arg, pass, long_case, cb, data, d);
+ internalAdd(ba, long_arg, long_case, cb, data, d);
}
}
void BLI_argsAdd(struct bArgs *ba,
- int pass,
const char *short_arg,
const char *long_arg,
const char *doc,
BA_ArgCallback cb,
void *data)
{
- BLI_argsAddCase(ba, pass, short_arg, 0, long_arg, 0, doc, cb, data);
+ BLI_argsAddCase(ba, short_arg, 0, long_arg, 0, doc, cb, data);
}
static void internalDocPrint(bArgDoc *d)
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index 13e8885ae5d..d1f83b323a4 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -2053,59 +2053,59 @@ void main_args_setup(bContext *C, bArgs *ba)
# define CB(a) a##_doc, a
# define CB_EX(a, b) a##_doc_##b, a
- // BLI_argsAdd(ba, pass, short_arg, long_arg, doc, cb, C);
-
/* end argument processing after -- */
- BLI_argsAdd(ba, -1, "--", NULL, CB(arg_handle_arguments_end), NULL);
+ BLI_argsPassSet(ba, -1);
+ BLI_argsAdd(ba, "--", NULL, CB(arg_handle_arguments_end), NULL);
/* Pass 0: Environment Setup
*
* It's important these run before any initialization is done, since they set up
* the environment used to access data-files, which are be used when initializing
* sub-systems such as color management. */
- BLI_argsAdd(
- ba, 0, NULL, "--python-use-system-env", CB(arg_handle_python_use_system_env_set), NULL);
+ BLI_argsPassSet(ba, 0);
+ BLI_argsAdd(ba, NULL, "--python-use-system-env", CB(arg_handle_python_use_system_env_set), NULL);
/* Note that we could add used environment variables too. */
BLI_argsAdd(
- ba, 0, NULL, "--env-system-datafiles", CB_EX(arg_handle_env_system_set, datafiles), NULL);
- BLI_argsAdd(
- ba, 0, NULL, "--env-system-scripts", CB_EX(arg_handle_env_system_set, scripts), NULL);
- BLI_argsAdd(ba, 0, NULL, "--env-system-python", CB_EX(arg_handle_env_system_set, python), NULL);
+ ba, NULL, "--env-system-datafiles", CB_EX(arg_handle_env_system_set, datafiles), NULL);
+ BLI_argsAdd(ba, NULL, "--env-system-scripts", CB_EX(arg_handle_env_system_set, scripts), NULL);
+ BLI_argsAdd(ba, NULL, "--env-system-python", CB_EX(arg_handle_env_system_set, python), NULL);
/* Pass 1: Background Mode & Settings
*
* Also and commands that exit after usage. */
- BLI_argsAdd(ba, 1, "-h", "--help", CB(arg_handle_print_help), ba);
+ BLI_argsPassSet(ba, 1);
+ BLI_argsAdd(ba, "-h", "--help", CB(arg_handle_print_help), ba);
/* Windows only */
- BLI_argsAdd(ba, 1, "/?", NULL, CB_EX(arg_handle_print_help, win32), ba);
+ BLI_argsAdd(ba, "/?", NULL, CB_EX(arg_handle_print_help, win32), ba);
- BLI_argsAdd(ba, 1, "-v", "--version", CB(arg_handle_print_version), NULL);
+ BLI_argsAdd(ba, "-v", "--version", CB(arg_handle_print_version), NULL);
+ BLI_argsAdd(ba, "-y", "--enable-autoexec", CB_EX(arg_handle_python_set, enable), (void *)true);
BLI_argsAdd(
- ba, 1, "-y", "--enable-autoexec", CB_EX(arg_handle_python_set, enable), (void *)true);
- BLI_argsAdd(
- ba, 1, "-Y", "--disable-autoexec", CB_EX(arg_handle_python_set, disable), (void *)false);
+ ba, "-Y", "--disable-autoexec", CB_EX(arg_handle_python_set, disable), (void *)false);
- BLI_argsAdd(ba, 1, NULL, "--disable-crash-handler", CB(arg_handle_crash_handler_disable), NULL);
- BLI_argsAdd(ba, 1, NULL, "--disable-abort-handler", CB(arg_handle_abort_handler_disable), NULL);
+ BLI_argsAdd(ba, NULL, "--disable-crash-handler", CB(arg_handle_crash_handler_disable), NULL);
+ BLI_argsAdd(ba, NULL, "--disable-abort-handler", CB(arg_handle_abort_handler_disable), NULL);
- BLI_argsAdd(ba, 1, "-b", "--background", CB(arg_handle_background_mode_set), NULL);
+ BLI_argsAdd(ba, "-t", "--threads", CB(arg_handle_threads_set), NULL);
- BLI_argsAdd(ba, 1, "-a", NULL, CB(arg_handle_playback_mode), NULL);
+ BLI_argsAdd(ba, "-b", "--background", CB(arg_handle_background_mode_set), NULL);
- BLI_argsAdd(ba, 1, NULL, "--log", CB(arg_handle_log_set), ba);
- BLI_argsAdd(ba, 1, NULL, "--log-level", CB(arg_handle_log_level_set), ba);
- BLI_argsAdd(ba, 1, NULL, "--log-show-basename", CB(arg_handle_log_show_basename_set), ba);
- BLI_argsAdd(ba, 1, NULL, "--log-show-backtrace", CB(arg_handle_log_show_backtrace_set), ba);
- BLI_argsAdd(ba, 1, NULL, "--log-show-timestamp", CB(arg_handle_log_show_timestamp_set), ba);
- BLI_argsAdd(ba, 1, NULL, "--log-file", CB(arg_handle_log_file_set), ba);
+ BLI_argsAdd(ba, "-a", NULL, CB(arg_handle_playback_mode), NULL);
- BLI_argsAdd(ba, 1, "-d", "--debug", CB(arg_handle_debug_mode_set), ba);
+ BLI_argsAdd(ba, NULL, "--log", CB(arg_handle_log_set), ba);
+ BLI_argsAdd(ba, NULL, "--log-level", CB(arg_handle_log_level_set), ba);
+ BLI_argsAdd(ba, NULL, "--log-show-basename", CB(arg_handle_log_show_basename_set), ba);
+ BLI_argsAdd(ba, NULL, "--log-show-backtrace", CB(arg_handle_log_show_backtrace_set), ba);
+ BLI_argsAdd(ba, NULL, "--log-show-timestamp", CB(arg_handle_log_show_timestamp_set), ba);
+ BLI_argsAdd(ba, NULL, "--log-file", CB(arg_handle_log_file_set), ba);
+
+ BLI_argsAdd(ba, "-d", "--debug", CB(arg_handle_debug_mode_set), ba);
# ifdef WITH_FFMPEG
BLI_argsAdd(ba,
- 1,
+
NULL,
"--debug-ffmpeg",
CB_EX(arg_handle_debug_mode_generic_set, ffmpeg),
@@ -2114,7 +2114,7 @@ void main_args_setup(bContext *C, bArgs *ba)
# ifdef WITH_FREESTYLE
BLI_argsAdd(ba,
- 1,
+
NULL,
"--debug-freestyle",
CB_EX(arg_handle_debug_mode_generic_set, freestyle),
@@ -2122,177 +2122,163 @@ void main_args_setup(bContext *C, bArgs *ba)
# endif
BLI_argsAdd(ba,
- 1,
+
NULL,
"--debug-python",
CB_EX(arg_handle_debug_mode_generic_set, python),
(void *)G_DEBUG_PYTHON);
BLI_argsAdd(ba,
- 1,
+
NULL,
"--debug-events",
CB_EX(arg_handle_debug_mode_generic_set, events),
(void *)G_DEBUG_EVENTS);
BLI_argsAdd(ba,
- 1,
+
NULL,
"--debug-handlers",
CB_EX(arg_handle_debug_mode_generic_set, handlers),
(void *)G_DEBUG_HANDLERS);
BLI_argsAdd(
- ba, 1, NULL, "--debug-wm", CB_EX(arg_handle_debug_mode_generic_set, wm), (void *)G_DEBUG_WM);
+ ba, NULL, "--debug-wm", CB_EX(arg_handle_debug_mode_generic_set, wm), (void *)G_DEBUG_WM);
# ifdef WITH_XR_OPENXR
BLI_argsAdd(
- ba, 1, NULL, "--debug-xr", CB_EX(arg_handle_debug_mode_generic_set, xr), (void *)G_DEBUG_XR);
+ ba, NULL, "--debug-xr", CB_EX(arg_handle_debug_mode_generic_set, xr), (void *)G_DEBUG_XR);
BLI_argsAdd(ba,
- 1,
+
NULL,
"--debug-xr-time",
CB_EX(arg_handle_debug_mode_generic_set, xr_time),
(void *)G_DEBUG_XR_TIME);
# endif
BLI_argsAdd(ba,
- 1,
NULL,
"--debug-ghost",
CB_EX(arg_handle_debug_mode_generic_set, handlers),
(void *)G_DEBUG_GHOST);
- BLI_argsAdd(ba, 1, NULL, "--debug-all", CB(arg_handle_d
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list