void ghb_dict_set_bool(GhbValue *dict, const gchar *key, gboolean bval) { GhbValue *value; value = ghb_bool_value_new(bval); ghb_dict_set(dict, key, value); }
static void end_element( GMarkupParseContext *ctx, const gchar *name, gpointer ud, GError **error) { parse_data_t *pd = (parse_data_t*)ud; gint id; union { gint id; gpointer pid; } start_id; gint ii; // Check to see if the first element found has been closed // If so, ignore any junk following it. if (pd->closed_top) return; for (ii = 0; ii < TAG_MAP_SZ; ii++) { if (strcmp(name, tag_map[ii].tag) == 0) { id = tag_map[ii].id; break; } } if (ii == TAG_MAP_SZ) { g_warning("Unrecognized start tag (%s)", name); return; } start_id.pid = g_queue_pop_head(pd->tag_stack); if (start_id.id != id) g_warning("start tag != end tag: (%s %d) %d", name, id, id); GhbValue *gval = NULL; GhbValue *current = g_queue_peek_head(pd->stack); GhbType gtype = 0; switch (id) { case P_PLIST: { // Ignore } break; case P_KEY: { if (pd->key) g_free(pd->key); pd->key = g_strdup(pd->value); return; } break; case P_DICT: { g_queue_pop_head(pd->stack); } break; case P_ARRAY: { g_queue_pop_head(pd->stack); } break; case P_INTEGER: { gint64 val = g_strtod(pd->value, NULL); gval = ghb_int_value_new(val); } break; case P_REAL: { gdouble val = g_strtod(pd->value, NULL); gval = ghb_double_value_new(val); } break; case P_STRING: { gval = ghb_string_value_new(pd->value); } break; case P_TRUE: { gval = ghb_bool_value_new(TRUE); } break; case P_FALSE: { gval = ghb_bool_value_new(FALSE); } break; default: { g_message("Unhandled plist type %d", id); } break; } if (gval) { // Get the top of the data structure stack and if it's an array // or dict, add the current element if (current == NULL) { pd->plist = gval; pd->closed_top = TRUE; return; } gtype = ghb_value_type(current); if (gtype == GHB_ARRAY) { ghb_array_append(current, gval); } else if (gtype == GHB_DICT) { if (pd->key == NULL) { g_warning("No key for dictionary item"); ghb_value_free(&gval); } else { ghb_dict_set(current, pd->key, gval); } } else { g_error("Invalid container type. This shouldn't happen"); } } if (g_queue_is_empty(pd->stack)) pd->closed_top = TRUE; }