static void save_one_device(void *_f, const char *model, uint32_t deviceid, const char *nickname, const char *serial_nr, const char *firmware) { struct membuffer *b = _f; /* Nicknames that are empty or the same as the device model are not interesting */ if (nickname) { if (!*nickname || !strcmp(model, nickname)) nickname = NULL; } /* Serial numbers that are empty are not interesting */ if (serial_nr && !*serial_nr) serial_nr = NULL; /* Firmware strings that are empty are not interesting */ if (firmware && !*firmware) firmware = NULL; /* Do we have anything interesting about this dive computer to save? */ if (!serial_nr && !nickname && !firmware) return; put_format(b, "<divecomputerid"); show_utf8(b, model, " model='", "'", 1); put_format(b, " deviceid='%08x'", deviceid); show_utf8(b, serial_nr, " serial='", "'", 1); show_utf8(b, firmware, " firmware='", "'", 1); show_utf8(b, nickname, " nickname='", "'", 1); put_format(b, "/>\n"); }
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc) { put_format(b, " <divecomputer"); show_utf8(b, dc->model, " model='", "'", 1); if (dc->deviceid) put_format(b, " deviceid='%08x'", dc->deviceid); if (dc->diveid) put_format(b, " diveid='%08x'", dc->diveid); if (dc->when && dc->when != dive->when) show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, " duration='", " min'"); if (dc->divemode != OC) { for (enum dive_comp_type i = 0; i < NUM_DC_TYPE; i++) if (dc->divemode == i) show_utf8(b, divemode_text[i], " dctype='", "'", 1); if (dc->no_o2sensors) put_format(b," no_o2sensors='%d'", dc->no_o2sensors); } put_format(b, ">\n"); save_depths(b, dc); save_temperatures(b, dc); save_airpressure(b, dc); save_salinity(b, dc); put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n"); save_extra_data(b, dc->extra_data); save_events(b, dc->events); save_samples(b, dc->samples, dc->sample); put_format(b, " </divecomputer>\n"); }
static void save_overview(struct membuffer *b, struct dive *dive) { show_utf8(b, dive->divemaster, " <divemaster>", "</divemaster>\n", 0); show_utf8(b, dive->buddy, " <buddy>", "</buddy>\n", 0); show_utf8(b, dive->notes, " <notes>", "</notes>\n", 0); show_utf8(b, dive->suit, " <suit>", "</suit>\n", 0); }
static void save_overview(struct membuffer *b, struct dive *dive) { show_gps(b, dive->latitude, dive->longitude); show_utf8(b, "location ", dive->location, "\n"); show_utf8(b, "divemaster ", dive->divemaster, "\n"); show_utf8(b, "buddy ", dive->buddy, "\n"); show_utf8(b, "suit ", dive->suit, "\n"); show_utf8(b, "notes ", dive->notes, "\n"); }
static void save_overview(FILE *f, struct dive *dive) { save_depths(f, dive); save_temperatures(f, dive); show_duration(f, dive->surfacetime, " <surfacetime>", "</surfacetime>\n"); show_location(f, dive); show_utf8(f, dive->divemaster, " <divemaster>","</divemaster>\n"); show_utf8(f, dive->buddy, " <buddy>","</buddy>\n"); show_utf8(f, dive->notes, " <notes>","</notes>\n"); }
static void save_extra_data(struct membuffer *b, struct extra_data *ed) { while (ed) { if (ed->key && ed->value) { put_string(b, " <extradata"); show_utf8(b, ed->key, " key='", "'", 1); show_utf8(b, ed->value, " value='", "'", 1); put_string(b, " />\n"); } ed = ed->next; } }
static void save_overview(FILE *f, struct dive *dive) { show_depth(f, dive->maxdepth, " <maxdepth>", "</maxdepth>\n"); show_depth(f, dive->meandepth, " <meandepth>", "</meandepth>\n"); show_temperature(f, dive->airtemp, " <airtemp>", "</airtemp>\n"); show_temperature(f, dive->watertemp, " <watertemp>", "</watertemp>\n"); show_duration(f, dive->duration, " <duration>", "</duration>\n"); show_duration(f, dive->surfacetime, " <surfacetime>", "</surfacetime>\n"); show_pressure(f, dive->beginning_pressure, " <cylinderstartpressure>", "</cylinderstartpressure>\n"); show_pressure(f, dive->end_pressure, " <cylinderendpressure>", "</cylinderendpressure>\n"); show_utf8(f, dive->location, " <location>","</location>\n"); show_utf8(f, dive->notes, " <notes>","</notes>\n"); }
static void save_cylinder_info(struct membuffer *b, struct dive *dive) { int i, nr; nr = nr_cylinders(dive); for (i = 0; i < nr; i++) { cylinder_t *cylinder = dive->cylinder + i; int volume = cylinder->type.size.mliter; const char *description = cylinder->type.description; int o2 = cylinder->gasmix.o2.permille; int he = cylinder->gasmix.he.permille; put_string(b, "cylinder"); if (volume) put_milli(b, " vol=", volume, "l"); put_pressure(b, cylinder->type.workingpressure, " workpressure=", "bar"); show_utf8(b, " description=", description, ""); strip_mb(b); if (o2) { put_format(b, " o2=%u.%u%%", FRACTION(o2, 10)); if (he) put_format(b, " he=%u.%u%%", FRACTION(he, 10)); } put_pressure(b, cylinder->start, " start=", "bar"); put_pressure(b, cylinder->end, " end=", "bar"); put_string(b, "\n"); } }
static void show_location(struct membuffer *b, struct dive *dive) { degrees_t latitude = dive->latitude; degrees_t longitude = dive->longitude; /* Should we write a location tag at all? */ if (!(latitude.udeg || longitude.udeg) && !dive->location) return; put_string(b, " <location"); /* * Ok, theoretically I guess you could dive at * exactly 0,0. But we don't support that. So * if you do, just fudge it a bit, and say that * you dove a few meters away. */ if (latitude.udeg || longitude.udeg) { put_degrees(b, latitude, " gps='", " "); put_degrees(b, longitude, "", "'"); } /* Do we have a location name or should we write a empty tag? */ if (dive->location && dive->location[0] != '\0') show_utf8(b, dive->location, ">", "</location>\n", 0); else put_string(b, "/>\n"); }
static void show_location(FILE *f, struct dive *dive) { char buffer[80]; const char *prefix = " <location>"; double latitude = dive->latitude; double longitude = dive->longitude; /* * Ok, theoretically I guess you could dive at * exactly 0,0. But we don't support that. So * if you do, just fudge it a bit, and say that * you dove a few meters away. */ if (latitude || longitude) { int len = snprintf(buffer, sizeof(buffer)-4, " <location gps='%.12g %.12g'>", latitude, longitude); if (!dive->location) { memcpy(&buffer[len-1], "/>\n", 4); fputs(buffer, f); return; } prefix = buffer; } show_utf8(f, dive->location, prefix,"</location>\n"); }
static void save_trip(FILE *f, dive_trip_t *trip) { struct tm tm; utc_mkdate(trip->when, &tm); fprintf(f, "<trip"); fprintf(f, " date='%04u-%02u-%02u'", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday); fprintf(f, " time='%02u:%02u:%02u'", tm.tm_hour, tm.tm_min, tm.tm_sec); if (trip->location) show_utf8(f, trip->location, " location=\'","\'", 1); fprintf(f, ">\n"); if (trip->notes) show_utf8(f, trip->notes, "<notes>","</notes>\n", 0); }
static void save_one_event(struct membuffer *b, struct event *ev) { put_format(b, " <event time='%d:%02d min'", FRACTION(ev->time.seconds, 60)); show_index(b, ev->type, "type='", "'"); show_index(b, ev->flags, "flags='", "'"); show_index(b, ev->value, "value='", "'"); show_utf8(b, ev->name, " name='", "'", 1); put_format(b, " />\n"); }
static void save_one_event(FILE *f, struct event *ev) { fprintf(f, " <event time='%d:%02d min'", FRACTION(ev->time.seconds,60)); show_index(f, ev->type, "type='", "'"); show_index(f, ev->flags, "flags='", "'"); show_index(f, ev->value, "value='", "'"); show_utf8(f, ev->name, " name='", "'"); fprintf(f, " />\n"); }
static void save_one_event(struct membuffer *b, struct event *ev) { put_format(b, "event %d:%02d", FRACTION(ev->time.seconds, 60)); show_index(b, ev->type, "type=", ""); show_index(b, ev->flags, "flags=", ""); show_index(b, ev->value, "value=", ""); show_utf8(b, " name=", ev->name, ""); put_string(b, "\n"); }
static void save_trip(FILE *f, struct dive *trip) { struct tm *tm = gmtime(&trip->when); fprintf(f, "<trip"); fprintf(f, " date='%04u-%02u-%02u'", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday); fprintf(f, " time='%02u:%02u:%02u'", tm->tm_hour, tm->tm_min, tm->tm_sec); if (trip->location) show_utf8(f, trip->location, " location=\'","\'", 1); fprintf(f, " />\n"); }
static void save_cylinder_info(struct membuffer *b, struct dive *dive) { int i, nr; nr = nr_cylinders(dive); for (i = 0; i < nr; i++) { cylinder_t *cylinder = dive->cylinder + i; int volume = cylinder->type.size.mliter; const char *description = cylinder->type.description; put_format(b, " <cylinder"); if (volume) put_milli(b, " size='", volume, " l'"); put_pressure(b, cylinder->type.workingpressure, " workpressure='", " bar'"); show_utf8(b, description, " description='", "'", 1); put_gasmix(b, &cylinder->gasmix); put_pressure(b, cylinder->start, " start='", " bar'"); put_pressure(b, cylinder->end, " end='", " bar'"); if (cylinder->cylinder_use != OC_GAS) show_utf8(b, cylinderuse_text[cylinder->cylinder_use], " use='", "'", 1); put_format(b, " />\n"); } }
static void save_trip(struct membuffer *b, dive_trip_t *trip) { int i; struct dive *dive; put_format(b, "<trip"); show_date(b, trip->when); show_utf8(b, trip->location, " location=\'", "\'", 1); put_format(b, ">\n"); show_utf8(b, trip->notes, "<notes>", "</notes>\n", 0); /* * Incredibly cheesy: we want to save the dives sorted, and they * are sorted in the dive array.. So instead of using the dive * list in the trip, we just traverse the global dive array and * check the divetrip pointer.. */ for_each_dive(i, dive) { if (dive->divetrip == trip) save_one_dive_to_mb(b, dive); } put_format(b, "</trip>\n"); }
static void save_weightsystem_info(struct membuffer *b, struct dive *dive) { int i, nr; nr = nr_weightsystems(dive); for (i = 0; i < nr; i++) { weightsystem_t *ws = dive->weightsystem + i; int grams = ws->weight.grams; const char *description = ws->description; put_string(b, "weightsystem"); put_milli(b, " weight=", grams, "kg"); show_utf8(b, " description=", description, ""); put_string(b, "\n"); } }
static void save_one_event(struct membuffer *b, struct event *ev) { put_format(b, " <event time='%d:%02d min'", FRACTION(ev->time.seconds, 60)); show_index(b, ev->type, "type='", "'"); show_index(b, ev->flags, "flags='", "'"); show_index(b, ev->value, "value='", "'"); show_utf8(b, ev->name, " name='", "'", 1); if (event_is_gaschange(ev)) { if (ev->gas.index >= 0) { show_index(b, ev->gas.index, "cylinder='", "'"); put_gasmix(b, &ev->gas.mix); } else if (!event_gasmix_redundant(ev)) put_gasmix(b, &ev->gas.mix); } put_format(b, " />\n"); }
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc) { show_utf8(b, "model ", dc->model, "\n"); if (dc->deviceid) put_format(b, "deviceid %08x\n", dc->deviceid); if (dc->diveid) put_format(b, "diveid %08x\n", dc->diveid); if (dc->when && dc->when != dive->when) show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, "duration ", "min\n"); save_depths(b, dc); save_temperatures(b, dc); save_airpressure(b, dc); save_salinity(b, dc); put_duration(b, dc->surfacetime, "surfacetime ", "min\n"); save_events(b, dc->events); save_samples(b, dc->samples, dc->sample); }
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc) { put_format(b, " <divecomputer"); show_utf8(b, dc->model, " model='", "'", 1); if (dc->deviceid) put_format(b, " deviceid='%08x'", dc->deviceid); if (dc->diveid) put_format(b, " diveid='%08x'", dc->diveid); if (dc->when && dc->when != dive->when) show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, " duration='", " min'"); put_format(b, ">\n"); save_depths(b, dc); save_temperatures(b, dc); save_airpressure(b, dc); save_salinity(b, dc); put_duration(b, dc->surfacetime, " <surfacetime>", " min</surfacetime>\n"); save_events(b, dc->events); save_samples(b, dc->samples, dc->sample); put_format(b, " </divecomputer>\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(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", 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); if (autogroup) put_format(b, " <autogroup state='1' />\n"); put_format(b, "</settings>\n"); /* save the dive sites */ put_format(b, "<divesites>\n"); for (i = 0; i < dive_site_table.nr; i++) { struct dive_site *ds = get_dive_site(i); if (dive_site_is_empty(ds)) { int j; struct dive *d; 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; } 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); 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"); }