gst-inspect: fix unused-const-variable error in windows
[platform/upstream/gstreamer.git] / tools / gst-inspect.c
index e1e5693..1b5ed83 100644 (file)
 #   include <sys/wait.h>
 #endif
 
-#define DEFAULT_PAGER "less"
+
+/* "R" : support color
+ * "X" : do not clear the screen when leaving the pager
+ * "F" : skip the pager if content fit into the screen
+ */
+#define DEFAULT_LESS_OPTS "RXF"
 
 gboolean colored_output = TRUE;
 
+#ifdef G_OS_UNIX
+static const gchar DEFAULT_PAGER[] = "less";
 GPid child_pid = -1;
+#endif
 GMainLoop *loop = NULL;
 
 /* Console colors */
@@ -628,9 +636,11 @@ print_object_properties_info (GObject * obj, GObjectClass * obj_class,
               g_type_name (param->value_type), RESET_COLOR);
           if (param->value_type == GST_TYPE_STRUCTURE) {
             const GstStructure *s = gst_value_get_structure (&value);
-            if (s)
+            if (s) {
+              g_print ("\n");
               gst_structure_foreach (s, print_field,
                   (gpointer) "                           ");
+            }
           }
         } else if (G_IS_PARAM_SPEC_POINTER (param)) {
           if (param->value_type != G_TYPE_POINTER) {
@@ -1882,20 +1892,18 @@ redirect_stdout (void)
 
   argv = g_strsplit (pager, " ", 0);
 
-  /* "R" : support color
-   * "X" : Do not init/deinit terminal. Uncleared "inspected output" on terminal
-   *       seems to be more useful
-   */
   envp = g_get_environ ();
-  envp = g_environ_setenv (envp, "LESS", "-RX", TRUE);
+  envp = g_environ_setenv (envp, "LESS", DEFAULT_LESS_OPTS, TRUE);
 
   if (!g_spawn_async_with_pipes (NULL, argv, envp,
           G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
           NULL, NULL, &child_pid, &stdin_fd,
           /* pass null stdout/stderr to inherit our fds */
           NULL, NULL, &error)) {
-    g_warning ("g_spawn_async_with_pipes() failed: %s\n",
-        GST_STR_NULL (error->message));
+    if (pager != DEFAULT_PAGER) {
+      g_warning ("g_spawn_async_with_pipes() failed: %s\n",
+          GST_STR_NULL (error->message));
+    }
     g_strfreev (argv);
     g_strfreev (envp);
     g_clear_error (&error);
@@ -2006,27 +2014,6 @@ main (int argc, char *argv[])
   gst_init (&argc, &argv);
 #endif
 
-  no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
-  /* We only support truecolor */
-  colored_output &= (no_colors == NULL);
-
-#ifdef G_OS_UNIX
-  if (isatty (STDOUT_FILENO)) {
-    if (redirect_stdout ())
-      loop = g_main_loop_new (NULL, FALSE);
-  } else {
-    colored_output = FALSE;
-  }
-#elif defined(G_OS_WIN32)
-  {
-    gint fd = _fileno (stdout);
-    /* On Windows 10, g_log_writer_supports_color will also setup the console
-     * so that it correctly interprets ANSI VT sequences if it's supported */
-    if (!_isatty (fd) || !g_log_writer_supports_color (fd))
-      colored_output = FALSE;
-  }
-#endif
-
   gst_tools_print_version ();
 
   if (print_all && argc > 1) {
@@ -2077,6 +2064,27 @@ main (int argc, char *argv[])
     return exit_code;
   }
 
+  no_colors = g_getenv ("GST_INSPECT_NO_COLORS");
+  /* We only support truecolor */
+  colored_output &= (no_colors == NULL);
+
+#ifdef G_OS_UNIX
+  if (isatty (STDOUT_FILENO)) {
+    if (redirect_stdout ())
+      loop = g_main_loop_new (NULL, FALSE);
+  } else {
+    colored_output = FALSE;
+  }
+#elif defined(G_OS_WIN32)
+  {
+    gint fd = _fileno (stdout);
+    /* On Windows 10, g_log_writer_supports_color will also setup the console
+     * so that it correctly interprets ANSI VT sequences if it's supported */
+    if (!_isatty (fd) || !g_log_writer_supports_color (fd))
+      colored_output = FALSE;
+  }
+#endif
+
   /* if no arguments, print out list of elements */
   if (uri_handlers) {
     print_all_uri_handlers ();