示例#1
0
void save_dives(const char *filename)
{
	int i;
	GList *trip = NULL;

	FILE *f = fopen(filename, "w");

	if (!f)
		return;

	/* Flush any edits of current dives back to the dives! */
	update_dive(current_dive);

	fprintf(f, "<dives>\n<program name='subsurface' version='%d'></program>\n", VERSION);

	/* save the trips */
	while ((trip = NEXT_TRIP(trip)) != NULL)
		save_trip(f, trip->data);

	/* save the dives */
	for (i = 0; i < dive_table.nr; i++)
		save_dive(f, get_dive(i));
	fprintf(f, "</dives>\n");
	fclose(f);
}
示例#2
0
void save_dives(const char *filename)
{
	int i;
	struct dive *dive;
	dive_trip_t *trip = NULL;

	FILE *f = g_fopen(filename, "w");

	if (!f)
		return;

	/* Flush any edits of current dives back to the dives! */
	update_dive(current_dive);

	fprintf(f, "<dives>\n<program name='subsurface' version='%d'></program>\n", VERSION);

	/* save the dives */
	for_each_dive(i, dive) {
		dive_trip_t *thistrip = dive->divetrip;
		if (trip != thistrip) {
			/* Close the old trip? */
			if (trip)
				fprintf(f, "</trip>\n");
			/* Open the new one */
			if (thistrip)
				save_trip(f, thistrip);
			trip = thistrip;
		}
		save_dive(f, get_dive(i));
	}
示例#3
0
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>%s</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<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(b, dive);

		} else {
			trip = dive->divetrip;

			/* Bare dive without a trip? */
			if (!trip) {
				save_one_dive(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");
}
示例#4
0
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");
}
示例#5
0
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");
}