void save_dives_buffer(struct membuffer *b, const bool select_only) { int i; struct dive *dive; dive_trip_t *trip; put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION); if (prefs.save_userid_local) put_format(b, " <userid>%30s</userid>\n", prefs.userid); /* save the dive computer nicknames, if any */ call_for_each_dc(b, save_one_device, select_only); if (autogroup) put_format(b, " <autogroup state='1' />\n"); put_format(b, "</settings>\n"); /* save the dive sites - to make the output consistent let's sort the table, first */ dive_site_table_sort(); put_format(b, "<divesites>\n"); for (i = 0; i < dive_site_table.nr; i++) { int j; struct dive *d; struct dive_site *ds = get_dive_site(i); if (dive_site_is_empty(ds)) { for_each_dive(j, d) { if (d->dive_site_uuid == ds->uuid) d->dive_site_uuid = 0; } delete_dive_site(get_dive_site(i)->uuid); i--; // since we just deleted that one continue; } if (select_only && !is_dive_site_used(ds->uuid, true)) continue; put_format(b, "<site uuid='%8x'", ds->uuid); show_utf8(b, ds->name, " name='", "'", 1); if (ds->latitude.udeg || ds->longitude.udeg) { put_degrees(b, ds->latitude, " gps='", " "); put_degrees(b, ds->longitude, "", "'"); } show_utf8(b, ds->description, " description='", "'", 1); show_utf8(b, ds->notes, " notes='", "'", 1); if (ds->taxonomy.nr) { put_format(b, ">\n"); for (int j = 0; j < ds->taxonomy.nr; j++) { struct taxonomy *t = &ds->taxonomy.category[j]; if (t->category != TC_NONE) { put_format(b, "<geo cat='%d'", t->category); put_format(b, " origin='%d'", t->origin); show_utf8(b, t->value, " value='", "'/>\n", 1); } } put_format(b, "</site>\n"); } else { put_format(b, "/>\n"); } } put_format(b, "</divesites>\n<dives>\n"); for (trip = dive_trip_list; trip != NULL; trip = trip->next) trip->index = 0; /* save the dives */ for_each_dive(i, dive) { if (select_only) { if (!dive->selected) continue; save_one_dive_to_mb(b, dive); } else { trip = dive->divetrip; /* Bare dive without a trip? */ if (!trip) { save_one_dive_to_mb(b, dive); continue; } /* Have we already seen this trip (and thus saved this dive?) */ if (trip->index) continue; /* We haven't seen this trip before - save it and all dives */ trip->index = 1; save_trip(b, trip); } } put_format(b, "</dives>\n</divelog>\n"); }
void save_dives_buffer(struct membuffer *b, const bool select_only) { int i; struct dive *dive; dive_trip_t *trip; put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION); if (prefs.save_userid_local) put_format(b, " <userid>%30s</userid>\n", prefs.userid); /* save the dive computer nicknames, if any */ call_for_each_dc(b, save_one_device, select_only); if (autogroup) put_format(b, " <autogroup state='1' />\n"); put_format(b, "</settings>\n"); /* save the dive sites - to make the output consistent let's sort the table, first */ dive_site_table_sort(); put_format(b, "<divesites>\n"); for (i = 0; i < dive_site_table.nr; i++) { int j; struct dive *d; struct dive_site *ds = get_dive_site(i); if (dive_site_is_empty(ds)) { for_each_dive(j, d) { if (d->dive_site_uuid == ds->uuid) d->dive_site_uuid = 0; } delete_dive_site(ds->uuid); i--; // since we just deleted that one continue; } else if (ds->name && (strncmp(ds->name, "Auto-created dive", 17) == 0 || strncmp(ds->name, "New Dive", 8) == 0)) { // these are the two default names for sites from // the web service; if the site isn't used in any // dive (really? you didn't rename it?), delete it if (!is_dive_site_used(ds->uuid, false)) { if (verbose) fprintf(stderr, "Deleted unused auto-created dive site %s\n", ds->name); delete_dive_site(ds->uuid); i--; // since we just deleted that one continue; } } if (select_only && !is_dive_site_used(ds->uuid, true)) continue; put_format(b, "<site uuid='%8x'", ds->uuid); show_utf8(b, ds->name, " name='", "'", 1); if (ds->latitude.udeg || ds->longitude.udeg) { put_degrees(b, ds->latitude, " gps='", " "); put_degrees(b, ds->longitude, "", "'"); } show_utf8(b, ds->description, " description='", "'", 1); put_format(b, ">\n"); show_utf8(b, ds->notes, " <notes>", " </notes>\n", 0); if (ds->taxonomy.nr) { for (int j = 0; j < ds->taxonomy.nr; j++) { struct taxonomy *t = &ds->taxonomy.category[j]; if (t->category != TC_NONE && t->value) { put_format(b, " <geo cat='%d'", t->category); put_format(b, " origin='%d'", t->origin); show_utf8(b, t->value, " value='", "'/>\n", 1); } } } put_format(b, "</site>\n"); }