hal: Branch 'master'
David Zeuthen
david at kemper.freedesktop.org
Wed Feb 28 17:38:32 PST 2007
libhal/libhal.c | 40 ++++++++++++++++++++++++++++++++++++++++
libhal/libhal.h | 4 ++++
tools/lshal.c | 2 ++
3 files changed, 46 insertions(+)
New commits:
diff-tree dae1cb8c47cdf915177a7a4206739dd5105bf0e1 (from 3b99fd882da9559162453043e861d9f09473c1a1)
Author: David Zeuthen <davidz at redhat.com>
Date: Wed Feb 28 20:38:27 2007 -0500
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.
diff --git a/libhal/libhal.c b/libhal/libhal.c
index d7a0c65..89c8a93 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 34135b7..4556189 100644
--- a/libhal/libhal.h
+++ b/libhal/libhal.h
@@ -407,6 +407,10 @@ LibHalPropertySet *libhal_device_get_all
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);
diff --git a/tools/lshal.c b/tools/lshal.c
index b5795c7..ca417d8 100644
--- a/tools/lshal.c
+++ b/tools/lshal.c
@@ -124,6 +124,8 @@ print_props (const char *udi)
return;
}
+ libhal_property_set_sort (props);
+
for (libhal_psi_init (&it, props); libhal_psi_has_more (&it); libhal_psi_next (&it)) {
type = libhal_psi_get_type (&it);
switch (type) {
More information about the hal-commit
mailing list