From e8d3f75541765fce3193b19a2f30ac8f827e00f5 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 5 Oct 2020 21:38:22 +0200 Subject: core: use C accessors in core/save-git.c instead of callback Now we can simply loop over the list of devices. In this case, it's not much more readable, but at least we don't have that nasty pass user-data through "void *" pattern. Signed-off-by: Berthold Stoeger --- core/save-git.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/core/save-git.c b/core/save-git.c index 4c8969047..041f01223 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -845,21 +845,22 @@ static void save_units(void *_b) prefs.units.vertical_speed_time == SECONDS ? "SECONDS" : "MINUTES"); } -static void save_one_device(void *_b, const char *model, uint32_t deviceid, - const char *nickname, const char *serial, const char *firmware) +static void save_one_device(struct membuffer *b, const struct device *d) { - struct membuffer *b = _b; - - if (nickname && !strcmp(model, nickname)) + const char *model = device_get_model(d); + const char *nickname = device_get_nickname(d); + const char *serial = device_get_serial(d); + const char *firmware = device_get_firmware(d); + if (!empty_string(nickname) && !strcmp(model, nickname)) nickname = NULL; - if (serial && !*serial) serial = NULL; - if (firmware && !*firmware) firmware = NULL; - if (nickname && !*nickname) nickname = NULL; + if (empty_string(serial)) serial = NULL; + if (empty_string(firmware)) firmware = NULL; + if (empty_string(nickname)) nickname = NULL; if (!nickname && !serial && !firmware) return; show_utf8(b, "divecomputerid ", model, ""); - put_format(b, " deviceid=%08x", deviceid); + put_format(b, " deviceid=%08x", device_get_id(d)); show_utf8(b, " serial=", serial, ""); show_utf8(b, " firmware=", firmware, ""); show_utf8(b, " nickname=", nickname, ""); @@ -871,7 +872,8 @@ static void save_settings(git_repository *repo, struct dir *tree) struct membuffer b = { 0 }; put_format(&b, "version %d\n", DATAFORMAT_VERSION); - call_for_each_dc(&b, save_one_device, false); + for (int i = 0; i < nr_devices(&device_table); i++) + save_one_device(&b, get_device(&device_table, i)); cond_put_format(autogroup, &b, "autogroup\n"); save_units(&b); if (prefs.tankbar) -- cgit v1.2.3-70-g09d2