diff options
author | Guido Lerch <guido.lerch@gmail.com> | 2015-09-05 11:21:14 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-05 11:29:13 -0700 |
commit | fa56d5d1361b66bc453009f32dfe4b1b90ddca32 (patch) | |
tree | b06cddd935fae853d9f3d20321481e34ce20ea1c | |
parent | 040caaa00b6874e1e93320d4c1c1aa6abba8fee4 (diff) | |
download | subsurface-fa56d5d1361b66bc453009f32dfe4b1b90ddca32.tar.gz |
Uemis downloader: add heler function to delete dive
[Dirk Hohndel: refactored one huge commit into smaller pieces]
Signed-off-by: Guido Lerch <guido.lerch@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | uemis-downloader.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/uemis-downloader.c b/uemis-downloader.c index fdaea876a..a503f91a7 100644 --- a/uemis-downloader.c +++ b/uemis-downloader.c @@ -732,6 +732,40 @@ static void parse_tag(struct dive *dive, char *tag, char *val) } } +static bool uemis_delete_dive(device_data_t *devdata, uint32_t diveid) +{ + struct dive *dive = NULL; + + if (devdata->download_table->dives[devdata->download_table->nr - 1]->dc.diveid == diveid) { + /* we hit the last one in the array */ + dive = devdata->download_table->dives[devdata->download_table->nr - 1]; + } else { + for (int i = 0; i < devdata->download_table->nr - 1; i++) { + if (devdata->download_table->dives[i]->dc.diveid == diveid) { + dive = devdata->download_table->dives[i]; + for (int x = i; x < devdata->download_table->nr - 1; x++) + devdata->download_table->dives[i] = devdata->download_table->dives[x + 1]; + } + } + } + if (dive) { + devdata->download_table->dives[--devdata->download_table->nr] = NULL; + if (dive->tripflag != TF_NONE) + remove_dive_from_trip(dive, false); + + free(dive->dc.sample); + free((void *)dive->notes); + free((void *)dive->divemaster); + free((void *)dive->buddy); + free((void *)dive->suit); + taglist_free(dive->tag_list); + free(dive); + + return true; + } + return false; +} + /* This function is called for both divelog and dive information that we get * from the SDA (what an insane design, btw). The object_id in the divelog * matches the logfilenr in the dive information (which has its own, often |