summaryrefslogtreecommitdiffstats
path: root/device.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-02-03 20:51:50 +1100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-03 21:28:13 +1100
commitb5a232cf32bf529817505c0680cfab7bb3700c7a (patch)
tree4952cdb33f0c948a32eb9648cd0be77f04101b7c /device.c
parentec0535d4dfe42d7e41c8a19d7fc196b0259bf49e (diff)
downloadsubsurface-b5a232cf32bf529817505c0680cfab7bb3700c7a.tar.gz
Sort the devices when adding them to the device list
This doesn't change any real semantics, but it means that we will write out the device computer information in a well-defined order, rather than in some random order (before this: reverse order of reading them in). Having the XML file be as stable as possible is important so that *real* changes stand out when you make changes to your dives. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'device.c')
-rw-r--r--device.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/device.c b/device.c
index 38e409980..660cfc1ab 100644
--- a/device.c
+++ b/device.c
@@ -31,6 +31,29 @@ struct device_info *get_device_info(const char *model, uint32_t deviceid)
return NULL;
}
+/*
+ * Sort the device_info list, so that we write it out
+ * in a stable order. Otherwise we'll end up having the
+ * XML file have the devices listed in some arbitrary
+ * order, which is annoying.
+ */
+static void add_entry_sorted(struct device_info *entry)
+{
+ struct device_info *p, **pp = &device_info_list;
+
+ while ((p = *pp) != NULL) {
+ int cmp = strcmp(p->model, entry->model);
+ if (cmp > 0)
+ break;
+ if (!cmp && p->deviceid > entry->deviceid)
+ break;
+ pp = &p->next;
+ }
+
+ entry->next = p;
+ *pp = entry;
+}
+
/* Get an existing device info model or create a new one if valid */
struct device_info *create_device_info(const char *model, uint32_t deviceid)
{
@@ -45,8 +68,7 @@ struct device_info *create_device_info(const char *model, uint32_t deviceid)
if (entry) {
entry->model = strdup(model);
entry->deviceid = deviceid;
- entry->next = device_info_list;
- device_info_list = entry;
+ add_entry_sorted(entry);
}
return entry;
}