aboutsummaryrefslogtreecommitdiffstats
path: root/core/parse.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-04-11 17:41:56 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-05-06 13:58:09 -0700
commit989d6a3f96b818e5eacc5a2ccb1cc82e6dd8354c (patch)
tree006daeb578ac4d3e68044ecfc36e7e12b1604ee8 /core/parse.c
parent282041e228d4a60ff7108fbfd1fc23caffd59ba4 (diff)
downloadsubsurface-989d6a3f96b818e5eacc5a2ccb1cc82e6dd8354c.tar.gz
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>
Diffstat (limited to 'core/parse.c')
-rw-r--r--core/parse.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/core/parse.c b/core/parse.c
index be10d65e3..f3b7e0b36 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -31,7 +31,6 @@ void free_parser_state(struct parser_state *state)
free_dive(state->cur_dive);
free_trip(state->cur_trip);
free_dive_site(state->cur_dive_site);
- free_picture(state->cur_picture);
free((void *)state->cur_extra_data.key);
free((void *)state->cur_extra_data.value);
free((void *)state->cur_settings.dc.model);
@@ -106,11 +105,11 @@ void event_end(struct parser_state *state)
{
struct divecomputer *dc = get_dc(state);
if (state->cur_event.type == 123) {
- struct picture *pic = alloc_picture();
- pic->filename = strdup(state->cur_event.name);
+ struct picture pic;
+ pic.filename = strdup(state->cur_event.name);
/* theoretically this could fail - but we didn't support multi year offsets */
- pic->offset.seconds = state->cur_event.time.seconds;
- dive_add_picture(state->cur_dive, pic);
+ pic.offset.seconds = state->cur_event.time.seconds;
+ add_picture(&state->cur_dive->pictures, pic); /* Takes ownership. */
} else {
struct event *ev;
/* At some point gas change events did not have any type. Thus we need to add
@@ -274,13 +273,13 @@ void trip_end(struct parser_state *state)
void picture_start(struct parser_state *state)
{
- state->cur_picture = alloc_picture();
}
void picture_end(struct parser_state *state)
{
- dive_add_picture(state->cur_dive, state->cur_picture);
- state->cur_picture = NULL;
+ add_picture(&state->cur_dive->pictures, state->cur_picture);
+ /* dive_add_picture took ownership, we can just clear out copy of the data */
+ state->cur_picture = empty_picture;
}
cylinder_t *cylinder_start(struct parser_state *state)