| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
#include <string.h> |
| 6 |
#include <glib.h> |
| 7 |
|
| 8 |
#include "debug.h" |
| 9 |
|
| 10 |
static GHashTable *debug_categories = NULL; |
| 11 |
|
| 12 |
void debug_init(void) { |
| 13 |
if (debug_categories) |
| 14 |
return; |
| 15 |
|
| 16 |
debug_categories = g_hash_table_new_full( |
| 17 |
g_str_hash, g_str_equal, g_free, NULL |
| 18 |
); |
| 19 |
|
| 20 |
const char *env = getenv("ALSA_SCARLETT_GUI_DEBUG"); |
| 21 |
if (!env || !*env) |
| 22 |
return; |
| 23 |
|
| 24 |
char *copy = g_strdup(env); |
| 25 |
char *saveptr = NULL; |
| 26 |
char *token = strtok_r(copy, ",", &saveptr); |
| 27 |
|
| 28 |
while (token) { |
| 29 |
|
| 30 |
while (*token == ' ') |
| 31 |
token++; |
| 32 |
char *end = token + strlen(token) - 1; |
| 33 |
while (end > token && *end == ' ') |
| 34 |
*end-- = '\0'; |
| 35 |
|
| 36 |
if (*token) |
| 37 |
g_hash_table_insert(debug_categories, g_strdup(token), (void *)1); |
| 38 |
|
| 39 |
token = strtok_r(NULL, ",", &saveptr); |
| 40 |
} |
| 41 |
|
| 42 |
g_free(copy); |
| 43 |
} |
| 44 |
|
| 45 |
int debug_enabled(const char *category) { |
| 46 |
if (!debug_categories || !category) |
| 47 |
return 0; |
| 48 |
|
| 49 |
return g_hash_table_contains(debug_categories, category); |
| 50 |
} |