Example #1
0
static void
print_distance(const double distance, const int no_scale, const int with_tab, const int decis)
{
    double dist = distance;

    if (gtxt_flags.metric == 0) {
        dist = METERS_TO_FEET(dist);

        if ((dist < 5280) || no_scale)
            gbfprintf(fout, "%.*f ft", decis, dist);
        else {
            dist = METERS_TO_MILES(distance);
            if (dist < (double)100)
                gbfprintf(fout, "%.1f mi", dist);
            else
                gbfprintf(fout, "%d mi", si_round(dist));
        }
    }
    else
    {
        if ((dist < 1000) || no_scale)
            gbfprintf(fout, "%.*f m", decis, dist);
        else {
            dist = dist / (double)1000.0;
            if (dist < (double)100)
                gbfprintf(fout, "%.1f km", dist);
            else
                gbfprintf(fout, "%d km", si_round(dist));
        }
    }
    if (with_tab) gbfprintf(fout, "\t");
}
Example #2
0
static void
copilot_writewpt(const waypoint *wpt)
{
	struct record4 *rec;
	char *vdata;

	rec = xcalloc(sizeof(*rec)+1141,1);

	pdb_write_double(&rec->latitude, RAD(wpt->latitude));
	pdb_write_double(&rec->longitude, RAD(-wpt->longitude));
	pdb_write_float(&rec->magvar, 0);
	pdb_write_float(&rec->elevation,
		METERS_TO_FEET(wpt->altitude));

	vdata = (char *)rec + sizeof(*rec);
	if ( wpt->shortname ) {
			  strncpy( vdata, wpt->shortname, 10 );
			  vdata[9] = '\0';
	}
	else {
			  vdata[0] ='\0';
	}
    vdata += strlen( vdata ) + 1;
	if ( wpt->description ) {
			strncpy( vdata, wpt->description, 100 );
			vdata[99] = '\0';
	}
	else {
			vdata[0] ='\0';
	}
	vdata += strlen( vdata ) + 1;
	
	if ( wpt->notes ) {
			strncpy( vdata, wpt->notes, 1000 );
			vdata[999] = '\0';
	}
	else {
			vdata[0] ='\0';
	}
	vdata += strlen( vdata ) + 1;

	pdb_write_rec(file_out, 0, 2, ct++, rec, (char *)vdata - (char *)rec);	       

	xfree(rec);
}
Example #3
0
static void
text_disp(const waypoint *wpt)
{
	int latint, lonint;
	char tbuf[1024];
	time_t tm = wpt->creation_time;
	gbint32 utmz;
	double utme, utmn;
	char utmzc;
	char *tmpout1, *tmpout2;
	char *altout;
	fs_xml *fs_gpx;

	waypoint_count++;
	
	if (split_output) {
		char *thisfname;
		xasprintf(&thisfname, "%s%d", output_name, waypoint_count);
		file_out = gbfopen(thisfname, "w", MYNAME);
	}
	
	lonint = abs((int) wpt->longitude);
	latint = abs((int) wpt->latitude);

	GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude, 
		&utme, &utmn, &utmz, &utmzc);

	if (tm == 0) 
		tm = time(NULL);
	strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm));

	tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0);
	if (wpt->altitude != unknown_alt) {
		xasprintf(&altout, " alt:%d", (int) ( (altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude) );
	}
	else {
		altout = "";
	}
	xasprintf (&tmpout2, "%s (%d%c %6.0f %7.0f)%s", tmpout1, utmz, utmzc, utme, utmn, altout );
	gbfprintf(file_out, "%-16s  %59s\n",
		(global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname,
		tmpout2);
	xfree(tmpout2);
	xfree(tmpout1);	
	if (altout[0]) 
		xfree(altout);
	

	if (strcmp(wpt->description, wpt->shortname)) {
		gbfprintf(file_out, "%s", wpt->description);
		if (wpt->gc_data->placer) 
			gbfprintf(file_out, " by %s", wpt->gc_data->placer);
		}
		if (wpt->gc_data->terr) {
			gbfprintf(file_out, " - %s / %s - (%d%s / %d%s)\n", 
				gs_get_cachetype(wpt->gc_data->type), gs_get_container(wpt->gc_data->container), 
				(int)(wpt->gc_data->diff / 10), (wpt->gc_data->diff%10)?".5":"", 
				(int)(wpt->gc_data->terr / 10), (wpt->gc_data->terr%10)?".5":""  ); 
	        if (wpt->gc_data->desc_short.utfstring) {
	                char *stripped_html = strip_html(&wpt->gc_data->desc_short);
			gbfprintf (file_out, "\n%s\n", stripped_html);
                	xfree(stripped_html);
       		}
	        if (wpt->gc_data->desc_long.utfstring) {
	                char *stripped_html = strip_html(&wpt->gc_data->desc_long);
			gbfprintf (file_out, "\n%s\n", stripped_html);
                	xfree(stripped_html);
       		}
		if (wpt->gc_data->hint) {
			char *hint = NULL;
			if ( txt_encrypt ) 
				hint = rot13( wpt->gc_data->hint );
			else
				hint = xstrdup( wpt->gc_data->hint );
			gbfprintf (file_out, "\nHint: %s\n", hint);
			xfree( hint );
		}
	}
	else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) {
		gbfprintf (file_out, "\n%s\n", wpt->notes);
	}

	fs_gpx = NULL;
	if ( includelogs ) {
		fs_gpx = (fs_xml *)fs_chain_find( wpt->fs, FS_GPX);
	}
	
	if ( fs_gpx && fs_gpx->tag ) {
		xml_tag *root = fs_gpx->tag;
		xml_tag *curlog = NULL;
		xml_tag *logpart = NULL;
		curlog = xml_findfirst( root, "groundspeak:log" );
		while ( curlog ) {
			time_t logtime = 0;
			struct tm *logtm = NULL;
			gbfprintf( file_out, "\n" );
			
			logpart = xml_findfirst( curlog, "groundspeak:type" );
			if ( logpart ) {
				gbfprintf( file_out, "%s by ", logpart->cdata );
			}
			
			logpart = xml_findfirst( curlog, "groundspeak:finder" );
			if ( logpart ) {
				gbfprintf( file_out, "%s on ", logpart->cdata );
			}
			
			logpart = xml_findfirst( curlog, "groundspeak:date" );
			if ( logpart ) {
				logtime = xml_parse_time( logpart->cdata, NULL);
				logtm = localtime( &logtime );
				if ( logtm ) {
					gbfprintf( file_out, 
						"%4.4d-%2.2d-%2.2d\n",
						logtm->tm_year+1900,
						logtm->tm_mon+1,
						logtm->tm_mday );
				}
			}
			
			logpart = xml_findfirst( curlog, "groundspeak:log_wpt" );
			if ( logpart ) {
				char *coordstr = NULL;
				float lat = 0;
				float lon = 0;
				coordstr = xml_attribute( logpart, "lat" );
				if ( coordstr ) {
					lat = atof( coordstr );
				}
			        coordstr = xml_attribute( logpart, "lon" );
				if ( coordstr ) {
					lon = atof( coordstr );
				}
				coordstr = pretty_deg_format(lat, lon, degformat[2], " ", 0);
				gbfprintf( file_out, "%s\n", coordstr);
				xfree(coordstr);
			}
			
			logpart = xml_findfirst( curlog, "groundspeak:text" );
			if ( logpart ) {
				char *encstr = NULL;
				char *s = NULL;
				int encoded = 0;
				encstr = xml_attribute( logpart, "encoded" );
				encoded = (encstr[0] != 'F');
				
				if ( txt_encrypt && encoded ) {
					s = rot13( logpart->cdata );
				}
				else {
					s = xstrdup( logpart->cdata );
				}
					
				gbfprintf( file_out, "%s", s ); 
				xfree( s );
			}

			gbfprintf( file_out, "\n" );
			curlog = xml_findnext( root, curlog, "groundspeak:log" );
		}
	}
	if (! suppresssep) 
		gbfprintf(file_out, "\n-----------------------------------------------------------------------------\n");
	else
		gbfprintf(file_out, "\n");

	if (split_output) {
		gbfclose(file_out);
		file_out = NULL;
	}
}
Example #4
0
static void
lowranceusr_waypt_disp(const waypoint *wpt)
{
	int text_len, Lat, Lon, Time, SymbolId;
	short int WayptType;
	char *name;
	char *comment;
	int alt = METERS_TO_FEET(wpt->altitude);

	if (wpt->altitude == unknown_alt) {
		alt = UNKNOWN_USR_ALTITUDE;
	}

	Lat = lat_deg_to_mm(wpt->latitude);
	Lon = lon_deg_to_mm(wpt->longitude);
	gbfputint32(Lat, file_out);
	gbfputint32(Lon, file_out);
	gbfputint32(alt, file_out);

        if (writing_version >= 3) {
          float depth = WAYPT_HAS(wpt, depth) ?
              METERS_TO_FEET(wpt->depth) : -99999.0;
          gbfputflt(depth, file_out);
        }

	if (global_opts.debug_level >= 1) {
		/* print lat/lon/alt on one easily greppable line */
		printf(MYNAME " waypt_disp: Lat = %d   Lon = %d   Alt = %d\n",Lat, Lon, alt);
	}

	/* Try and make sure we have a name */
	if ((! wpt->shortname) || global_opts.synthesize_shortnames) {
		if (wpt->description && global_opts.synthesize_shortnames) {
			name = mkshort_from_wpt(mkshort_handle, wpt);
		} else if (wpt->shortname) {
			name = xstrdup(wpt->shortname);
		} else if (wpt->description) {
			name = xstrdup(wpt->description);
		} else {
			name = xstrdup("");
		}
	} else {
		name = xstrdup(wpt->shortname);
	}

	text_len = strlen(name);
	if (text_len > MAXUSRSTRINGSIZE) text_len = MAXUSRSTRINGSIZE;
	gbfputint32(text_len, file_out);
	gbfwrite(name, 1, text_len, file_out);

	if (global_opts.debug_level >= 1)
		printf(MYNAME " waypt_disp: Waypt name = %s\n",name);

	xfree(name);

	/**
	 * Comments are now used by the iFinder (Expedition C supports them)
	 */
	if (wpt->description && strcmp(wpt->description, wpt->shortname) != 0) {
		comment = xstrdup(wpt->description);
		text_len = strlen(comment);
		if (text_len > MAXUSRSTRINGSIZE) text_len = MAXUSRSTRINGSIZE;
		gbfputint32(text_len, file_out);
		gbfwrite(comment, 1, text_len, file_out);
		xfree(comment);
	} else {
		text_len = 0;
		gbfputint32(text_len, file_out);
	}

	if (wpt->creation_time > base_time_secs) {
		Time = wpt->creation_time - base_time_secs;
	} else {
		Time = 0;
	}

	if (global_opts.debug_level >= 2)
	{
		time_t wpt_time = Time;
		printf(MYNAME " waypt_disp: base_time : %d\n", (int)base_time_secs);
		printf(MYNAME " waypt_disp: creation time : %d\n", (int)wpt->creation_time);
		printf(MYNAME " waypt_disp: waypt time : %d\n", (int)wpt_time);
		printf(MYNAME " waypt_disp: waypt time (local): %s\n", ctime(&wpt_time));
	}

	gbfputint32(Time, file_out);

	if (get_cache_icon(wpt) && wpt->icon_descr && (strcmp(wpt->icon_descr, "Geocache Found") != 0)) {
		SymbolId = lowranceusr_find_icon_number_from_desc(get_cache_icon(wpt));
	} else {
		SymbolId = lowranceusr_find_icon_number_from_desc(wpt->icon_descr);
	}
	/* If the waypoint is archived or disabled, use a "disabled" icon instead. */
	if ( (wpt->gc_data->is_archived==status_true) || (wpt->gc_data->is_available==status_false) ) {
		SymbolId = lowranceusr_find_icon_number_from_desc("Disabled Cache");
	}

	gbfputint32(SymbolId, file_out);

	/* USER waypoint type */
	WayptType = 0;
	gbfputint16(WayptType, file_out);
}