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>
This commit is contained in:
Berthold Stoeger 2020-10-05 21:38:22 +02:00 committed by Dirk Hohndel
parent 7aca64bfca
commit e8d3f75541

View file

@ -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)