- 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 );
- g_debug ( "%s: %s", __FUNCTION__, cmd );
- if ( g_shell_parse_argv(cmd, &nb_args, &args, NULL) ) {
- ret = babel_general_convert_to ( vt, cb, args, name_src, user_data );
- g_strfreev(args);
+ 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, 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:
+ *
+ * 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", device->name);
+ } else {
+ g_warning ( "Unexpected gpsbabel format string: %s", line);