changeset 2678:195267d1c78f

Fix #548: Send text output to stdout https://github.com/BestImageViewer/geeqie/issues/548 Additional parameter to print_term() and printf_term() to send output to either stderr or stdout
author cclark <colin.clark@cclark.uk>
date Sat, 09 Dec 2017 11:13:34 +0000
parents 2487552f9995
children 0645828182a9
files src/debug.c src/main.c src/remote.c src/ui_fileops.c src/ui_fileops.h
diffstat 5 files changed, 48 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/src/debug.c	Fri Dec 08 11:58:17 2017 +0000
+++ b/src/debug.c	Sat Dec 09 11:13:34 2017 +0000
@@ -92,7 +92,7 @@
 
 				if (!ret_exec)
 					{
-					print_term(buf_nl);
+					print_term(FALSE, buf_nl);
 					if (strcmp(domain, DOMAIN_INFO) == 0)
 						g_idle_add(log_normal_cb, buf_nl);
 					else
@@ -103,7 +103,7 @@
 		}
 	else
 		{
-		print_term(buf_nl);
+		print_term(FALSE, buf_nl);
 		if (strcmp(domain, DOMAIN_INFO) == 0)
 			g_idle_add(log_normal_cb, buf_nl);
 		else
--- a/src/main.c	Fri Dec 08 11:58:17 2017 +0000
+++ b/src/main.c	Sat Dec 09 11:13:34 2017 +0000
@@ -345,7 +345,7 @@
 			else if (strcmp(cmd_line, "-v") == 0 ||
 				 strcmp(cmd_line, "--version") == 0)
 				{
-				printf_term("%s %s\n", GQ_APPNAME, VERSION);
+				printf_term(FALSE, "%s %s\n", GQ_APPNAME, VERSION);
 				exit(0);
 				}
 			else if (strcmp(cmd_line, "--alternate") == 0)
@@ -357,31 +357,31 @@
 			else if (strcmp(cmd_line, "-h") == 0 ||
 				 strcmp(cmd_line, "--help") == 0)
 				{
-				printf_term("%s %s\n", GQ_APPNAME, VERSION);
-				printf_term(_("Usage: %s [options] [path]\n\n"), GQ_APPNAME_LC);
-				print_term(_("valid options are:\n"));
-				print_term(_("  +t, --with-tools                 force show of tools\n"));
-				print_term(_("  -t, --without-tools              force hide of tools\n"));
-				print_term(_("  -f, --fullscreen                 start in full screen mode\n"));
-				print_term(_("  -s, --slideshow                  start in slideshow mode\n"));
-				print_term(_("  -l, --list [files] [collections] open collection window for command line\n"));
-				print_term(_("      --blank                      start with blank file list\n"));
-				print_term(_("      --geometry=XxY+XOFF+YOFF     set main window location\n"));
-				print_term(_("  -r, --remote                     send following commands to open window\n"));
-				print_term(_("  -rh,--remote-help                print remote command list\n"));
+				printf_term(FALSE, "%s %s\n", GQ_APPNAME, VERSION);
+				printf_term(FALSE, _("Usage: %s [options] [path]\n\n"), GQ_APPNAME_LC);
+				print_term(FALSE, _("valid options are:\n"));
+				print_term(FALSE, _("  +t, --with-tools                 force show of tools\n"));
+				print_term(FALSE, _("  -t, --without-tools              force hide of tools\n"));
+				print_term(FALSE, _("  -f, --fullscreen                 start in full screen mode\n"));
+				print_term(FALSE, _("  -s, --slideshow                  start in slideshow mode\n"));
+				print_term(FALSE, _("  -l, --list [files] [collections] open collection window for command line\n"));
+				print_term(FALSE, _("      --blank                      start with blank file list\n"));
+				print_term(FALSE, _("      --geometry=XxY+XOFF+YOFF     set main window location\n"));
+				print_term(FALSE, _("  -r, --remote                     send following commands to open window\n"));
+				print_term(FALSE, _("  -rh,--remote-help                print remote command list\n"));
 #ifdef DEBUG
-				print_term(_("      --debug[=level]              turn on debug output\n"));
-				print_term(_("  -g:<regexp>, --grep:<regexp>     filter debug output\n"));
+				print_term(FALSE, _("      --debug[=level]              turn on debug output\n"));
+				print_term(FALSE, _("  -g:<regexp>, --grep:<regexp>     filter debug output\n"));
 #endif
-				print_term(_("  +w, --show-log-window            show log window\n"));
-				print_term(_("  -o:<file>, --log-file:<file>     save log data to file\n"));
-				print_term(_("  -v, --version                    print version info\n"));
-				print_term(_("  -h, --help                       show this message\n\n"));
+				print_term(FALSE, _("  +w, --show-log-window            show log window\n"));
+				print_term(FALSE, _("  -o:<file>, --log-file:<file>     save log data to file\n"));
+				print_term(FALSE, _("  -v, --version                    print version info\n"));
+				print_term(FALSE, _("  -h, --help                       show this message\n\n"));
 
 #if 0
 				/* these options are not officially supported!
 				 * only for testing new features, no need to translate them */
-				print_term(  "  --alternate                use alternate similarity algorithm\n");
+				print_term(FALSE, "  --alternate                use alternate similarity algorithm\n");
 #endif
 
 
@@ -389,7 +389,7 @@
 				}
 			else if (!remote_do)
 				{
-				printf_term(_("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
+				printf_term(TRUE, _("invalid or ignored: %s\nUse --help for options\n"), cmd_line);
 				}
 
 			g_free(cmd_all);
@@ -418,16 +418,16 @@
 			{
 			GList *work = remote_errors;
 
-			printf_term(_("Invalid or ignored remote options: "));
+			printf_term(TRUE,_("Invalid or ignored remote options: "));
 			while (work)
 				{
 				gchar *opt = work->data;
 
-				printf_term("%s%s", (work == remote_errors) ? "" : ", ", opt);
+				printf_term(TRUE, "%s%s", (work == remote_errors) ? "" : ", ", opt);
 				work = work->next;
 				}
 
-			printf_term(_("\nUse --remote-help for valid remote options.\n"));
+			printf_term(TRUE, _("\nUse --remote-help for valid remote options.\n"));
 			}
 
 		remote_control(argv[0], remote_list, command_line->path, list, command_line->collection_list);
--- a/src/remote.c	Fri Dec 08 11:58:17 2017 +0000
+++ b/src/remote.c	Sat Dec 09 11:13:34 2017 +0000
@@ -502,7 +502,7 @@
 		if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS ||
 				t1 >= 24 || t2 >= 60 || t3 >= 60)
 			{
-			printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
+			printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
 								SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
 			return;
 			}
@@ -513,7 +513,7 @@
 		if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS ||
 				t1 >= 60 || t2 >= 60)
 			{
-			printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
+			printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
 								SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
 			return;
 			}
@@ -523,7 +523,7 @@
 		n = t1;
 		if (n < SLIDESHOW_MIN_SECONDS || n > SLIDESHOW_MAX_SECONDS)
 			{
-			printf_term("Remote slideshow delay out of range (%.1f to %.1f)\n",
+			printf_term(TRUE, "Remote slideshow delay out of range (%.1f to %.1f)\n",
 								SLIDESHOW_MIN_SECONDS, SLIDESHOW_MAX_SECONDS);
 			return;
 			}
@@ -876,7 +876,7 @@
 	gchar *s_opt_param;
 	gchar *l_opt_param;
 
-	print_term(_("Remote command list:\n"));
+	print_term(FALSE, _("Remote command list:\n"));
 
 	i = 0;
 	while (remote_commands[i].func != NULL)
@@ -885,7 +885,7 @@
 			{
 			s_opt_param = g_strconcat(remote_commands[i].opt_s, remote_commands[i].parameter, NULL);
 			l_opt_param = g_strconcat(remote_commands[i].opt_l, remote_commands[i].parameter, NULL);
-			printf_term("  %-11s%-1s %-30s%-s\n",
+			printf_term(FALSE, "  %-11s%-1s %-30s%-s\n",
 				    (remote_commands[i].opt_s) ? s_opt_param : "",
 				    (remote_commands[i].opt_s && remote_commands[i].opt_l) ? "," : " ",
 				    (remote_commands[i].opt_l) ? l_opt_param : "",
@@ -895,7 +895,7 @@
 			}
 		i++;
 		}
-	printf_term(N_("\n  All other command line parameters are used as plain files if they exists.\n"));
+	printf_term(FALSE, N_("\n  All other command line parameters are used as plain files if they exists.\n"));
 }
 
 GList *remote_build_list(GList *list, gint argc, gchar *argv[], GList **errors)
@@ -945,7 +945,7 @@
 		gint retry_count = 12;
 		gboolean blank = FALSE;
 
-		printf_term(_("Remote %s not running, starting..."), GQ_APPNAME);
+		printf_term(FALSE, _("Remote %s not running, starting..."), GQ_APPNAME);
 
 		command = g_string_new(arg_exec);
 
@@ -985,11 +985,11 @@
 			{
 			usleep((retry_count > 10) ? 500000 : 1000000);
 			rc = remote_client_open(buf);
-			if (!rc) print_term(".");
+			if (!rc) print_term(FALSE, ".");
 			retry_count--;
 			}
 
-		print_term("\n");
+		print_term(FALSE, "\n");
 
 		started = TRUE;
 		}
@@ -1081,7 +1081,7 @@
 		}
 	else
 		{
-		print_term(_("Remote not available\n"));
+		print_term(TRUE, _("Remote not available\n"));
 		}
 
 	_exit(0);
--- a/src/ui_fileops.c	Fri Dec 08 11:58:17 2017 +0000
+++ b/src/ui_fileops.c	Sat Dec 09 11:13:34 2017 +0000
@@ -52,12 +52,19 @@
 
 
 
-void print_term(const gchar *text_utf8)
+void print_term(gboolean err, const gchar *text_utf8)
 {
 	gchar *text_l;
 
 	text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL);
-	fputs((text_l) ? text_l : text_utf8, stderr);
+	if (err)
+		{
+		fputs((text_l) ? text_l : text_utf8, stderr);
+		}
+	else
+		{
+		fputs((text_l) ? text_l : text_utf8, stdout);
+		}
 	if(command_line && command_line->ssi)
 		secure_fputs(command_line->ssi, (text_l) ? text_l : text_utf8);
 	g_free(text_l);
--- a/src/ui_fileops.h	Fri Dec 08 11:58:17 2017 +0000
+++ b/src/ui_fileops.h	Sat Dec 09 11:13:34 2017 +0000
@@ -30,12 +30,12 @@
 
 
 
-void print_term(const gchar *text_utf8);
+void print_term(gboolean err, const gchar *text_utf8);
 
-#define printf_term(...) \
+#define printf_term(err, ...) \
 	do { \
 		gchar *msg = g_strdup_printf(__VA_ARGS__); \
-		print_term(msg); \
+		print_term(err, msg); \
 		g_free(msg); \
 	} while (0)