aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-06 21:46:44 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-16 14:26:37 -0700
commit1e34e19c6d067b469ad915a39561ccf5a831ec22 (patch)
treeeda6092956bb76fca7a0abe38d3ad5a59398dd97
parentd93b261e8954e8ce5f652d0af2dcf0b379c1bed1 (diff)
downloadsubsurface-1e34e19c6d067b469ad915a39561ccf5a831ec22.tar.gz
core: use C accessors in core/save-xml.c instead of callback
We now can loop over devices from C and check for selection. So let's get rid of the last user of the call_for_all_devices() callback. Code readability improvement is not stellar, but one less place where we shoe-horn user data through a void-pointer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/save-xml.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/core/save-xml.c b/core/save-xml.c
index 0f2d92439..6da9a7528 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -574,23 +574,23 @@ static void save_trip(struct membuffer *b, dive_trip_t *trip, bool anonymize)
put_format(b, "</trip>\n");
}
-static void save_one_device(void *_f, const char *model, uint32_t deviceid,
- const char *nickname, const char *serial_nr, const char *firmware)
+static void save_one_device(struct membuffer *b, const struct device *d)
{
- struct membuffer *b = _f;
+ const char *model = device_get_model(d);
+ const char *nickname = device_get_nickname(d);
+ const char *serial_nr = device_get_serial(d);
+ const char *firmware = device_get_firmware(d);
/* Nicknames that are empty or the same as the device model are not interesting */
- if (nickname) {
- if (!*nickname || !strcmp(model, nickname))
+ if (empty_string(nickname) || !strcmp(model, nickname))
nickname = NULL;
- }
/* Serial numbers that are empty are not interesting */
- if (serial_nr && !*serial_nr)
+ if (empty_string(serial_nr))
serial_nr = NULL;
/* Firmware strings that are empty are not interesting */
- if (firmware && !*firmware)
+ if (empty_string(firmware))
firmware = NULL;
/* Do we have anything interesting about this dive computer to save? */
@@ -599,7 +599,7 @@ static void save_one_device(void *_f, const char *model, uint32_t deviceid,
put_format(b, "<divecomputerid");
show_utf8(b, model, " model='", "'", 1);
- put_format(b, " deviceid='%08x'", deviceid);
+ put_format(b, " deviceid='%08x'", device_get_id(d));
show_utf8(b, serial_nr, " serial='", "'", 1);
show_utf8(b, firmware, " firmware='", "'", 1);
show_utf8(b, nickname, " nickname='", "'", 1);
@@ -670,7 +670,11 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION);
/* save the dive computer nicknames, if any */
- call_for_each_dc(b, save_one_device, select_only);
+ for (int i = 0; i < nr_devices(&device_table); i++) {
+ const struct device *d = get_device(&device_table, i);
+ if (!select_only || device_used_by_selected_dive(d))
+ save_one_device(b, d);
+ }
if (autogroup)
put_format(b, " <autogroup state='1' />\n");
put_format(b, "</settings>\n");