aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2016-10-31 01:52:18 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2016-10-31 01:52:18 +0100
commit7c3c92c533b65d4c29f2990915c9c424c3f6629d (patch)
treed9eb784d9c458c3d91fcf9a9e31e636f39d8a360 /miscutils
parenta92a74961d838209f3468d10426bc945ba26070c (diff)
downloadbusybox-w32-7c3c92c533b65d4c29f2990915c9c424c3f6629d.tar.gz
busybox-w32-7c3c92c533b65d4c29f2990915c9c424c3f6629d.tar.bz2
busybox-w32-7c3c92c533b65d4c29f2990915c9c424c3f6629d.zip
man: make width selection more thorough; explain how to override it
Fedora's "man CMD >file" still uses terminal width, not 80 (but disables formatting), this change mimics that. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/man.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/miscutils/man.c b/miscutils/man.c
index 01382c4d7..adb7770b4 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -9,6 +9,8 @@
9//usage: "Format and display manual page\n" 9//usage: "Format and display manual page\n"
10//usage: "\n -a Display all pages" 10//usage: "\n -a Display all pages"
11//usage: "\n -w Show page locations" 11//usage: "\n -w Show page locations"
12//usage: "\n"
13//usage: "\n$COLUMNS overrides output width"
12 14
13#include "libbb.h" 15#include "libbb.h"
14#include "common_bufsiz.h" 16#include "common_bufsiz.h"
@@ -53,7 +55,7 @@ struct globals {
53 setup_common_bufsiz(); \ 55 setup_common_bufsiz(); \
54 G.col = "col"; \ 56 G.col = "col"; \
55 G.tbl = "tbl"; \ 57 G.tbl = "tbl"; \
56 /* replaced -Tlatin1 with -Tascii for non-UTF8 displays */; \ 58 /* replaced -Tlatin1 with -Tascii for non-UTF8 displays */ \
57 G.nroff = "nroff -mandoc -Tascii"; \ 59 G.nroff = "nroff -mandoc -Tascii"; \
58 G.pager = ENABLE_LESS ? "less" : "more"; \ 60 G.pager = ENABLE_LESS ? "less" : "more"; \
59} while (0) 61} while (0)
@@ -132,15 +134,12 @@ static int run_pipe(char *man_filename, int man, int level)
132 close(STDIN_FILENO); 134 close(STDIN_FILENO);
133 open_zipped(man_filename, /*fail_if_not_compressed:*/ 0); /* guaranteed to use fd 0 (STDIN_FILENO) */ 135 open_zipped(man_filename, /*fail_if_not_compressed:*/ 0); /* guaranteed to use fd 0 (STDIN_FILENO) */
134 if (man) { 136 if (man) {
135 /* "man man" formats to screen width. 137 int w = get_terminal_width(-1);
136 * "man man >file" formats to default 80 columns.
137 * "man man | cat" formats to default 80 columns.
138 */
139 int w = get_terminal_width(STDOUT_FILENO);
140 if (w > 10) 138 if (w > 10)
141 w -= 2; 139 w -= 2;
142 /* "2>&1" is added so that nroff errors are shown in pager too. 140 /* "2>&1" is added so that nroff errors are shown in pager too.
143 * Otherwise it may show just empty screen */ 141 * Otherwise it may show just empty screen.
142 */
144 cmd = xasprintf("%s | %s -rLL=%un -rLT=%un 2>&1 | %s", 143 cmd = xasprintf("%s | %s -rLL=%un -rLT=%un 2>&1 | %s",
145 G.tbl, G.nroff, w, w, 144 G.tbl, G.nroff, w, w,
146 G.pager); 145 G.pager);