Core: dynamically resize weight table

Replace the fixed-size weightsystem table by a dynamically
relocated table. Reuse the table-macros used in other parts
of the code.

The table stores weightsystem entries, not pointers to
weightsystems. Thus, ownership of the description string is
taken when adding a weightsystem. An extra function adds
a cloned weightsystem at the end of the table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-06-26 17:21:03 +02:00 committed by Dirk Hohndel
parent efdb3503ea
commit a5e7f4253a
25 changed files with 182 additions and 154 deletions

View file

@ -447,16 +447,12 @@ void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_o
put_format(&buf, "\n%% Weighting information:\n");
qty_weight = 0;
total_weight = 0;
for (i = 0; i < MAX_WEIGHTSYSTEMS; i++){
if (dive->weightsystem[i].weight.grams){
put_format(&buf, "\\def\\%sweight%ctype{%s}\n", ssrf, 'a' + i, dive->weightsystem[i].description);
put_format(&buf, "\\def\\%sweight%camt{%.3f\\%sweightunit}\n", ssrf, 'a' + i, get_weight_units(dive->weightsystem[i].weight.grams, NULL, &unit), ssrf);
qty_weight += 1;
total_weight += get_weight_units(dive->weightsystem[i].weight.grams, NULL, &unit);
} else {
put_format(&buf, "\\def\\%sweight%ctype{}\n", ssrf, 'a' + i);
put_format(&buf, "\\def\\%sweight%camt{}\n", ssrf, 'a' + i);
}
for (i = 0; i < dive->weightsystems.nr; i++) {
weightsystem_t w = dive->weightsystems.weightsystems[i];
put_format(&buf, "\\def\\%sweight%ctype{%s}\n", ssrf, 'a' + i, w.description);
put_format(&buf, "\\def\\%sweight%camt{%.3f\\%sweightunit}\n", ssrf, 'a' + i, get_weight_units(w.weight.grams, NULL, &unit), ssrf);
qty_weight += 1;
total_weight += get_weight_units(w.weight.grams, NULL, &unit);
}
put_format(&buf, "\\def\\%sqtyweights{%d}\n", ssrf, qty_weight);
put_format(&buf, "\\def\\%stotalweight{%.2f\\%sweightunit}\n", ssrf, total_weight, ssrf);