diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-01-09 14:35:31 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-01-09 15:06:18 -0800 |
commit | 6f25713408797bb5563af730ca991bc5ec474e33 (patch) | |
tree | 799d7cf822049bc41d33e31c3063e80ce76142b6 | |
parent | a92484e4edd7ad2609d9d9e09cdb064e370e745d (diff) | |
download | subsurface-6f25713408797bb5563af730ca991bc5ec474e33.tar.gz |
Add more infrastructure for a separate dive table
This will allow us to download the dives from the dive computer into a
separate table just for that purpose and not into the main dive_table.
I really dislike the code that's in place that dates back to the very
earliest code written for Subsurface. Dumping the dives straight into the
main dive_table seems really stupid to me.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dive.h | 10 | ||||
-rw-r--r-- | parse-xml.c | 12 | ||||
-rw-r--r-- | qt-ui/subsurfacewebservices.cpp | 9 |
3 files changed, 21 insertions, 10 deletions
@@ -506,6 +506,13 @@ static inline struct dive *get_dive(int nr) return dive_table.dives[nr]; } +static inline struct dive *get_dive_from_table(int nr, struct dive_table *dt) +{ + if (nr >= dt->nr || nr < 0) + return NULL; + return dt->dives[nr]; +} + static inline unsigned int number_of_computers(struct dive *dive) { unsigned int total_number = 0; @@ -677,12 +684,15 @@ extern timestamp_t utc_mktime(struct tm *tm); extern void utc_mkdate(timestamp_t, struct tm *tm); extern struct dive *alloc_dive(void); +extern void record_dive_to_table(struct dive *dive, struct dive_table *table); extern void record_dive(struct dive *dive); extern void clear_dive(struct dive *dive); extern void copy_dive(struct dive *s, struct dive *d); extern void selective_copy_dive(struct dive *s, struct dive *d, struct dive_components what, bool clear); extern struct dive *clone_dive(struct dive *s); +extern void clear_table(struct dive_table *table); + extern struct sample *prepare_sample(struct divecomputer *dc); extern void finish_sample(struct divecomputer *dc); diff --git a/parse-xml.c b/parse-xml.c index fe13f66f2..bd6e21bec 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -49,9 +49,19 @@ int trimspace(char *buffer) { } /* + * Clear a dive_table + */ +void clear_table(struct dive_table *table) +{ + for (int i = 0; i < table->nr; i++) + free(table->dives[i]); + table->nr = 0; +} + +/* * Add a dive into the dive_table array */ -static void record_dive_to_table(struct dive *dive, struct dive_table *table) +void record_dive_to_table(struct dive *dive, struct dive_table *table) { assert(table != NULL); int nr = table->nr, allocated = table->allocated; diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index 646e0ebb3..c98413d12 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -99,15 +99,6 @@ static bool merge_locations_into_dives(void) return changed > 0; } -//TODO: C-code. -static void clear_table(struct dive_table *table) -{ - int i; - for (i = 0; i < table->nr; i++) - free(table->dives[i]); - table->nr = 0; -} - // TODO: This looks like should be ported to C code. or a big part of it. bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected) { |