diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-09-06 12:39:51 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-09-06 12:59:54 -0700 |
commit | 7f1def86021eda8cc01911b4944be4bc38ae65fe (patch) | |
tree | 49eec74b2d0a4789e328f9f1728be3aeb882e72f /core/parse-xml.c | |
parent | 55e42373066ade9ad2e1a51adf27a0a28cb0d02a (diff) | |
download | subsurface-7f1def86021eda8cc01911b4944be4bc38ae65fe.tar.gz |
cleanup: use taxonomy_set_category() function
Instead of manipulating the taxonomy structures directly, use the
taxonomy_set_category() function. This improves encapsulation and
gives us the possibility to improve the taxonomy data structures.
This concerns three places:
1) git parser
2) XML parser
3) reverse geo-lookup
This improves the XML parser code slightly: The parser assumes that
the value-attribute comes last (after origin and category). While
it still does that, it now at least generates a warning if it encounters
a value-attribute without origin- or category-attribute.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/parse-xml.c')
-rw-r--r-- | core/parse-xml.c | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/core/parse-xml.c b/core/parse-xml.c index 0d52eb733..22de449cc 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -1377,12 +1377,12 @@ static void try_to_fill_trip(dive_trip_t *dive_trip, const char *name, char *buf } /* We're processing a divesite entry - try to fill the components */ -static void try_to_fill_dive_site(struct dive_site *ds, const char *name, char *buf) +static void try_to_fill_dive_site(struct parser_state *state, const char *name, char *buf) { - start_match("divesite", name, buf); + struct dive_site *ds = state->cur_dive_site; + char *taxonomy_value = NULL; - if (ds->taxonomy.category == NULL) - ds->taxonomy.category = alloc_taxonomy(); + start_match("divesite", name, buf); if (MATCH("uuid", hex_value, &ds->uuid)) return; @@ -1394,13 +1394,22 @@ static void try_to_fill_dive_site(struct dive_site *ds, const char *name, char * return; if (MATCH("gps", gps_location, ds)) return; - if (MATCH("cat.geo", get_index, (int *)&ds->taxonomy.category[ds->taxonomy.nr].category)) + if (MATCH("cat.geo", get_index, &state->taxonomy_category)) return; - if (MATCH("origin.geo", get_index, (int *)&ds->taxonomy.category[ds->taxonomy.nr].origin)) + if (MATCH("origin.geo", get_index, &state->taxonomy_origin)) return; - if (MATCH("value.geo", utf8_string, &ds->taxonomy.category[ds->taxonomy.nr].value)) { - if (ds->taxonomy.nr < TC_NR_CATEGORIES) - ds->taxonomy.nr++; + if (MATCH("value.geo", utf8_string, &taxonomy_value)) { + /* The code assumes that "value.geo" comes last, which is against + * the expectations of an XML file. Let's at least make sure that + * cat and origin have been set! */ + if (state->taxonomy_category < 0 || state->taxonomy_origin < 0) { + report_error("Warning: taxonomy value without origin or category"); + } else { + taxonomy_set_category(&ds->taxonomy, state->taxonomy_category, + taxonomy_value, state->taxonomy_origin); + } + state->taxonomy_category = state->taxonomy_origin = -1; + free(taxonomy_value); return; } @@ -1423,7 +1432,7 @@ static bool entry(const char *name, char *buf, struct parser_state *state) return true; } if (state->cur_dive_site) { - try_to_fill_dive_site(state->cur_dive_site, name, buf); + try_to_fill_dive_site(state, name, buf); return true; } if (!state->cur_event.deleted) { |