- gchar *unbuffer_loc = g_find_program_in_path("unbuffer");
- cmd = g_strdup_printf ( "%s%s%s %s -i gpx %s %s",
- unbuffer_loc ? unbuffer_loc : "",
- unbuffer_loc ? " " : "",
- gpsbabel_loc,
- babelargs,
- name_src,
- to);
-
- if ( unbuffer_loc )
- g_free ( unbuffer_loc );
-#ifdef DBG
- fprintf(stderr, "cmd=%s\n", cmd);
-#endif /* DBG */
- args = g_strsplit(cmd, " ", 0);
- ret = babel_general_convert_to ( vt, cb, args, name_src, user_data );
- g_strfreev(args);
- g_free ( cmd );
- }
+ gchar **sub_args = g_strsplit(babelargs, " ", 0);
+
+ i = 0;
+ if (unbuffer_loc)
+ args[i++] = unbuffer_loc;
+ args[i++] = gpsbabel_loc;
+ args[i++] = "-i";
+ args[i++] = "gpx";
+ for (j = 0; sub_args[j]; j++)
+ /* some version of gpsbabel can not take extra blank arg */
+ if (sub_args[j][0] != '\0')
+ args[i++] = sub_args[j];
+ args[i++] = "-f";
+ args[i++] = name_src;
+ args[i++] = "-F";
+ args[i++] = (char *)to;
+ args[i] = NULL;
+
+ ret = babel_general_convert_to ( vt, track, cb, args, name_src, user_data );
+
+ g_strfreev(sub_args);
+ } else
+ g_critical("gpsbabel not found in PATH");
+ g_remove(name_src);
+ g_free(name_src);
+ }
+
+ return ret;
+}
+
+static void set_mode(BabelMode *mode, gchar *smode)
+{
+ mode->waypointsRead = smode[0] == 'r';
+ mode->waypointsWrite = smode[1] == 'w';
+ mode->tracksRead = smode[2] == 'r';
+ mode->tracksWrite = smode[3] == 'w';
+ mode->routesRead = smode[4] == 'r';
+ mode->routesWrite = smode[5] == 'w';
+}
+
+/**
+ * load_feature_parse_line:
+ *
+ * Load a single feature stored in the given line.
+ */
+static void load_feature_parse_line (gchar *line)
+{
+ gchar **tokens = g_strsplit ( line, "\t", 0 );
+ if ( tokens != NULL
+ && tokens[0] != NULL ) {
+ if ( strcmp("serial", tokens[0]) == 0 ) {
+ if ( tokens[1] != NULL
+ && tokens[2] != NULL
+ && tokens[3] != NULL
+ && tokens[4] != NULL ) {
+ BabelDevice *device = g_malloc ( sizeof (BabelDevice) );
+ set_mode (&(device->mode), tokens[1]);
+ device->name = g_strdup (tokens[2]);
+ device->label = g_strndup (tokens[4], 50); // Limit really long label text
+ a_babel_device_list = g_list_append (a_babel_device_list, device);
+ g_debug ("New gpsbabel device: %s, %d%d%d%d%d%d(%s)",
+ device->name,
+ device->mode.waypointsRead, device->mode.waypointsWrite,
+ device->mode.tracksRead, device->mode.tracksWrite,
+ device->mode.routesRead, device->mode.routesWrite,
+ tokens[1]);
+ } else {
+ g_warning ( "Unexpected gpsbabel format string: %s", line);
+ }
+ } else if ( strcmp("file", tokens[0]) == 0 ) {
+ if ( tokens[1] != NULL
+ && tokens[2] != NULL
+ && tokens[3] != NULL
+ && tokens[4] != NULL ) {
+ BabelFile *file = g_malloc ( sizeof (BabelFile) );
+ set_mode (&(file->mode), tokens[1]);
+ file->name = g_strdup (tokens[2]);
+ file->ext = g_strdup (tokens[3]);
+ file->label = g_strdup (tokens[4]);
+ a_babel_file_list = g_list_append (a_babel_file_list, file);
+ g_debug ("New gpsbabel file: %s, %d%d%d%d%d%d(%s)",
+ file->name,
+ file->mode.waypointsRead, file->mode.waypointsWrite,
+ file->mode.tracksRead, file->mode.tracksWrite,
+ file->mode.routesRead, file->mode.routesWrite,
+ tokens[1]);
+ } else {
+ g_warning ( "Unexpected gpsbabel format string: %s", line);
+ }
+ } /* else: ignore */
+ } else {
+ g_warning ( "Unexpected gpsbabel format string: %s", line);