return a negative error code instead of exiting on parse error

Original commit message from CVS:
return a negative error code instead of exiting on parse error
This commit is contained in:
Steve Baker 2001-10-27 13:44:18 +00:00
parent f7589295b3
commit a4e42f7b06
4 changed files with 47 additions and 16 deletions

View file

@ -246,23 +246,23 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
// we have the start of a name of the preceding element. // we have the start of a name of the preceding element.
// rename previous element to next arg. // rename previous element to next arg.
if (arg[1] != '\0') { if (arg[1] != '\0') {
fprintf(stderr,"error, unexpected junk after [\n"); fprintf(stderr,"error, unexpected junk after [\n");
exit(-1); return GST_PARSE_ERROR_SYNTAX;
} }
i++; i++;
if (i < argc) { if (i < argc) {
gst_element_set_name(previous, argv[i]); gst_element_set_name(previous, argv[i]);
} else { } else {
fprintf(stderr,"error, expected element name, found end of arguments\n"); fprintf(stderr,"error, expected element name, found end of arguments\n");
exit(-1); return GST_PARSE_ERROR_SYNTAX;
} }
i++; i++;
if (i >= argc) { if (i >= argc) {
fprintf(stderr,"error, expected ], found end of arguments\n"); fprintf(stderr,"error, expected ], found end of arguments\n");
exit(-1); return GST_PARSE_ERROR_SYNTAX;
} else if (strcmp(argv[i], "]") != 0) { } else if (strcmp(argv[i], "]") != 0) {
fprintf(stderr,"error, expected ], found '%s'\n", argv[i]); fprintf(stderr,"error, expected ], found '%s'\n", argv[i]);
exit(-1); return GST_PARSE_ERROR_SYNTAX;
} }
} else { } else {
DEBUG("have element or bin/thread\n"); DEBUG("have element or bin/thread\n");
@ -273,7 +273,7 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
element = gst_bin_new(g_strdup_printf("bin%d",priv->bincount++)); element = gst_bin_new(g_strdup_printf("bin%d",priv->bincount++));
if (!element) { if (!element) {
fprintf(stderr,"Couldn't create a bin!\n"); fprintf(stderr,"Couldn't create a bin!\n");
// exit(-1); return GST_PARSE_ERROR_CREATING_ELEMENT;
} }
GST_DEBUG(0,"CREATED bin %s\n",GST_ELEMENT_NAME(element)); GST_DEBUG(0,"CREATED bin %s\n",GST_ELEMENT_NAME(element));
} else if (arg[0] == '{') { } else if (arg[0] == '{') {
@ -281,7 +281,7 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
element = gst_thread_new(g_strdup_printf("thread%d",priv->threadcount++)); element = gst_thread_new(g_strdup_printf("thread%d",priv->threadcount++));
if (!element) { if (!element) {
fprintf(stderr,"Couldn't create a thread!\n"); fprintf(stderr,"Couldn't create a thread!\n");
// exit(-1); return GST_PARSE_ERROR_CREATING_ELEMENT;
} }
GST_DEBUG(0,"CREATED thread %s\n",GST_ELEMENT_NAME(element)); GST_DEBUG(0,"CREATED thread %s\n",GST_ELEMENT_NAME(element));
} else { } else {
@ -290,7 +290,10 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
continue; continue;
} }
i += gst_parse_launch_cmdline(argc - i, argv + i + 1, GST_BIN (element), priv); j = gst_parse_launch_cmdline(argc - i, argv + i + 1, GST_BIN (element), priv);
//check for parse error
if (j < 0) return j;
i += j;
} else { } else {
// we have an element // we have an element
@ -304,7 +307,7 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr
#else #else
fprintf(stderr,"Couldn't create a '%s', no such element or need to load pluginn?\n",arg); fprintf(stderr,"Couldn't create a '%s', no such element or need to load pluginn?\n",arg);
#endif #endif
exit(-1); return GST_PARSE_ERROR_NOSUCH_ELEMENT;
} }
GST_DEBUG(0,"CREATED element %s\n",GST_ELEMENT_NAME(element)); GST_DEBUG(0,"CREATED element %s\n",GST_ELEMENT_NAME(element));
} }

View file

@ -31,6 +31,12 @@ extern "C" {
#ifndef GST_DISABLE_PARSE #ifndef GST_DISABLE_PARSE
typedef enum {
GST_PARSE_ERROR_SYNTAX = -1,
GST_PARSE_ERROR_CREATING_ELEMENT = -2,
GST_PARSE_ERROR_NOSUCH_ELEMENT = -3,
} GstParseErrors;
gint gst_parse_launch (const gchar *cmdline, GstBin *parent); gint gst_parse_launch (const gchar *cmdline, GstBin *parent);
#else // GST_DISABLE_PARSE #else // GST_DISABLE_PARSE

View file

@ -516,6 +516,7 @@ parse_callback( GtkWidget *widget,
GtkWidget *tree_item = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(widget), "tree_item"); GtkWidget *tree_item = (GtkWidget*)gtk_object_get_data(GTK_OBJECT(widget), "tree_item");
gchar *last_pipe = (gchar*)gtk_object_get_data(GTK_OBJECT(widget), "last_pipe"); gchar *last_pipe = (gchar*)gtk_object_get_data(GTK_OBJECT(widget), "last_pipe");
gchar *try_pipe = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(pipe_combo)->entry)); gchar *try_pipe = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(pipe_combo)->entry));
gint parse_result;
if (pipeline){ if (pipeline){
g_print("unreffing\n"); g_print("unreffing\n");
@ -524,7 +525,25 @@ parse_callback( GtkWidget *widget,
g_print ("trying pipeline: %s\n", try_pipe); g_print ("trying pipeline: %s\n", try_pipe);
pipeline = gst_pipeline_new ("launch"); pipeline = gst_pipeline_new ("launch");
gst_parse_launch (try_pipe, GST_BIN (pipeline)); parse_result = gst_parse_launch (try_pipe, GST_BIN (pipeline));
if (parse_result < 0){
switch(parse_result){
case GST_PARSE_ERROR_SYNTAX:
gtk_label_set_text(GTK_LABEL(status), "error parsing syntax of pipeline");
break;
case GST_PARSE_ERROR_CREATING_ELEMENT:
gtk_label_set_text(GTK_LABEL(status), "error creating a core element");
break;
case GST_PARSE_ERROR_NOSUCH_ELEMENT:
gtk_label_set_text(GTK_LABEL(status), "error finding an element which was requested");
break;
default:
gtk_label_set_text(GTK_LABEL(status), "unknown error parsing pipeline");
break;
}
gst_object_unref (GST_OBJECT (pipeline));
return;
}
gtk_widget_set_sensitive(GTK_WIDGET(start_but), TRUE); gtk_widget_set_sensitive(GTK_WIDGET(start_but), TRUE);
build_tree(tree_item, GST_BIN(pipeline)); build_tree(tree_item, GST_BIN(pipeline));

View file

@ -152,7 +152,10 @@ main(int argc, char *argv[])
exit(1); exit(1);
} }
gst_parse_launch (cmdline, GST_BIN (pipeline)); if (gst_parse_launch (cmdline, GST_BIN (pipeline)) < 0){
fprintf(stderr,"ERROR: pipeline description could not be parsed\n");
exit(1);
}
#ifndef GST_DISABLE_LOADSAVE #ifndef GST_DISABLE_LOADSAVE
if (save_pipeline) { if (save_pipeline) {