Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 3 Jun 2011 05:16:33 +0000 (UTC)
From:      Ruslan Ermilov <ru@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r222635 - head/usr.bin/man
Message-ID:  <201106030516.p535GXau049081@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ru
Date: Fri Jun  3 05:16:33 2011
New Revision: 222635
URL: http://svn.freebsd.org/changeset/base/222635

Log:
  Added support for the MANWIDTH environment variable:
  
  If set to a numeric value, used as the width manpages should be
  displayed.  Otherwise, if set to a special value ``tty'', and
  output is to a terminal, the pages may be displayed over the
  whole width of the screen.

Modified:
  head/usr.bin/man/man.1
  head/usr.bin/man/man.sh

Modified: head/usr.bin/man/man.1
==============================================================================
--- head/usr.bin/man/man.1	Fri Jun  3 03:39:33 2011	(r222634)
+++ head/usr.bin/man/man.1	Fri Jun  3 05:16:33 2011	(r222635)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 1, 2010
+.Dd June 2, 2011
 .Dt MAN 1
 .Os
 .Sh NAME
@@ -283,6 +283,12 @@ Restricts manual sections searched to th
 Corresponds to the
 .Fl S
 option.
+.It Ev MANWIDTH
+If set to a numeric value, used as the width manpages should be displayed.
+Otherwise, if set to a special value
+.Dq Li tty ,
+and output is to a terminal,
+the pages may be displayed over the whole width of the screen.
 .It Ev PAGER
 Program used to display files.
 If unset,

Modified: head/usr.bin/man/man.sh
==============================================================================
--- head/usr.bin/man/man.sh	Fri Jun  3 03:39:33 2011	(r222634)
+++ head/usr.bin/man/man.sh	Fri Jun  3 05:16:33 2011	(r222635)
@@ -112,7 +112,11 @@ check_man() {
 		setup_cattool $manpage
 		decho "    Found manpage $manpage"
 
-		if exists "$2" && is_newer $found $manpage; then
+		if [ -n "${use_width}" ]; then
+			# non-standard width
+			unset use_cat
+			decho "    Skipping catpage: non-standard page width"
+		elif exists "$2" && is_newer $found $manpage; then
 			# cat page found and is newer, use that
 			use_cat=yes
 			catpage=$found
@@ -352,6 +356,10 @@ man_display_page() {
 		;;
 	esac
 
+	if [ -n "${use_width}" ]; then
+		NROFF="$NROFF -rLL=${use_width}n -rLT=${use_width}n"
+	fi
+
 	if [ -n "$MANROFFSEQ" ]; then
 		set -- -$MANROFFSEQ
 		while getopts 'egprtv' preproc_arg; do
@@ -562,6 +570,35 @@ man_setup() {
 
 	build_manpath
 	man_setup_locale
+	man_setup_width
+}
+
+# Usage: man_setup_width
+# Set up page width.
+man_setup_width() {
+	local sizes
+
+	unset use_width
+	case "$MANWIDTH" in
+	[0-9]*)
+		if [ "$MANWIDTH" -gt 0 2>/dev/null ]; then
+			use_width=$MANWIDTH
+		fi
+		;;
+	[Tt][Tt][Yy])
+		if { sizes=$($STTY size 0>&3 2>/dev/null); } 3>&1; then
+			set -- $sizes
+			if [ $2 -gt 80 ]; then
+				use_width=$(($2-2))
+			fi
+		fi
+		;;
+	esac
+	if [ -n "$use_width" ]; then
+		decho "Using non-standard page width: ${use_width}"
+	else
+		decho 'Using standard page width'
+	fi
 }
 
 # Usage: man_setup_locale
@@ -900,6 +937,7 @@ VGRIND=vgrind
 
 COL=/usr/bin/col
 LOCALE=/usr/bin/locale
+STTY=/bin/stty
 SYSCTL=/sbin/sysctl
 
 debug=0



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201106030516.p535GXau049081>