summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-05 21:38:22 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-16 14:26:37 -0700
commite8d3f75541765fce3193b19a2f30ac8f827e00f5 (patch)
treef2d26dd91d8ea44cf78975af9a353d1223a9a96b
parent7aca64bfca4b9937369a271da8ed5f9445bb4bad (diff)
downloadsubsurface-e8d3f75541765fce3193b19a2f30ac8f827e00f5.tar.gz
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 <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/save-git.c22
1 files 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)