Revision: 1239
http://geeqie.svn.sourceforge.net/geeqie/?rev=1239&view=rev
Author: zas_
Date: 2008-11-15 10:35:43 +0000 (Sat, 15 Nov 2008)
Log Message:
-----------
Add a wrapper around system() call named runcmd() which allows easier
debugging. Improve the code launching the help browser.
Modified Paths:
--------------
trunk/src/fullscreen.c
trunk/src/misc.c
trunk/src/misc.h
trunk/src/remote.c
trunk/src/window.c
Modified: trunk/src/fullscreen.c
===================================================================
--- trunk/src/fullscreen.c 2008-11-14 01:10:18 UTC (rev 1238)
+++ trunk/src/fullscreen.c 2008-11-15 10:35:43 UTC (rev 1239)
@@ -15,6 +15,7 @@
#include "fullscreen.h"
#include "image.h"
+#include "misc.h"
#include "ui_fileops.h"
#include "ui_menu.h"
#include "ui_misc.h"
@@ -190,7 +191,7 @@
if (found)
{
- system(XSCREENSAVER_COMMAND);
+ runcmd(XSCREENSAVER_COMMAND);
}
}
Modified: trunk/src/misc.c
===================================================================
--- trunk/src/misc.c 2008-11-14 01:10:18 UTC (rev 1238)
+++ trunk/src/misc.c 2008-11-15 10:35:43 UTC (rev 1239)
@@ -186,4 +186,56 @@
}
return g_strdup("\"\"");
}
+
+/* Run a command like system() but may output debug messages. */
+int runcmd(gchar *cmd)
+{
+#if 1
+ return system(cmd);
+ return 0;
+#else
+ /* For debugging purposes */
+ int retval = -1;
+ FILE *in;
+
+ DEBUG_1("Running command: %s", cmd);
+
+ in = popen(cmd, "r");
+ if (in)
+ {
+ int status;
+ const gchar *msg;
+ gchar buf[2048];
+
+ while (fgets(buf, sizeof(buf), in) != NULL )
+ {
+ DEBUG_1("Output: %s", buf);
+ }
+
+ status = pclose(in);
+
+ if (WIFEXITED(status))
+ {
+ msg = "Command terminated with exit code";
+ retval = WEXITSTATUS(status);
+ }
+ else if (WIFSIGNALED(status))
+ {
+ msg = "Command was killed by signal";
+ retval = WTERMSIG(status);
+ }
+ else
+ {
+ msg = "pclose() returned";
+ retval = status;
+ }
+
+ DEBUG_1("%s : %d\n", msg, retval);
+ }
+
+ return retval;
+#endif
+}
+
+
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
Modified: trunk/src/misc.h
===================================================================
--- trunk/src/misc.h 2008-11-14 01:10:18 UTC (rev 1238)
+++ trunk/src/misc.h 2008-11-15 10:35:43 UTC (rev 1239)
@@ -19,6 +19,7 @@
gchar *expand_tilde(const gchar *filename);
gchar *quoted_value(const gchar *text, const gchar **tail);
gchar *escquote_value(const gchar *text);
+int runcmd(gchar *cmd);
#endif /* MISC_H */
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
Modified: trunk/src/remote.c
===================================================================
--- trunk/src/remote.c 2008-11-14 01:10:18 UTC (rev 1238)
+++ trunk/src/remote.c 2008-11-15 10:35:43 UTC (rev 1239)
@@ -743,7 +743,7 @@
if (get_debug_level()) g_string_append(command, " --debug");
g_string_append(command, " &");
- system(command->str);
+ runcmd(command->str);
g_string_free(command, TRUE);
while (!rc && retry_count > 0)
Modified: trunk/src/window.c
===================================================================
--- trunk/src/window.c 2008-11-14 01:10:18 UTC (rev 1238)
+++ trunk/src/window.c 2008-11-15 10:35:43 UTC (rev 1239)
@@ -12,6 +12,7 @@
#include "main.h"
#include "window.h"
+#include "misc.h"
#include "pixbuf_util.h"
#include "ui_fileops.h"
#include "ui_help.h"
@@ -113,14 +114,15 @@
return result;
}
-static void help_browser_command(const gchar *command, const gchar *path)
+static int help_browser_command(const gchar *command, const gchar *path)
{
gchar *result;
gchar *buf;
gchar *begin;
gchar *end;
+ int retval = -1;
- if (!command || !path) return;
+ if (!command || !path) return retval;
DEBUG_1("Help command pre \"%s\", \"%s\"", command, path);
@@ -142,9 +144,11 @@
DEBUG_1("Help command post [%s]", result);
- system(result);
+ retval = runcmd(result);
+ DEBUG_1("Help command exit code: %d", retval);
g_free(result);
+ return retval;
}
/*
@@ -177,18 +181,32 @@
static void help_browser_run(void)
{
- gchar *path;
- gchar *result;
+ gchar *name = options->helpers.html_browser.command_name;
+ gchar *cmd = options->helpers.html_browser.command_line;
+ gchar *path = g_build_filename(options->documentation.htmldir,
"index.html", NULL);
+ gchar *result = NULL;
gint i;
- result = command_result(options->helpers.html_browser.command_name,
options->helpers.html_browser.command_line);
-
- i = 0;
- while (!result && html_browsers[i])
+ i = 0;
+ while (!result)
{
- result = command_result(html_browsers[i], html_browsers[i+1]);
- i += 2;
+ if ((name && *name) || (cmd && *cmd)) {
+ DEBUG_1("Trying browser: name=%s command=%s", name,
cmd);
+ result = command_result(name, cmd);
+ DEBUG_1("Result: %s", result);
+ if (result)
+ {
+ int ret = help_browser_command(result, path);
+
+ if (ret == 0) break;
+ g_free(result);
+ result = NULL;
+ }
}
+ if (!html_browsers[i]) break;
+ name = html_browsers[i++];
+ cmd = html_browsers[i++];
+ }
if (!result)
{
@@ -196,10 +214,7 @@
return;
}
- path = g_build_filename(options->documentation.htmldir, "index.html",
NULL);
- help_browser_command(result, path);
g_free(path);
-
g_free(result);
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geeqie-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geeqie-svn