From 6e81677d89591099266c1d94e06afbf54dbb6358 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Wed, 1 Jul 2015 12:29:32 -0700 Subject: [PATCH] Geo taxonomy: save and load the geo taxonomy data with git This also supports the cloud storage, of course. Signed-off-by: Dirk Hohndel --- load-git.c | 18 +++++++++++++++++- save-git.c | 8 ++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/load-git.c b/load-git.c index 0610cd0d8..7cfad325f 100644 --- a/load-git.c +++ b/load-git.c @@ -300,6 +300,22 @@ static void parse_site_gps(char *line, struct membuffer *str, void *_ds) ds->longitude = parse_degrees(line, &line); } +static void parse_site_geo(char *line, struct membuffer *str, void *_ds) +{ + fprintf(stderr, "line |%s| str |%s|\n", line, mb_cstring(str)); + struct dive_site *ds = _ds; + if (ds->taxonomy.category == NULL) + ds->taxonomy.category = alloc_taxonomy(); + int nr = ds->taxonomy.nr; + if (nr < NR_CATEGORIES) { + struct taxonomy *t = &ds->taxonomy.category[nr]; + t->value = strdup(mb_cstring(str)); + sscanf(line, "cat %d origin %d \"", &t->category, &t->origin); + fprintf(stderr, "found category %d origin %d value |%s|\n", t->category, t->origin, t->value); + ds->taxonomy.nr++; + } +} + /* Parse key=val parts of samples and cylinders etc */ static char *parse_keyvalue_entry(void (*fn)(void *, const char *, const char *), void *fndata, char *line) { @@ -906,7 +922,7 @@ static void dive_parser(char *line, struct membuffer *str, void *_dive) struct keyword_action site_action[] = { #undef D #define D(x) { #x, parse_site_ ## x } - D(description), D(gps), D(name), D(notes) + D(description), D(geo), D(gps), D(name), D(notes) }; static void site_parser(char *line, struct membuffer *str, void *_ds) diff --git a/save-git.c b/save-git.c index a18ef8f84..ff82ca841 100644 --- a/save-git.c +++ b/save-git.c @@ -897,6 +897,14 @@ static void save_divesites(git_repository *repo, struct dir *tree) show_utf8(&b, "description ", ds->description, "\n"); show_utf8(&b, "notes ", ds->notes, "\n"); show_gps(&b, ds->latitude, ds->longitude); + if (prefs.geocoding.enable_geocoding) + for (int j = 0; j < ds->taxonomy.nr; j++) { + struct taxonomy *t = &ds->taxonomy.category[j]; + if (t->category != NONE) { + put_format(&b, "geo cat %d origin %d ", t->category, t->origin); + show_utf8(&b, "", t->value, "\n" ); + } + } blob_insert(repo, subdir, &b, mb_cstring(&site_file_name)); } }