man.config can define lines such as
DEFINE         pager   less -s

this patch parses them, additionally it always sets pager to less instead of more.

Signed-off-by: John Spencer <maillist-busy...@barfooze.de>

--- busybox-1.20.2.org/miscutils/man.c	2013-06-02 10:12:54.251000003 +0000
+++ busybox-1.20.2/miscutils/man.c	2013-06-02 10:43:25.251000003 +0000
@@ -150,7 +150,7 @@
 int man_main(int argc UNUSED_PARAM, char **argv)
 {
 	parser_t *parser;
-	const char *pager;
+	const char *pager = 0;
 	char **man_path_list;
 	char *sec_list;
 	char *cur_path, *cur_sect;
@@ -171,12 +171,6 @@
 		man_path_list[0] = (char*)"/usr/man";
 	else
 		count_mp++;
-	pager = getenv("MANPAGER");
-	if (!pager) {
-		pager = getenv("PAGER");
-		if (!pager)
-			pager = "more";
-	}
 
 	/* Parse man.conf[ig] or man_db.conf */
 	/* man version 1.6f uses man.config */
@@ -190,7 +184,13 @@
 	while (config_read(parser, token, 2, 0, "# \t", PARSE_NORMAL)) {
 		if (!token[1])
 			continue;
-		if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */
+		if (strcmp("DEFINE", token[0]) == 0) {
+			size_t n = 5;
+			if (strncmp("pager", token[1], n) == 0) {
+				while(isspace(token[1][++n]));
+				pager = xstrdup(token[1]+n);
+			}
+		} else if (strcmp("MANDATORY_MANPATH"+10, token[0]) == 0 /* "MANPATH"? */
 		 || strcmp("MANDATORY_MANPATH", token[0]) == 0
 		) {
 			char *path = token[1];
@@ -229,6 +229,14 @@
 		}
 	}
 	config_close(parser);
+	
+	{
+		/* environment overrides setting from man.config */
+		const char* env_pager = getenv("MANPAGER");
+		if (!env_pager) env_pager = getenv("PAGER");
+		if (env_pager) pager = env_pager;
+		if (!pager) pager = "less";
+	}
 
 	not_found = 0;
 	do { /* for each argv[] */
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to