mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
efdb3503ea
commit
a5e7f4253a
25 changed files with 182 additions and 154 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue