summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-01-30 09:25:09 +1100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-30 14:38:07 +1100
commit9099972c20a49a96a0abac2ff2c4b163b59c6883 (patch)
treed31e3a874f42f11e451cb35dc919c442f4ee303e
parent702493053063688e6341fc1cfc3f9450c120b4ba (diff)
downloadsubsurface-9099972c20a49a96a0abac2ff2c4b163b59c6883.tar.gz
Make 'get_dive_by_diveid()' work even for non-primary dive computers
It's only used by the Uemis importer, and Dirk always seems to import his Uemis data first, so it wasn't very noticeable. But if the Uemis data wasn't the first dive computer, it would not find the dive. Side note: just comparing deviceid is not correct. We should pass in the device model too. But again, that will realistically never really matter, since non-Uemis importers will generate complex SHA1 hashes of the dive data for the dive ID, so a collision with the Uemis numbers is very unlikely. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.h31
1 files changed, 18 insertions, 13 deletions
diff --git a/dive.h b/dive.h
index 120393b6b..4132d0c30 100644
--- a/dive.h
+++ b/dive.h
@@ -440,19 +440,6 @@ static inline struct dive *get_dive(int nr)
return dive_table.dives[nr];
}
-static inline struct dive *get_dive_by_diveid(int diveid, int deviceid)
-{
- int i;
- for (i = 0; i < dive_table.nr; i++)
- if (dive_table.dives[i]->dc.diveid == diveid &&
- dive_table.dives[i]->dc.deviceid == deviceid)
- return dive_table.dives[i];
- return NULL;
-}
-
-/* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */
-extern int match_one_dc(struct divecomputer *a, struct divecomputer *b);
-
/*
* Iterate over each dive, with the first parameter being the index
* iterator variable, and the second one being the dive one.
@@ -463,6 +450,24 @@ extern int match_one_dc(struct divecomputer *a, struct divecomputer *b);
#define for_each_dive(_i,_x) \
for ((_i) = 0; ((_x) = get_dive(_i)) != NULL; (_i)++)
+static inline struct dive *get_dive_by_diveid(int diveid, int deviceid)
+{
+ int i;
+ struct dive *dive;
+
+ for_each_dive(i, dive) {
+ struct divecomputer *dc = &dive->dc;
+ do {
+ if (dc->diveid == diveid && dc->deviceid == deviceid)
+ return dive;
+ } while ((dc = dc->next) != NULL);
+ }
+ return NULL;
+}
+
+/* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */
+extern int match_one_dc(struct divecomputer *a, struct divecomputer *b);
+
extern void parse_xml_init(void);
extern void parse_xml_buffer(const char *url, const char *buf, int size, GError **error);
extern void parse_xml_exit(void);