diff --git a/gst/gstparse.c b/gst/gstparse.c index 16091dc399..03e8bf9a43 100644 --- a/gst/gstparse.c +++ b/gst/gstparse.c @@ -323,8 +323,9 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent) gst_parse_priv priv; gchar **argvn; gint newargc; - gint len; - int i,j,k; + gint i; + const gchar *cp, *start, *end; + GSList *string_list = NULL, *slist; priv.bincount = 0; priv.threadcount = 0; @@ -333,46 +334,64 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent) priv.verbose = FALSE; priv.debug = FALSE; - // first walk through quickly and see how many more slots we need - len = strlen(cmdline); - newargc = 1; - for (i=0;i 0) { + // normal argument - copy and add to the list + string_list = g_slist_prepend(string_list, g_strndup(cp, i)); + newargc++; + cp += i; + } + + // skip spaces + while (cp < end && *cp == ' ') + cp++; + + // handle quoted arguments + if (*cp == '"') { + start = ++cp; + + // find matching quote + while (cp < end && *cp != '"') + cp++; + + // make sure we got it + if (cp == end) { + g_warning("gst_parse_launch: Unbalanced quote in command line"); + // FIXME: The list leaks here + return 0; + } + + // copy the string sans quotes + string_list = g_slist_prepend(string_list, g_strndup(start, cp - start)); + newargc++; + cp += 2; // skip the quote aswell + } + + // brackets exist in a separate argument slot + if (*cp && strchr("([{}])", *cp)) { + string_list = g_slist_prepend(string_list, g_strndup(cp, 1)); + newargc++; + cp++; } } // now allocate the new argv array - argvn = g_new0(char *,newargc+1); - GST_DEBUG(0,"supposed to have %d args\n",newargc); + argvn = g_new0(char *,newargc); + GST_DEBUG(0,"got %d args\n",newargc); - // now attempt to construct the new arg list - j = 0;k = 0; - for (i=0;i 0) { - if (cmdline[k] == ' ') k++; - argvn[j] = g_new0(char,(i-k)+1); - memcpy(argvn[j],&cmdline[k],i-k); + // reverse the list and put the strings in the new array + i = newargc; - // catch misparses - if (strlen(argvn[j]) > 0) j++; - } - k = i; + for (slist = string_list; slist; slist = slist->next) + argvn[--i] = slist->data; - // if this is a bracket, construct a word - if ((cmdline[i] != ' ') && (cmdline[i] != '\0')) { - argvn[j++] = g_strdup_printf("%c",cmdline[i]); - k++; - } - } - } + g_slist_free(string_list); // print them out for (i=0;i