shithub: x

ref: b77fd67eca2958623314acf29c05dfbabd14c90d
dir: /man/

View raw version
#!/bin/rc
rfork e
. /sys/lib/x/lib.rc
usage = '
	x/man [-b] [man-flags] [section] title
'

flags=()
width=72
out='stdout'
section=()
title=()
while(~ $1 -* && ! ~ $1 --){
	switch($1){
	case -b
		out='plumb'
	case *
		flags=($flags $1)
	}
	shift
}
if(~ $1 --)
	shift
if(~ $#* 2){
	section = $1; shift
}
title = $1
if(~ $#title 0)
	usage

if(~ $out 'plumb')
	fn output {
		t = /tmp/xman
		mkdir -p $t
		col -bx >$t/tmp.$pid
		if(~ $#section 0){
			<$t/tmp.$pid awk -F'[)(]' '
				NR == 1 {printf($2) >"/env/section"}
			'
			section = `{cat /env/section}
		}
		if(~ $#section 0)
			section = ''
		mkdir -p $t/$section
		mv $t/tmp.$pid $t/$section/$title
		plumb $t/$section/$title
	}
if not
	fn output {col -bx}

{if(~ $#section 0)
	x/run 'MANWIDTH='$width man $flags $title
if not
	x/run 'MANWIDTH='$width man $flags -s $section $title
}| output