git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] help: use man viewer path from "man.<tool>.path" config var

From
Christian Couder <chriscool@tuxfamily.org>
Date
Mar 18, 2008, 05:22 UTC
Message-ID
<20080318062236.7b5e515f.chriscool@tuxfamily.org>

This patch implements reading values from "man.<tool>.path" configuration variables, and using these values as pathes to the man viewer <tool>s when lauching them.

This makes it possible to use different version of the tools than the one on the current PATH, or maybe a custom script.

In this patch we also try to launch "konqueror" using "kfmclient" even if a path to a konqueror binary is given in "man.konqueror.path".

And we add warnings after "exec" calls in case of exec errors. 
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 help.c |   97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 94 insertions(+), 3 deletions(-)
diff --git a/help.c b/help.c
index ecaca77..fd88c22 100644
--- a/help.c
+++ b/help.c
@@ -15,6 +15,12 @@ static struct man_viewer_list {
 	struct man_viewer_list *next;
 } *man_viewer_list;
 
+static struct man_viewer_info_list {
+	struct man_viewer_info_list *next;
+	const char *info;
+	char name[FLEX_ARRAY];
+} *man_viewer_info_list;
+
 enum help_format {
 	HELP_FORMAT_MAN,
 	HELP_FORMAT_INFO,
@@ -48,6 +54,18 @@ static enum help_format parse_help_format(const char *format)
 	die("unrecognized help format '%s'", format);
 }
 
+static const char *get_man_viewer_info(const char *name)
+{
+	struct man_viewer_info_list *viewer;
+
+	for (viewer = man_viewer_info_list; viewer; viewer = viewer->next)
+	{
+		if (!strcasecmp(name, viewer->name))
+			return viewer->info;
+	}
+	return NULL;
+}
+
 static int check_emacsclient_version(void)
 {
 	struct strbuf buffer = STRBUF_INIT;
@@ -99,8 +117,13 @@ static void exec_woman_emacs(const char *page)
 	if (!check_emacsclient_version()) {
 		/* This works only with emacsclient version >= 22. */
 		struct strbuf man_page = STRBUF_INIT;
+		const char *path = get_man_viewer_info("woman");
+
+		if (!path)
+			path = "emacsclient";
 		strbuf_addf(&man_page, "(woman \"%s\")", page);
-		execlp("emacsclient", "emacsclient", "-e", man_page.buf, NULL);
+		execlp(path, "emacsclient", "-e", man_page.buf, NULL);
+		warning("failed to exec '%s': %s", path, strerror(errno));
 	}
 }
 
@@ -109,14 +132,35 @@ static void exec_man_konqueror(const char *page)
 	const char *display = getenv("DISPLAY");
 	if (display && *display) {
 		struct strbuf man_page = STRBUF_INIT;
+		const char *path = get_man_viewer_info("konqueror");
+
+		/* It's simpler to launch konqueror using kfmclient. */
+		if (path) {
+			const char *file = strrchr(path, '/') + 1;
+			if (!strcmp(file, "konqueror")) {
+				char *new = xstrdup(path);
+				char *dest = strrchr(new, '/') + 1;
+
+				/* strlen("konqueror") == strlen("kfmclient") */
+				strcpy(dest, "kfmclient");
+				path = new;
+			}
+		} else
+			path = "kfmclient";
 		strbuf_addf(&man_page, "man:%s(1)", page);
-		execlp("kfmclient", "kfmclient", "newTab", man_page.buf, NULL);
+		execlp(path, "kfmclient", "newTab", man_page.buf, NULL);
+		warning("failed to exec '%s': %s", path, strerror(errno));
 	}
 }
 
 static void exec_man_man(const char *page)
 {
-	execlp("man", "man", page, NULL);
+	const char *path = get_man_viewer_info("man");
+
+	if (!path)
+		path = "man";
+	execlp(path, "man", page, NULL);
+	warning("failed to exec '%s': %s", path, strerror(errno));
 }
 
 static void do_add_man_viewer(void (*exec)(const char *))
@@ -144,6 +188,50 @@ static int add_man_viewer(const char *value)
 	return 0;
 }
 
+static void do_add_man_viewer_info(const char *name,
+				   size_t len,
+				   const char *value)
+{
+	struct man_viewer_info_list *new = xcalloc(1, sizeof(*new) + len + 1);
+
+	strncpy(new->name, name, len);
+	new->info = xstrdup(value);
+	new->next = man_viewer_info_list;
+	man_viewer_info_list = new;
+}
+
+static int add_man_viewer_path(const char *name,
+			       size_t len,
+			       const char *value)
+{
+	if (!strncasecmp("man", name, len) ||
+	    !strncasecmp("woman", name, len) ||
+	    !strncasecmp("konqueror", name, len))
+		do_add_man_viewer_info(name, len, value);
+	else
+		warning("'%s': path for unsupported man viewer.", name);
+
+	return 0;
+}
+
+static int add_man_viewer_info(const char *var, const char *value)
+{
+	const char *name = var + 4;
+	const char *subkey = strrchr(name, '.');
+
+	if (!subkey)
+		return error("Config with no key for man viewer: %s", name);
+
+	if (!strcmp(subkey, ".path")) {
+		if (!value)
+			return config_error_nonbool(var);
+		return add_man_viewer_path(name, subkey - name, value);
+	}
+
+	warning("'%s': unsupported man viewer sub key.", subkey);
+	return 0;
+}
+
 static int git_help_config(const char *var, const char *value)
 {
 	if (!strcmp(var, "help.format")) {
@@ -157,6 +245,9 @@ static int git_help_config(const char *var, const char *value)
 			return config_error_nonbool(var);
 		return add_man_viewer(value);
 	}
+	if (!prefixcmp(var, "man."))
+		return add_man_viewer_info(var, value);
+
 	return git_default_config(var, value);
 }
 
-- 
1.5.4.4.685.g3070a.dirty
Next: Junio C Hamano
Message 1 of 11 in “help: use man viewer path from "man.<tool>.path" config var”
  1. 1/2 help: use man viewer path from "man.<tool>.path" config varChristian Couder, Mar 18, 2008
  2. Junio C HamanoMar 18, 2008
  3. Christian CouderMar 20, 2008
  4. Junio C HamanoMar 20, 2008
  5. Christian CouderMar 21, 2008
  6. Junio C HamanoMar 21, 2008
  7. Christian CouderMar 25, 2008
  8. Junio C HamanoMar 25, 2008
  9. Christian CouderMar 26, 2008
  10. Xavier MaillardMar 23, 2008
  11. Xavier MaillardMar 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.