Thursday, December 20, 2007

Writing extra geocache information into tomtom description field with gpsbabel

I wrote a patch for gpsbabel 1.3.3 to make the tomtom descriptions of caches more useful. Invoke it like:

gpsbabel -i gpx -f 1483978.gpx -o tomtom,cache=1 -F Geocaching.ov2


I have sent the patch to the authors of tomtom.c so we will see what happens.


--- tomtom.c 2007-12-22 23:41:56.000000000 -0500
+++ /home/gpsbabel-1.3.3/tomtom.c 2006-07-17 14:38:56.000000000 -0400
@@ -44,12 +44,9 @@

static FILE *file_in;
static FILE *file_out;
-static char *opt_geocache = NULL;

static
arglist_t tomtom_args[] = {
- { "cache", &opt_geocache, "Cram geocaching info into description field",
- NULL, ARGTYPE_BOOL, ARG_NOMINMAX },
ARG_TERMINATOR
};

@@ -216,20 +213,6 @@
struct blockheader *ch2;
};

-static int get_desc(char *desc_field, waypoint *wpt) {
- if (opt_geocache) {
- snprintf(desc_field,256,"%s(t%ud%u)%s(type%dcont%d)",wpt->description,
- wpt->gc_data.terr/10,
- wpt->gc_data.diff/10,
- wpt->shortname,
- (int) wpt->gc_data.type,
- (int) wpt->gc_data.container);
- } else {
- strcpy(desc_field,wpt->description);
- }
- return strlen(desc_field);
-}
-
static void
write_blocks( FILE *f, struct blockheader *blocks ) {
int i;
@@ -248,13 +231,10 @@
if ( !blocks->ch1 && !blocks->ch2 ) {
for ( i = 0; i < blocks->count; i++ ) {
write_char( f, 2 );
- char desc_field [256];
- get_desc(desc_field,blocks->start[i].wpt);
- //Unfortunately enums mean we get numbers for cache type and container.
- write_long( f, strlen( desc_field ) + 14 );
+ write_long( f, strlen( blocks->start[i].wpt->description ) + 14 );
write_float_as_long( f, blocks->start[i].wpt->longitude*100000);
write_float_as_long( f, blocks->start[i].wpt->latitude*100000);
- write_string( f, desc_field);
+ write_string( f, blocks->start[i].wpt->description);
}
}
}
@@ -280,8 +260,7 @@
newblock->size += 4 * 3 + 1;
/* wpt const part 3 longs, 1 char */
wpt = start[i].wpt;
- char tempstr [256];
- newblock->size += get_desc(tempstr,wpt) + 1;
+ newblock->size += strlen( wpt->description ) + 1;
}
}
else {

No comments: