From 1e34e19c6d067b469ad915a39561ccf5a831ec22 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 6 Oct 2020 21:46:44 +0200 Subject: 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 --- core/save-xml.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'core') 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, "\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, "\n\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, " \n"); put_format(b, "\n"); -- cgit v1.2.3-70-g09d2