Index: gst.c
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gst.c,v
retrieving revision 1.146.2.1
diff -u -r1.146.2.1 gst.c
--- gst.c	3 Mar 2005 18:39:49 -0000	1.146.2.1
+++ gst.c	10 Mar 2005 16:50:14 -0000
@@ -64,6 +64,8 @@
     const GstPoptOption * option, const char *arg, void *data);
 static gboolean init_pre (void);
 static gboolean init_post (void);
+static gboolean parse_goption_arg (const gchar * s_opt,
+    const gchar * arg, gpointer data, GError ** err);
 
 static GSList *preload_plugins = NULL;
 
@@ -227,6 +229,78 @@
 }
 
 /**
+ * gst_init_get_option_group:
+ *
+ * Returns a #GOptionGroup with GStreamer's argument specifications. The
+ * group is set up to use standard GOption callbacks, so when using this
+ * group in combination with GOption parsing methods, all argument parsing
+ * and initialization is automated.
+ *
+ * This function is useful if you want to integrate GStreamer with other
+ * libraries that use GOption.
+ *
+ * Returns: a pointer to a GStreamer option group. Should be dereferenced
+ * after use.
+ */
+
+GOptionGroup *
+gst_init_get_option_group (void)
+{
+  GOptionGroup *group;
+  static GOptionEntry gst_args[] = {
+    { "gst-version", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Print the GStreamer version"), NULL },
+    { "gst-fatal-warnings", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+       N_("Make all warnings fatal"), NULL },
+#ifndef GST_DISABLE_GST_DEBUG
+    { "gst-debug-help", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Print available debug categories and exit"), NULL },
+    { "gst-debug-level", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Default debug level from 1 (only error) to 5 (anything) or "
+         "0 for no output"),
+      N_("LEVEL") },
+    { "gst-debug", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Comma-separated list of category_name:level pairs to set "
+         "specific levels for the individual categories. Example: "
+         "GST_AUTOPLUG:5,GST_ELEMENT_*:3"),
+      N_("LIST") },
+    { "gst-debug-no-color", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Disable colored debugging output"), NULL },
+    { "gst-debug-disable", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Disable debugging"), NULL },
+#endif
+    { "gst-disable-cpu-opt", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Disable accelerated CPU instructions"), NULL },
+    { "gst-plugin-spew", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Enable verbose plugin loading diagnostics"), NULL },
+    { "gst-plugin-path", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Colon-separated paths containing plugins"), N_("PATHS") },
+    { "gst-plugin-load", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Comma-separated list of plugins to preload in addition to the "
+         "list stored in environment variable GST_PLUGIN_PATH"),
+      N_("PLUGINS") },
+    { "gst-disable-segtrap", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Disable trapping of segmentation faults during plugin loading"),
+      NULL },
+    { "gst-scheduler", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Scheduler to use"), N_("SCHEDULER") },
+    { "gst-registry", 0, 0, G_OPTION_ARG_CALLBACK, parse_goption_arg,
+      N_("Registry to use"), N_("REGISTRY") },
+    { NULL }
+  };
+
+  group = g_option_group_new ("gst", _("GStreamer Options"),
+      _("Show GStreamer Options"), NULL, NULL);
+  g_option_group_set_parse_hooks (group, (GOptionParseFunc) init_pre,
+      (GOptionParseFunc) init_post);
+
+  g_option_group_add_entries (group, gst_args);
+  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+
+  return group;
+}
+
+/**
  * gst_init_check:
  * @argc: pointer to application's argc
  * @argv: pointer to application's argv
@@ -726,12 +800,120 @@
 }
 #endif
 
+static gboolean
+parse_one_option (gint opt, const gchar * arg, GError ** err)
+{
+  switch (opt) {
+    case ARG_VERSION:
+      g_print ("GStreamer Core Library version %s\n", GST_VERSION);
+      exit (0);
+    case ARG_FATAL_WARNINGS: {
+      GLogLevelFlags fatal_mask;
+
+      fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
+      fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
+      g_log_set_always_fatal (fatal_mask);
+      break;
+    }
+#ifndef GST_DISABLE_GST_DEBUG
+    case ARG_DEBUG_LEVEL:{
+      gint tmp = 0;
+
+      tmp = strtol (arg, NULL, 0);
+      if (tmp >= 0 && tmp < GST_LEVEL_COUNT) {
+        gst_debug_set_default_threshold (tmp);
+      }
+      break;
+    }
+    case ARG_DEBUG:
+      parse_debug_list (arg);
+      break;
+    case ARG_DEBUG_NO_COLOR:
+      gst_debug_set_colored (FALSE);
+      break;
+    case ARG_DEBUG_DISABLE:
+      gst_debug_set_active (FALSE);
+      break;
+    case ARG_DEBUG_HELP:
+      gst_debug_help ();
+      exit (0);
+#endif
+    case ARG_DISABLE_CPU_OPT:
+      _gst_enable_cpu_opt = FALSE;
+      break;
+    case ARG_PLUGIN_SPEW:
+      break;
+    case ARG_PLUGIN_PATH:
+#ifndef GST_DISABLE_REGISTRY
+      split_and_iterate (arg, G_SEARCHPATH_SEPARATOR_S, add_path_func,
+          _user_registry);
+#endif /* GST_DISABLE_REGISTRY */
+      break;
+    case ARG_PLUGIN_LOAD:
+      split_and_iterate (arg, ",", prepare_for_load_plugin_func, NULL);
+      break;
+    case ARG_SEGTRAP_DISABLE:
+      _gst_disable_segtrap = TRUE;
+      break;
+    case ARG_SCHEDULER:
+      gst_scheduler_factory_set_default_name (arg);
+      break;
+    case ARG_REGISTRY:
+#ifndef GST_DISABLE_REGISTRY
+      g_object_set (G_OBJECT (_user_registry), "location", arg, NULL);
+      _gst_registry_fixed = TRUE;
+#endif /* GST_DISABLE_REGISTRY */
+      break;
+    default:
+      g_set_error (err, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION,
+          _("Unknown option"));
+      return FALSE;
+  }
+
+  return TRUE;
+}
+
+static gboolean
+parse_goption_arg (const gchar * opt,
+    const gchar * arg, gpointer data, GError ** err)
+{
+  const struct {
+    gchar *opt; int val;
+  } options[] = {
+    { "gst-version", ARG_VERSION },
+    { "gst-fatal-warnings", ARG_FATAL_WARNINGS },
+#ifndef GST_DISABLE_GST_DEBUG
+    { "gst-debug-level", ARG_DEBUG_LEVEL },
+    { "gst-debug", ARG_DEBUG },
+    { "gst-debug-disable", ARG_DEBUG_DISABLE },
+    { "gst-debug-no-color", ARG_DEBUG_NO_COLOR },
+    { "gst-debug-help", ARG_DEBUG_HELP },
+#endif
+    { "gst-disable-cpu-opt", ARG_DISABLE_CPU_OPT },
+    { "gst-plugin-spew", ARG_PLUGIN_SPEW },
+    { "gst-plugin-path", ARG_PLUGIN_PATH },
+    { "gst-plugin-load", ARG_PLUGIN_LOAD },
+    { "gst-disable-segtrap", ARG_SEGTRAP_DISABLE },
+    { "gst-scheduler", ARG_SCHEDULER },
+    { "gst-registry", ARG_REGISTRY },
+    { NULL }
+  };
+  gint val = 0, n;
+
+  for (n = 0; options[n].opt; n++) {
+    if (!strcmp (opt, options[n].opt)) {
+      val = n;
+      break;
+    }
+  }
+
+  return parse_one_option (val, arg, err);
+}
+
 static void
 init_popt_callback (poptContext context, enum poptCallbackReason reason,
     const GstPoptOption * option, const char *arg, void *data)
 {
-  GLogLevelFlags fatal_mask;
-
   if (gst_initialized)
     return;
   switch (reason) {
@@ -739,70 +921,16 @@
       if (!init_pre ())
         _gst_initialization_failure = TRUE;
       break;
-    case POPT_CALLBACK_REASON_OPTION:
-      switch (option->val) {
-        case ARG_VERSION:
-          g_print ("GStreamer Core Library version %s\n", GST_VERSION);
-          exit (0);
-        case ARG_FATAL_WARNINGS:
-          fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
-          fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
-          g_log_set_always_fatal (fatal_mask);
-          break;
-#ifndef GST_DISABLE_GST_DEBUG
-        case ARG_DEBUG_LEVEL:{
-          gint tmp = 0;
+    case POPT_CALLBACK_REASON_OPTION: {
+      GError *err = NULL;
 
-          tmp = strtol (arg, NULL, 0);
-          if (tmp >= 0 && tmp < GST_LEVEL_COUNT) {
-            gst_debug_set_default_threshold (tmp);
-          }
-          break;
-        }
-        case ARG_DEBUG:
-          parse_debug_list (arg);
-          break;
-        case ARG_DEBUG_NO_COLOR:
-          gst_debug_set_colored (FALSE);
-          break;
-        case ARG_DEBUG_DISABLE:
-          gst_debug_set_active (FALSE);
-          break;
-        case ARG_DEBUG_HELP:
-          gst_debug_help ();
-          exit (0);
-#endif
-        case ARG_DISABLE_CPU_OPT:
-          _gst_enable_cpu_opt = FALSE;
-          break;
-        case ARG_PLUGIN_SPEW:
-          break;
-        case ARG_PLUGIN_PATH:
-#ifndef GST_DISABLE_REGISTRY
-          split_and_iterate (arg, G_SEARCHPATH_SEPARATOR_S, add_path_func,
-              _user_registry);
-#endif /* GST_DISABLE_REGISTRY */
-          break;
-        case ARG_PLUGIN_LOAD:
-          split_and_iterate (arg, ",", prepare_for_load_plugin_func, NULL);
-          break;
-        case ARG_SEGTRAP_DISABLE:
-          _gst_disable_segtrap = TRUE;
-          break;
-        case ARG_SCHEDULER:
-          gst_scheduler_factory_set_default_name (arg);
-          break;
-        case ARG_REGISTRY:
-#ifndef GST_DISABLE_REGISTRY
-          g_object_set (G_OBJECT (_user_registry), "location", arg, NULL);
-          _gst_registry_fixed = TRUE;
-#endif /* GST_DISABLE_REGISTRY */
-          break;
-        default:
-          g_warning ("option %d not recognized", option->val);
-          break;
+      if (!parse_one_option (option->val, arg, &err)) {
+        g_print ("%s\n", err->message);
+        g_error_free (err);
+        exit (1);
       }
       break;
+    }
     case POPT_CALLBACK_REASON_POST:
       if (!init_post ())
         _gst_initialization_failure = TRUE;
Index: gst.h
===================================================================
RCS file: /cvs/gstreamer/gstreamer/gst/gst.h,v
retrieving revision 1.73
diff -u -r1.73 gst.h
--- gst.h	21 Jan 2005 17:52:50 -0000	1.73
+++ gst.h	10 Mar 2005 16:50:14 -0000
@@ -93,7 +93,8 @@
 						 const GstPoptOption
 						 *popt_options);
 
-const GstPoptOption *	gst_init_get_popt_table		(void);
+const GstPoptOption *	gst_init_get_popt_table	(void);
+GOptionGroup *	gst_init_get_option_group	(void);
 
 #ifndef GST_DISABLE_DEPRECATED
 void		gst_use_threads			(gboolean use_threads);
