void collection_print_config (xmmsc_result_t *res, cli_infos_t *infos, gchar *attrname) { xmmsv_coll_t *coll; gchar *attrvalue; xmmsv_t *val; val = xmmsc_result_get_value (res); if (xmmsv_get_coll (val, &coll)) { if (attrname == NULL) { xmmsc_coll_attribute_foreach (coll, coll_print_attributes, NULL); } else { if (xmmsc_coll_attribute_get (coll, attrname, &attrvalue)) { coll_print_attributes (attrname, attrvalue, NULL); } else { g_printf (_("Invalid attribute!\n")); } } } else { g_printf (_("Invalid collection!\n")); } cli_infos_loop_resume (infos); xmmsc_result_unref (res); }
static VALUE c_attrs_has_key (VALUE self, VALUE key) { RbCollection *coll = NULL; VALUE tmp; int s; StringValue (key); tmp = rb_iv_get (self, "collection"); Data_Get_Struct (tmp, RbCollection, coll); s = xmmsc_coll_attribute_get (coll->real, StringValuePtr (key), NULL); return s ? Qtrue : Qfalse; }
static VALUE c_attrs_aref (VALUE self, VALUE key) { RbCollection *coll = NULL; VALUE tmp; int s; char *value; StringValue (key); tmp = rb_iv_get (self, "collection"); Data_Get_Struct (tmp, RbCollection, coll); s = xmmsc_coll_attribute_get (coll->real, StringValuePtr (key), &value); if (!s) return Qnil; return rb_str_new2 (value); }
/* Dump the structure of the collection as a string (from src/clients/cli/cmd_coll.c) */ static void coll_dump (xmmsv_coll_t *coll, guint level) { gint i; gchar *indent; gchar *attr1; gchar *attr2; xmmsv_coll_t *operand; GString *idlist_str; indent = g_malloc ((level * 2) + 1); for (i = 0; i < level * 2; ++i) { indent[i] = ' '; } indent[i] = '\0'; /* type */ switch (xmmsc_coll_get_type (coll)) { case XMMS_COLLECTION_TYPE_REFERENCE: xmmsc_coll_attribute_get (coll, "reference", &attr1); print_info ("%sReference: '%s'", indent, attr1); break; case XMMS_COLLECTION_TYPE_UNION: print_info ("%sUnion:", indent); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; case XMMS_COLLECTION_TYPE_INTERSECTION: print_info ("%sIntersection:", indent); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; case XMMS_COLLECTION_TYPE_COMPLEMENT: print_info ("%sComplement:", indent); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; case XMMS_COLLECTION_TYPE_EQUALS: xmmsc_coll_attribute_get (coll, "field", &attr1); xmmsc_coll_attribute_get (coll, "value", &attr2); print_info ("%sEquals ('%s', '%s') for:", indent, attr1, attr2); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; case XMMS_COLLECTION_TYPE_HAS: xmmsc_coll_attribute_get (coll, "field", &attr1); print_info ("%sHas ('%s') for:", indent, attr1); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; case XMMS_COLLECTION_TYPE_MATCH: xmmsc_coll_attribute_get (coll, "field", &attr1); xmmsc_coll_attribute_get (coll, "value", &attr2); print_info ("%sMatch ('%s', '%s') for:", indent, attr1, attr2); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; case XMMS_COLLECTION_TYPE_SMALLER: xmmsc_coll_attribute_get (coll, "field", &attr1); xmmsc_coll_attribute_get (coll, "value", &attr2); print_info ("%sSmaller ('%s', '%s') for:", indent, attr1, attr2); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; case XMMS_COLLECTION_TYPE_GREATER: xmmsc_coll_attribute_get (coll, "field", &attr1); xmmsc_coll_attribute_get (coll, "value", &attr2); print_info ("%sGreater ('%s', '%s') for:", indent, attr1, attr2); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; case XMMS_COLLECTION_TYPE_IDLIST: idlist_str = coll_idlist_to_string (coll); print_info ("%sIdlist: %s", indent, idlist_str->str); g_string_free (idlist_str, TRUE); break; case XMMS_COLLECTION_TYPE_QUEUE: idlist_str = coll_idlist_to_string (coll); print_info ("%sQueue: %s", indent, idlist_str->str); g_string_free (idlist_str, TRUE); break; case XMMS_COLLECTION_TYPE_PARTYSHUFFLE: idlist_str = coll_idlist_to_string (coll); print_info ("%sParty Shuffle: %s from :", indent, idlist_str->str); g_string_free (idlist_str, TRUE); coll_dump_list (xmmsv_coll_operands_get (coll), level + 1); break; default: print_info ("%sUnknown Operator!", indent); break; } }