diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-06-26 17:21:03 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-07-18 06:01:07 -0700 |
commit | a5e7f4253ac98ad18354973fda7049e9daaea8eb (patch) | |
tree | 16b95a18d0a1af296e4645d6b7a204b5b325ff01 /core/load-git.c | |
parent | efdb3503eadd7e47cb64b1c252e50488d2e9d0fe (diff) | |
download | subsurface-a5e7f4253ac98ad18354973fda7049e9daaea8eb.tar.gz |
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>
Diffstat (limited to 'core/load-git.c')
-rw-r--r-- | core/load-git.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/core/load-git.c b/core/load-git.c index ee31e99ac..b23204b79 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -330,7 +330,7 @@ static char *parse_keyvalue_entry(void (*fn)(void *, const char *, const char *) return line; } -static int cylinder_index, weightsystem_index; +static int cylinder_index; static int o2pressure_sensor; static void parse_cylinder_keyvalue(void *_cylinder, const char *key, const char *value) @@ -424,21 +424,19 @@ static void parse_weightsystem_keyvalue(void *_ws, const char *key, const char * static void parse_dive_weightsystem(char *line, struct membuffer *str, void *_dive) { struct dive *dive = _dive; - weightsystem_t *ws = dive->weightsystem + weightsystem_index; + weightsystem_t ws = { 0 }; - if (weightsystem_index >= MAX_WEIGHTSYSTEMS) - return; - - weightsystem_index++; - ws->description = get_utf8(str); + ws.description = get_utf8(str); for (;;) { char c; while (isspace(c = *line)) line++; if (!c) break; - line = parse_keyvalue_entry(parse_weightsystem_keyvalue, ws, line); + line = parse_keyvalue_entry(parse_weightsystem_keyvalue, &ws, line); } + + add_to_weightsystem_table(&dive->weightsystems, dive->weightsystems.nr, ws); } static int match_action(char *line, struct membuffer *str, void *data, @@ -1506,7 +1504,8 @@ static int parse_dive_entry(git_repository *repo, const git_tree_entry *entry, c return report_error("Unable to read dive file"); if (*suffix) dive->number = atoi(suffix+1); - cylinder_index = weightsystem_index = 0; + cylinder_index = 0; + clear_weightsystem_table(&dive->weightsystems); o2pressure_sensor = 1; for_each_line(blob, dive_parser, active_dive); git_blob_free(blob); |