From a4e42f7b06ffe6413f8ae5028f540b1fbe7666c2 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Sat, 27 Oct 2001 13:44:18 +0000 Subject: [PATCH] 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 --- gst/gstparse.c | 29 ++++++++++++++++------------- gst/gstparse.h | 6 ++++++ tools/gstreamer-guilaunch.c | 23 +++++++++++++++++++++-- tools/gstreamer-launch.c | 5 ++++- 4 files changed, 47 insertions(+), 16 deletions(-) diff --git a/gst/gstparse.c b/gst/gstparse.c index b7e5191..533d0cf 100644 --- a/gst/gstparse.c +++ b/gst/gstparse.c @@ -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. // rename previous element to next arg. if (arg[1] != '\0') { - fprintf(stderr,"error, unexpected junk after [\n"); - exit(-1); + fprintf(stderr,"error, unexpected junk after [\n"); + return GST_PARSE_ERROR_SYNTAX; } i++; if (i < argc) { - gst_element_set_name(previous, argv[i]); + gst_element_set_name(previous, argv[i]); } else { - fprintf(stderr,"error, expected element name, found end of arguments\n"); - exit(-1); + fprintf(stderr,"error, expected element name, found end of arguments\n"); + return GST_PARSE_ERROR_SYNTAX; } i++; if (i >= argc) { - fprintf(stderr,"error, expected ], found end of arguments\n"); - exit(-1); + fprintf(stderr,"error, expected ], found end of arguments\n"); + return GST_PARSE_ERROR_SYNTAX; } else if (strcmp(argv[i], "]") != 0) { - fprintf(stderr,"error, expected ], found '%s'\n", argv[i]); - exit(-1); + fprintf(stderr,"error, expected ], found '%s'\n", argv[i]); + return GST_PARSE_ERROR_SYNTAX; } } else { 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++)); if (!element) { 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)); } 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++)); if (!element) { 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)); } else { @@ -290,7 +290,10 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr 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 { // we have an element @@ -304,7 +307,7 @@ gst_parse_launch_cmdline(int argc,char *argv[],GstBin *parent,gst_parse_priv *pr #else fprintf(stderr,"Couldn't create a '%s', no such element or need to load pluginn?\n",arg); #endif - exit(-1); + return GST_PARSE_ERROR_NOSUCH_ELEMENT; } GST_DEBUG(0,"CREATED element %s\n",GST_ELEMENT_NAME(element)); } diff --git a/gst/gstparse.h b/gst/gstparse.h index fda38ae..374e456 100644 --- a/gst/gstparse.h +++ b/gst/gstparse.h @@ -31,6 +31,12 @@ extern "C" { #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); #else // GST_DISABLE_PARSE diff --git a/tools/gstreamer-guilaunch.c b/tools/gstreamer-guilaunch.c index ce5e23c..91f6c3b 100644 --- a/tools/gstreamer-guilaunch.c +++ b/tools/gstreamer-guilaunch.c @@ -516,7 +516,8 @@ parse_callback( GtkWidget *widget, 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 *try_pipe = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(pipe_combo)->entry)); - + gint parse_result; + if (pipeline){ g_print("unreffing\n"); gst_object_unref (GST_OBJECT (pipeline)); @@ -524,7 +525,25 @@ parse_callback( GtkWidget *widget, g_print ("trying pipeline: %s\n", try_pipe); 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); build_tree(tree_item, GST_BIN(pipeline)); diff --git a/tools/gstreamer-launch.c b/tools/gstreamer-launch.c index 61c6bee..8e91fc0 100644 --- a/tools/gstreamer-launch.c +++ b/tools/gstreamer-launch.c @@ -152,7 +152,10 @@ main(int argc, char *argv[]) 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 if (save_pipeline) { -- 2.7.4