-static
-void escape_json_string(const char *str, GString *escaped_str)
-{
- g_string_assign(escaped_str, "");
-
- for (const char *ch = str; *ch; ch++) {
- if (*ch == '\\' || *ch == '"') {
- g_string_append_c(escaped_str, '\\');
- }
-
- g_string_append_c(escaped_str, *ch);
- }
-}
-
-static
-void list_triggers(const struct cond_trigger triggers[], size_t trigger_count)
-{
- GString *escaped_str = g_string_new(NULL);
- size_t i;
-
- BT_ASSERT(escaped_str);
- printf("[");
-
- for (i = 0; i < trigger_count; i++) {
- const struct cond_trigger *trigger = &triggers[i];
-
- /* Condition ID */
- escape_json_string(trigger->cond_id, escaped_str);
- printf("{\"cond-id\":\"%s\",", escaped_str->str);
-
- /* Name starts with condition ID */
- printf("\"name\":\"%s", escaped_str->str);
-
- if (trigger->suffix) {
- escape_json_string(trigger->suffix, escaped_str);
- printf("-%s", escaped_str->str);
- }
-
- printf("\"}");
-
- if (i < trigger_count - 1) {
- /* Comma between objects */
- printf(",");
- }
- }
-
- printf("]");
- g_string_free(escaped_str, TRUE);
- fflush(stdout);
-}