}
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: */
#include "main.h"
#include "window.h"
+#include "misc.h"
#include "pixbuf_util.h"
#include "ui_fileops.h"
#include "ui_help.h"
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);
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;
}
/*
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)
return;
}
- path = g_build_filename(options->documentation.htmldir, "index.html", NULL);
- help_browser_command(result, path);
g_free(path);
-
g_free(result);
}