Example #1
0
static void
unicsv_print_str(const char *str)
{
	if (str && *str) {
		char *cout, *cx;

		cout = strenquote(str, UNICSV_QUOT_CHAR);

		while ((cx = strstr(cout, "\r\n"))) {
			memmove(cx, cx + 1, strlen(cx));
			*cx++ = ',';
			lrtrim(cx);
		}
		while ((cx = strchr(cout, '\r'))) {
			*cx++ = ',';
			lrtrim(cx);
		}
		while ((cx = strchr(cout, '\n'))) {
			*cx++ = ',';
			lrtrim(cx);
		}

		gbfprintf(fout, "%s%s", unicsv_fieldsep, cout);
		xfree(cout);
	}
	else gbfputs(unicsv_fieldsep, fout);
}
Example #2
0
/*
 * Write an optional tag with a value that may need to be entity escaped.
 * Never changes indention leve, but does honour it.
 */
static void
kml_write_xmle(const char *tag, const char *v)
{
	int i;
	if (v && *v) {
		char *tmp_ent = xml_entitize(v);
		for (i = 0; i < indent_level; i++) {
			gbfputs("  ", ofd);
		}
		gbfprintf(ofd, "<%s>%s</%s>\n",tag, tmp_ent, tag);
		xfree(tmp_ent);
	}
}
Example #3
0
/*
 *  Indent is a direction to change indention level.
 * If positive, increase one level after printing this line.
 * If zero, just print this line at the current indent leve.
 * If negative, descrease the indent level.
 */
static void
kml_write_xml(int indent, const char *fmt, ...)
{
	va_list args;
	int i;
	va_start(args, fmt);

	if (indent < 0) indent_level--;

	if (fmt[1] != '!' && do_indentation) {
		for (i = 0; i < indent_level; i++) {
			gbfputs("  ", ofd);
		}
	}

	gbvfprintf(ofd, fmt, args);

	if (indent > 0) indent_level++;

	va_end(args);
}
Example #4
0
static void
unicsv_waypt_disp_cb(const waypoint *wpt)
{
	double lat, lon, alt;
	char *cout = NULL;
	const char *shortname;
	garmin_fs_t *gmsd;
#ifdef UNICSV_GC_READY
	const geocache_data *gc_data = NULL;
#endif
	unicsv_waypt_ct++;

	shortname = (wpt->shortname) ? wpt->shortname : "";
	gmsd = GMSD_FIND(wpt);

	if (unicsv_datum_idx == DATUM_WGS84) {
		lat = wpt->latitude;
		lon = wpt->longitude;
		alt = wpt->altitude;
	}
	else {
		GPS_Math_WGS84_To_Known_Datum_M(wpt->latitude, wpt->longitude, 0.0,
			&lat, &lon, &alt, unicsv_datum_idx);
	}

	gbfprintf(fout, "%d%s", unicsv_waypt_ct, unicsv_fieldsep);

	switch(unicsv_grid_idx) {

	case grid_lat_lon_ddd:
		cout = pretty_deg_format(lat, lon, 'd', unicsv_fieldsep, 0);
		gbfputs(cout, fout);
		break;

	case grid_lat_lon_dmm:
		cout = pretty_deg_format(lat, lon, 'm', unicsv_fieldsep, 0);
		gbfputs(cout, fout);
		break;

	case grid_lat_lon_dms: {
		char *sep, *tmp;
		cout = pretty_deg_format(lat, lon, 's', unicsv_fieldsep, 0);
		sep = strchr(cout, ',');
		*sep = '\0';
		tmp = strenquote(cout, UNICSV_QUOT_CHAR);
		gbfprintf(fout, "%s%s", tmp, unicsv_fieldsep);
		xfree(tmp);
		tmp = strenquote(sep+1, UNICSV_QUOT_CHAR);
		gbfputs(tmp, fout);
		xfree(tmp);
		}
		break;

	case grid_bng: {
		char map[3];
		double north, east;

		if (! GPS_Math_WGS84_To_UKOSMap_M(wpt->latitude, wpt->longitude, &east, &north, map))
			unicsv_fatal_outside(wpt);
		gbfprintf(fout, "%s%s%5.0f%s%5.0f",
			map, unicsv_fieldsep,
			east, unicsv_fieldsep,
			north);
		break;
	}
	case grid_utm: {
		int zone;
		char zonec;
		double north, east;

		if (! GPS_Math_Known_Datum_To_UTM_EN(lat, lon,
			&east, &north, &zone, &zonec, unicsv_datum_idx))
			unicsv_fatal_outside(wpt);
		gbfprintf(fout, "%02d%s%c%s%.0f%s%.0f",
			zone, unicsv_fieldsep,
			zonec, unicsv_fieldsep,
			east, unicsv_fieldsep,
			north);
		break;
	}
	case grid_swiss: {
		double north, east;

		if (! GPS_Math_WGS84_To_Swiss_EN(wpt->latitude, wpt->longitude, &east, &north))
			unicsv_fatal_outside(wpt);
		gbfprintf(fout, "%.f%s%.f",
			east, unicsv_fieldsep, north);
		break;

	}
	default:
		gbfprintf(fout, "%.*f%s%.*f", llprec, lat, unicsv_fieldsep, llprec, lon);
		break;
	}

	if (cout) xfree(cout);

	if FIELD_USED(fld_shortname) unicsv_print_str(shortname);
	if FIELD_USED(fld_altitude) {
		if (wpt->altitude != unknown_alt)
			gbfprintf(fout, "%s%.1f", unicsv_fieldsep, wpt->altitude);
		else
			gbfputs(unicsv_fieldsep, fout);
	}
	if FIELD_USED(fld_description) unicsv_print_str(wpt->description);
	if FIELD_USED(fld_notes) unicsv_print_str(wpt->notes);
	if FIELD_USED(fld_symbol)
		unicsv_print_str((wpt->icon_descr != NULL) ? wpt->icon_descr : "Waypoint");
	if FIELD_USED(fld_depth) {
		if WAYPT_HAS(wpt, depth)
			gbfprintf(fout, "%s%.3f", unicsv_fieldsep, wpt->depth);
		else
			gbfputs(unicsv_fieldsep, fout);
	}