The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

a/util: Add DEBUG_GET_ONCE_TRISTATE_OPTION

authored by

Moses Turner and committed by
Jakob Bornecrantz
0c4b45c6 c0eed827

+76
+55
src/xrt/auxiliary/util/u_debug.c
··· 96 96 return ret; 97 97 } 98 98 99 + 100 + enum debug_tristate_option 101 + debug_string_to_tristate(const char *raw) 102 + { 103 + enum debug_tristate_option ret; 104 + if (raw == NULL) { 105 + ret = DEBUG_TRISTATE_AUTO; 106 + } else if (!strcmp(raw, "AUTO")) { 107 + ret = DEBUG_TRISTATE_AUTO; 108 + } else if (!strcmp(raw, "auto")) { 109 + ret = DEBUG_TRISTATE_AUTO; 110 + } else if (!strcmp(raw, "a")) { 111 + ret = DEBUG_TRISTATE_AUTO; 112 + } else if (!strcmp(raw, "A")) { 113 + ret = DEBUG_TRISTATE_AUTO; 114 + } else { 115 + bool bool_ret = debug_string_to_bool(raw); 116 + if (bool_ret) { 117 + ret = DEBUG_TRISTATE_ON; 118 + } else { 119 + ret = DEBUG_TRISTATE_OFF; 120 + } 121 + } 122 + return ret; 123 + } 124 + 125 + enum debug_tristate_option 126 + debug_get_tristate_option(const char *name) 127 + { 128 + const char *raw = os_getenv(name); 129 + enum debug_tristate_option ret = debug_string_to_tristate(raw); 130 + 131 + if (debug_get_bool_option_print()) { 132 + const char *pretty_val; 133 + switch (ret) { 134 + case DEBUG_TRISTATE_OFF: { 135 + pretty_val = "OFF"; 136 + break; 137 + } 138 + case DEBUG_TRISTATE_AUTO: { 139 + pretty_val = "AUTO"; 140 + break; 141 + } 142 + case DEBUG_TRISTATE_ON: { 143 + pretty_val = "ON"; 144 + break; 145 + } 146 + default: pretty_val = "invalid"; 147 + } 148 + U_LOG_RAW("%s=%s (%s)", name, pretty_val, raw == NULL ? "nil" : raw); 149 + } 150 + 151 + return ret; 152 + } 153 + 99 154 long 100 155 debug_get_num_option(const char *name, long _default) 101 156 {
+21
src/xrt/auxiliary/util/u_debug.h
··· 19 19 extern "C" { 20 20 #endif 21 21 22 + enum debug_tristate_option 23 + { 24 + DEBUG_TRISTATE_OFF, 25 + DEBUG_TRISTATE_AUTO, 26 + DEBUG_TRISTATE_ON 27 + }; 22 28 23 29 const char * 24 30 debug_get_option(const char *name, const char *_default); 25 31 26 32 bool 27 33 debug_string_to_bool(const char *string); 34 + 35 + enum debug_tristate_option 36 + debug_get_tristate_option(const char *name); 28 37 29 38 bool 30 39 debug_get_bool_option(const char *name, bool _default); ··· 46 55 if (!gotten) { \ 47 56 gotten = true; \ 48 57 stored = debug_get_option(name, _default); \ 58 + } \ 59 + return stored; \ 60 + } 61 + 62 + #define DEBUG_GET_ONCE_TRISTATE_OPTION(suffix, name) \ 63 + static enum debug_tristate_option debug_get_tristate_option_##suffix() \ 64 + { \ 65 + static bool gotten = false; \ 66 + static enum debug_tristate_option stored; \ 67 + if (!gotten) { \ 68 + gotten = true; \ 69 + stored = debug_get_tristate_option(name); \ 49 70 } \ 50 71 return stored; \ 51 72 }