Module: Mesa Branch: main Commit: 419274773750673da992e5bcb2292a1065434e31 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=419274773750673da992e5bcb2292a1065434e31
Author: Lionel Landwerlin <[email protected]> Date: Sun May 22 15:46:48 2022 +0300 util/debug: add an enable parsing helper This allows to parse something like : ENV_VAR=+a,-b which will enable a and disable b. Signed-off-by: Lionel Landwerlin <[email protected]> Reviewed-by: Danylo Piliaiev <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16717> --- src/util/debug.c | 42 ++++++++++++++++++++++++++++++++++++++++++ src/util/debug.h | 4 ++++ 2 files changed, 46 insertions(+) diff --git a/src/util/debug.c b/src/util/debug.c index 89ae6131074..b7b49ae8974 100644 --- a/src/util/debug.c +++ b/src/util/debug.c @@ -53,6 +53,48 @@ parse_debug_string(const char *debug, return flag; } +uint64_t +parse_enable_string(const char *debug, + uint64_t default_value, + const struct debug_control *control) +{ + uint64_t flag = default_value; + + if (debug != NULL) { + for (; control->string != NULL; control++) { + if (!strcmp(debug, "all")) { + flag |= control->flag; + + } else { + const char *s = debug; + unsigned n; + + for (; n = strcspn(s, ", "), *s; s += MAX2(1, n)) { + bool enable; + if (s[0] == '+') { + enable = true; + s++; n--; + } else if (s[0] == '-') { + enable = false; + s++; n--; + } else { + enable = true; + } + if (strlen(control->string) == n && + !strncmp(control->string, s, n)) { + if (enable) + flag |= control->flag; + else + flag &= ~control->flag; + } + } + } + } + } + + return flag; +} + bool comma_separated_list_contains(const char *list, const char *s) { diff --git a/src/util/debug.h b/src/util/debug.h index bbcc1975545..6d48ea08fcf 100644 --- a/src/util/debug.h +++ b/src/util/debug.h @@ -39,6 +39,10 @@ struct debug_control { uint64_t parse_debug_string(const char *debug, const struct debug_control *control); +uint64_t +parse_enable_string(const char *debug, + uint64_t default_value, + const struct debug_control *control); bool comma_separated_list_contains(const char *list, const char *s); bool
