summaryrefslogtreecommitdiff
path: root/libhal
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2007-02-28 20:38:27 -0500
committerDavid Zeuthen <davidz@redhat.com>2007-02-28 20:38:27 -0500
commitdae1cb8c47cdf915177a7a4206739dd5105bf0e1 (patch)
treecfd954dcce9aaf5760f11d1513117ea257d88bcb /libhal
parent3b99fd882da9559162453043e861d9f09473c1a1 (diff)
sort properties in lshal output
I can't believe I didn't implement this earlier. Also extend libhal with a libhal_property_set_sort() method and provide a lame bubble-sort implementation for now.
Diffstat (limited to 'libhal')
-rw-r--r--libhal/libhal.c40
-rw-r--r--libhal/libhal.h4
2 files changed, 44 insertions, 0 deletions
diff --git a/libhal/libhal.c b/libhal/libhal.c
index d7a0c659..89c8a938 100644
--- a/libhal/libhal.c
+++ b/libhal/libhal.c
@@ -493,6 +493,46 @@ oom:
return NULL;
}
+/* libhal_property_set_sort:
+ * @set: property-set to sort
+ *
+ * sort all properties according to property name
+ */
+void
+libhal_property_set_sort (LibHalPropertySet *set)
+{
+ unsigned int i;
+ unsigned int num_elements;
+ LibHalProperty *p;
+ LibHalProperty *q;
+ LibHalProperty **r;
+
+ /* TODO: for the sake of gods; do something smarter than a slow bubble-sort!! */
+
+ num_elements = libhal_property_set_get_num_elems (set);
+ for (i = 0; i < num_elements; i++) {
+ for (p = set->properties_head, r = &(set->properties_head); p != NULL; p = q) {
+ q = p->next;
+
+ if (q == NULL)
+ continue;
+
+ if (strcmp (p->key, q->key) > 0) {
+ /* switch p and q */
+ p->next = q->next;
+ q->next = p;
+ *r = q;
+
+ r = &(q->next);
+ q = p;
+ } else {
+ /* do nothing */
+ r = &(p->next);
+ }
+ }
+ }
+}
+
/**
* libhal_free_property_set:
* @set: property-set to free
diff --git a/libhal/libhal.h b/libhal/libhal.h
index 34135b75..45561894 100644
--- a/libhal/libhal.h
+++ b/libhal/libhal.h
@@ -407,6 +407,10 @@ LibHalPropertySet *libhal_device_get_all_properties (LibHalContext *ctx,
const char *udi,
DBusError *error);
+
+/* sort all properties according to property name */
+void libhal_property_set_sort (LibHalPropertySet *set);
+
/* Free a property set earlier obtained with libhal_device_get_all_properties(). */
void libhal_free_property_set (LibHalPropertySet *set);