mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-13 17:20:09 +00:00
a/util: Add DEBUG_GET_ONCE_TRISTATE_OPTION
This commit is contained in:
parent
c0eed827c5
commit
0c4b45c6c2
|
@ -96,6 +96,61 @@ debug_get_bool_option(const char *name, bool _default)
|
|||
return ret;
|
||||
}
|
||||
|
||||
|
||||
enum debug_tristate_option
|
||||
debug_string_to_tristate(const char *raw)
|
||||
{
|
||||
enum debug_tristate_option ret;
|
||||
if (raw == NULL) {
|
||||
ret = DEBUG_TRISTATE_AUTO;
|
||||
} else if (!strcmp(raw, "AUTO")) {
|
||||
ret = DEBUG_TRISTATE_AUTO;
|
||||
} else if (!strcmp(raw, "auto")) {
|
||||
ret = DEBUG_TRISTATE_AUTO;
|
||||
} else if (!strcmp(raw, "a")) {
|
||||
ret = DEBUG_TRISTATE_AUTO;
|
||||
} else if (!strcmp(raw, "A")) {
|
||||
ret = DEBUG_TRISTATE_AUTO;
|
||||
} else {
|
||||
bool bool_ret = debug_string_to_bool(raw);
|
||||
if (bool_ret) {
|
||||
ret = DEBUG_TRISTATE_ON;
|
||||
} else {
|
||||
ret = DEBUG_TRISTATE_OFF;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
enum debug_tristate_option
|
||||
debug_get_tristate_option(const char *name)
|
||||
{
|
||||
const char *raw = os_getenv(name);
|
||||
enum debug_tristate_option ret = debug_string_to_tristate(raw);
|
||||
|
||||
if (debug_get_bool_option_print()) {
|
||||
const char *pretty_val;
|
||||
switch (ret) {
|
||||
case DEBUG_TRISTATE_OFF: {
|
||||
pretty_val = "OFF";
|
||||
break;
|
||||
}
|
||||
case DEBUG_TRISTATE_AUTO: {
|
||||
pretty_val = "AUTO";
|
||||
break;
|
||||
}
|
||||
case DEBUG_TRISTATE_ON: {
|
||||
pretty_val = "ON";
|
||||
break;
|
||||
}
|
||||
default: pretty_val = "invalid";
|
||||
}
|
||||
U_LOG_RAW("%s=%s (%s)", name, pretty_val, raw == NULL ? "nil" : raw);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
long
|
||||
debug_get_num_option(const char *name, long _default)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum debug_tristate_option
|
||||
{
|
||||
DEBUG_TRISTATE_OFF,
|
||||
DEBUG_TRISTATE_AUTO,
|
||||
DEBUG_TRISTATE_ON
|
||||
};
|
||||
|
||||
const char *
|
||||
debug_get_option(const char *name, const char *_default);
|
||||
|
@ -26,6 +32,9 @@ debug_get_option(const char *name, const char *_default);
|
|||
bool
|
||||
debug_string_to_bool(const char *string);
|
||||
|
||||
enum debug_tristate_option
|
||||
debug_get_tristate_option(const char *name);
|
||||
|
||||
bool
|
||||
debug_get_bool_option(const char *name, bool _default);
|
||||
|
||||
|
@ -50,6 +59,18 @@ debug_get_log_option(const char *name, enum u_logging_level _default);
|
|||
return stored; \
|
||||
}
|
||||
|
||||
#define DEBUG_GET_ONCE_TRISTATE_OPTION(suffix, name) \
|
||||
static enum debug_tristate_option debug_get_tristate_option_##suffix() \
|
||||
{ \
|
||||
static bool gotten = false; \
|
||||
static enum debug_tristate_option stored; \
|
||||
if (!gotten) { \
|
||||
gotten = true; \
|
||||
stored = debug_get_tristate_option(name); \
|
||||
} \
|
||||
return stored; \
|
||||
}
|
||||
|
||||
#define DEBUG_GET_ONCE_BOOL_OPTION(suffix, name, _default) \
|
||||
static bool debug_get_bool_option_##suffix() \
|
||||
{ \
|
||||
|
|
Loading…
Reference in a new issue