diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-06-17 22:45:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-09-29 16:13:03 -0700 |
commit | 41cf83583d129edde607654592a52fe7bff57dc7 (patch) | |
tree | 7127476f88358f2248b22684c01f127997380d43 /core/parse-xml.c | |
parent | cef15c978d466af37a0f453c50f2e8942ed7cdc2 (diff) | |
download | subsurface-41cf83583d129edde607654592a52fe7bff57dc7.tar.gz |
filter: load filter presets from XML files
This is a bit painful: since we don't want to modify the filter
presets when the user imports (as opposed to opens) a log,
we have to provide a table where the parser stores the presets.
Calling the parser is getting quite unwieldy, since many tables
are passed. We probably should introduce a structure representing
a full log-book at one point, which collects all the things that
are saved to the log.
Apart from that, this is simply the counterpart to saving to XML.
The interpretation of the string data is performed by core
functions, not the parser itself to avoid code duplication with
the git parser.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/parse-xml.c')
-rw-r--r-- | core/parse-xml.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/core/parse-xml.c b/core/parse-xml.c index 22de449cc..61af0f617 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -1416,6 +1416,50 @@ static void try_to_fill_dive_site(struct parser_state *state, const char *name, nonmatch("divesite", name, buf); } +static void try_to_fill_filter(struct filter_preset *filter, const char *name, char *buf) +{ + start_match("filterpreset", name, buf); + + char *s = NULL; + if (MATCH("name", utf8_string, &s)) { + filter_preset_set_name(filter, s); + free(s); + return; + } + + nonmatch("filterpreset", name, buf); +} + +static void try_to_fill_fulltext(const char *name, char *buf, struct parser_state *state) +{ + start_match("fulltext", name, buf); + + if (MATCH("mode", utf8_string, &state->fulltext_string_mode)) + return; + if (MATCH("fulltext", utf8_string, &state->fulltext)) + return; + + nonmatch("fulltext", name, buf); +} + +static void try_to_fill_filter_constraint(const char *name, char *buf, struct parser_state *state) +{ + start_match("fulltext", name, buf); + + if (MATCH("type", utf8_string, &state->filter_constraint_type)) + return; + if (MATCH("string_mode", utf8_string, &state->filter_constraint_string_mode)) + return; + if (MATCH("range_mode", utf8_string, &state->filter_constraint_range_mode)) + return; + if (MATCH("negate", get_bool, &state->filter_constraint_negate)) + return; + if (MATCH("constraint", utf8_string, &state->filter_constraint)) + return; + + nonmatch("fulltext", name, buf); +} + static bool entry(const char *name, char *buf, struct parser_state *state) { if (!strncmp(name, "version.program", sizeof("version.program") - 1) || @@ -1435,6 +1479,18 @@ static bool entry(const char *name, char *buf, struct parser_state *state) try_to_fill_dive_site(state, name, buf); return true; } + if (state->in_filter_constraint) { + try_to_fill_filter_constraint(name, buf, state); + return true; + } + if (state->in_fulltext) { + try_to_fill_fulltext(name, buf, state); + return true; + } + if (state->cur_filter) { + try_to_fill_filter(state->cur_filter, name, buf); + return true; + } if (!state->cur_event.deleted) { try_to_fill_event(name, buf, state); return true; @@ -1567,6 +1623,9 @@ static struct nesting { { "divecomputerid", dc_settings_start, dc_settings_end }, { "settings", settings_start, settings_end }, { "site", dive_site_start, dive_site_end }, + { "filterpreset", filter_preset_start, filter_preset_end }, + { "fulltext", fulltext_start, fulltext_end }, + { "constraint", filter_constraint_start, filter_constraint_end }, { "dive", dive_start, dive_end }, { "Dive", dive_start, dive_end }, { "trip", trip_start, trip_end }, @@ -1662,7 +1721,7 @@ static const char *preprocess_divelog_de(const char *buffer) int parse_xml_buffer(const char *url, const char *buffer, int size, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites, - const char **params) + filter_preset_table_t *filter_presets, const char **params) { UNUSED(size); xmlDoc *doc; @@ -1674,6 +1733,7 @@ int parse_xml_buffer(const char *url, const char *buffer, int size, state.target_table = table; state.trips = trips; state.sites = sites; + state.filter_presets = filter_presets; doc = xmlReadMemory(res, strlen(res), url, NULL, 0); if (!doc) doc = xmlReadMemory(res, strlen(res), url, "latin1", 0); |