mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-30 05:31:15 +00:00
Applied Dominic Ludlam's patch to allow quoted args in gstreamer-launch
Original commit message from CVS: Applied Dominic Ludlam's patch to allow quoted args in gstreamer-launch
This commit is contained in:
parent
ef48e57a9e
commit
5a15653ca1
1 changed files with 61 additions and 36 deletions
|
@ -323,8 +323,9 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
|
||||||
gst_parse_priv priv;
|
gst_parse_priv priv;
|
||||||
gchar **argvn;
|
gchar **argvn;
|
||||||
gint newargc;
|
gint newargc;
|
||||||
gint len;
|
gint i;
|
||||||
int i,j,k;
|
const gchar *cp, *start, *end;
|
||||||
|
GSList *string_list = NULL, *slist;
|
||||||
|
|
||||||
priv.bincount = 0;
|
priv.bincount = 0;
|
||||||
priv.threadcount = 0;
|
priv.threadcount = 0;
|
||||||
|
@ -333,46 +334,64 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
|
||||||
priv.verbose = FALSE;
|
priv.verbose = FALSE;
|
||||||
priv.debug = FALSE;
|
priv.debug = FALSE;
|
||||||
|
|
||||||
// first walk through quickly and see how many more slots we need
|
end = cmdline + strlen(cmdline);
|
||||||
len = strlen(cmdline);
|
newargc = 0;
|
||||||
newargc = 1;
|
|
||||||
for (i=0;i<len;i++) {
|
// Extract the arguments to a gslist in reverse order
|
||||||
// if it's a space, it denotes a new arg
|
for (cp = cmdline; cp < end; ) {
|
||||||
if (cmdline[i] == ' ') newargc++;
|
i = strcspn(cp, "([{}]) \"");
|
||||||
// if it's a brace and isn't followed by a space, give it an arg
|
|
||||||
if (strchr("([{}])",cmdline[i])) {
|
if (i > 0) {
|
||||||
// not followed by space, gets one
|
// normal argument - copy and add to the list
|
||||||
if (cmdline[i+1] != ' ') newargc++;
|
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
|
// now allocate the new argv array
|
||||||
argvn = g_new0(char *,newargc+1);
|
argvn = g_new0(char *,newargc);
|
||||||
GST_DEBUG(0,"supposed to have %d args\n",newargc);
|
GST_DEBUG(0,"got %d args\n",newargc);
|
||||||
|
|
||||||
// now attempt to construct the new arg list
|
// reverse the list and put the strings in the new array
|
||||||
j = 0;k = 0;
|
i = newargc;
|
||||||
for (i=0;i<len+1;i++) {
|
|
||||||
// if it's a delimiter
|
|
||||||
if (strchr("([{}]) ",cmdline[i]) || (cmdline[i] == '\0')) {
|
|
||||||
// extract the previous arg
|
|
||||||
if (i-k > 0) {
|
|
||||||
if (cmdline[k] == ' ') k++;
|
|
||||||
argvn[j] = g_new0(char,(i-k)+1);
|
|
||||||
memcpy(argvn[j],&cmdline[k],i-k);
|
|
||||||
|
|
||||||
// catch misparses
|
for (slist = string_list; slist; slist = slist->next)
|
||||||
if (strlen(argvn[j]) > 0) j++;
|
argvn[--i] = slist->data;
|
||||||
}
|
|
||||||
k = i;
|
|
||||||
|
|
||||||
// if this is a bracket, construct a word
|
g_slist_free(string_list);
|
||||||
if ((cmdline[i] != ' ') && (cmdline[i] != '\0')) {
|
|
||||||
argvn[j++] = g_strdup_printf("%c",cmdline[i]);
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// print them out
|
// print them out
|
||||||
for (i=0;i<newargc;i++) {
|
for (i=0;i<newargc;i++) {
|
||||||
|
@ -382,5 +401,11 @@ gst_parse_launch(const gchar *cmdline,GstBin *parent)
|
||||||
// set up the elementcounts hash
|
// set up the elementcounts hash
|
||||||
priv.elementcounts = g_hash_table_new(g_str_hash,g_str_equal);
|
priv.elementcounts = g_hash_table_new(g_str_hash,g_str_equal);
|
||||||
|
|
||||||
return gst_parse_launch_cmdline(newargc,argvn,parent,&priv);
|
// do it!
|
||||||
|
i = gst_parse_launch_cmdline(newargc,argvn,parent,&priv);
|
||||||
|
|
||||||
|
// GST_DEBUG(0, "Finished - freeing temporary argument array");
|
||||||
|
// g_strfreev(argvn);
|
||||||
|
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue