media: use table instead of linked list for media

For consistency with equipment, use our table macros for pictures.
Generally tables (arrays) are preferred over linked lists, because
they allow random access.

This is mostly copy & paste of the equipment code.

Sadly, our table macros are quite messy and need some revamping.
Therefore, the resulting code is likewise somewhat messy.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-04-11 17:41:56 +02:00 committed by Dirk Hohndel
parent 282041e228
commit 989d6a3f96
15 changed files with 136 additions and 106 deletions

View file

@ -34,7 +34,7 @@ struct git_parser_state {
struct divecomputer *active_dc;
struct dive *active_dive;
dive_trip_t *active_trip;
struct picture *active_pic;
struct picture active_pic;
struct dive_site *active_site;
struct dive_table *table;
struct trip_table *trips;
@ -1006,13 +1006,13 @@ static void parse_settings_divecomputerid(char *line, struct membuffer *str, str
static void parse_picture_filename(char *line, struct membuffer *str, struct git_parser_state *state)
{
UNUSED(line);
state->active_pic->filename = detach_cstring(str);
state->active_pic.filename = detach_cstring(str);
}
static void parse_picture_gps(char *line, struct membuffer *str, struct git_parser_state *state)
{
UNUSED(str);
parse_location(line, &state->active_pic->location);
parse_location(line, &state->active_pic.location);
}
static void parse_picture_hash(char *line, struct membuffer *str, struct git_parser_state *state)
@ -1615,13 +1615,15 @@ static int parse_picture_entry(struct git_parser_state *state, const git_tree_en
if (!blob)
return report_error("Unable to read picture file");
state->active_pic = alloc_picture();
state->active_pic->offset.seconds = offset;
state->active_pic.offset.seconds = offset;
for_each_line(blob, picture_parser, state);
dive_add_picture(state->active_dive, state->active_pic);
add_picture(&state->active_dive->pictures, state->active_pic);
git_blob_free(blob);
state->active_pic = NULL;
/* add_picture took ownership of the data -
* clear out our copy just to be sure. */
state->active_pic = empty_picture;
return 0;
}