9front - general discussion about 9front
 help / color / mirror / Atom feed
* Re: [9front] Manpage Previews
@ 2019-06-07  6:23 vp
  2019-06-07 14:09 ` Stanley Lieber
  0 siblings, 1 reply; 8+ messages in thread
From: vp @ 2019-06-07  6:23 UTC (permalink / raw)
  To: 9front

[-- Attachment #1: Type: text/plain, Size: 481 bytes --]

Binding over the system manual path is a nice Plan 9™ code avoidance
tactic, which got tired really quickly for me during some sources
expeditions.

My solution was adding the -f flag to the man(1) utility which
disables the searching behaviour and treats the arguments as paths to
the troff source files, for example:

	man -f /sys/man/1/man 
	
The resulting diff is weird to look at since I've hoisted a big chunk
of code into a function, so I attach the whole script instead.

[-- Attachment #2: man --]
[-- Type: text/plain, Size: 2172 bytes --]

#!/bin/rc
# man - print manual pages
rfork e

. /sys/man/fonts

out=cat
search=yes
cmd=n
sec=()
files=()

fn usage {
	echo 'Usage: man [-bfnpPStw] [section ...] title ...' >[1=2]
	exit
}

fn roff {
	preproc=()
	postproc=cat
	x=`{doctype $2}
	if (~ $1 t){
		opts=-Tutf
		if(~ $x *grap*)
			preproc=($preproc grap)
		if(~ $x *pic*)
			preproc=($preproc pic)
	}
	if not{
		opts='-N -rL1000i'
		if (grep -s '^\.(2C|sp *[0-9]*\.)' $2)
			postproc=col
	}
	if(~ $x *eqn*)
		preproc=($preproc eqn)
	if(~ $x *tbl*)
		preproc=($preproc tbl)
	preproc=`{echo $preproc | sed 's/ /|/g'}
	if(~ $#preproc 0)
		preproc=cat
	{echo -n $FONTS | cat $2} | eval $preproc | troff $opts -$MAN | $postproc
}

fn doman {
	cmd=$1; shift
	for(i){
		switch($cmd){
		case w
			echo $i
		case t
			roff t $i
		case p
			roff t $i | grep -v '^x X html'
		case P
			roff t $i
		case n
			roff n $i | sed '
				${
       				       /^$/p
				}
				//N
				/^\n$/D'
		case b
			x=`{echo $i | sed 's;/sys/man/(.*)/(.*);\1 \2;'}
			if(~ $x(2) 0intro) x=($x(1) intro)
			roff n $i | sed '
				${
       				       /^$/p
				}
				//N
				/^\n$/D' |
			plumb -i -d edit -a 'action=showdata filename=/man/'$x(2)^'('$x(1)^')'
		}
	} | $out
}

d=no
while(~ $d no){
	if(~ $#* 0) usage
	if(test -d /sys/man/$1){
		sec=($sec $1)
		shift
	}
	if not
		switch($1){
		case -b ; cmd=b ; shift
		case -f ; search=file ; shift
		case -n ; cmd=n ; shift
		case -P ; cmd=P ; out=page ; shift
		case -p ; cmd=p ; out=proof ; shift
		case -S ; search=no ; shift
		case -t ; cmd=t ; shift
		case -w ; cmd=w ; shift
		case * ; d=yes
		}
}
if(~ $#* 0) usage

if(~ $search file){
	doman $cmd $*
	exit
}
if(~ $#sec 0)
	sec=`{ls -pd /sys/man/[0-9]*}
if(~ $search yes){
	pat='^('^`{echo $* | sed 's/ /|/g'}^') '
	for(i in /sys/man/$sec)
		if(/bin/test -f $i/INDEX){
			try=`{grep -i $pat $i/INDEX | sed 's/^[^ ]* //' | sort -u}
			if(! ~ $#try 0)
				files=($files $i/$try)
		}
}
if(~ $#files 0)
	for(i){
		if(~ $i intro) i=0intro
		for(n in $sec){
			try=`{echo /sys/man/$n/$i | tr A-Z a-z}
			if (/bin/test -f $try)
				files=($files $try)
		}
	}
if(~ $#files 0){
	echo 'man: no manual page' >[1=2]
	exit 'no man'
}
doman $cmd $files

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [9front] Manpage Previews
@ 2019-06-09 20:11 umbraticus
  0 siblings, 0 replies; 8+ messages in thread
From: umbraticus @ 2019-06-09 20:11 UTC (permalink / raw)
  To: 9front

> Couldn't you also just `nroff -man' directly and avoid `man' altogether?
> What is `man' really buying you here, if you're not searching the index?

man does some extra work to remove nroff's pagination, but yeah...

umbraticus


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [9front] Manpage Previews
@ 2019-06-09 18:26 vp
  0 siblings, 0 replies; 8+ messages in thread
From: vp @ 2019-06-09 18:26 UTC (permalink / raw)
  To: 9front

It only took me a weekend and a nudge to realize that:

	troff -man manual.man | page

is all I need.



^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: [9front] Manpage Previews
@ 2019-06-07  5:55 ori
  0 siblings, 0 replies; 8+ messages in thread
From: ori @ 2019-06-07  5:55 UTC (permalink / raw)
  To: sl, 9front

>      Can’t you just bind your work directory over /sys/man/[n]?  

Point.

Forget that patch, then.



^ permalink raw reply	[flat|nested] 8+ messages in thread
* Manpage Previews
@ 2019-06-07  5:44 ori
  2019-06-07  5:51 ` [9front] " Stanley Lieber
  0 siblings, 1 reply; 8+ messages in thread
From: ori @ 2019-06-07  5:44 UTC (permalink / raw)
  To: 9front

I'm writing some manpages. I'd like to be able to preview them
with man. I'm proposing that if we don't find a manpage in
/sys/man/*, we look in the current directory.

Ok?

diff -r f0621f169310 rc/bin/man
--- a/rc/bin/man	Wed Jun 05 16:04:50 2019 +0930
+++ b/rc/bin/man	Thu Jun 06 22:42:54 2019 -0700
@@ -103,6 +103,8 @@
 			if (/bin/test -f $try)
 				fils=($fils $try)
 		}
+		if(/bin/test -f $i)
+			fils=($fils $i)
 	}
 	if(~ $#fils 0) {
 		echo 'man: no manual page' >[1=2]



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-06-09 20:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-07  6:23 [9front] Manpage Previews vp
2019-06-07 14:09 ` Stanley Lieber
2019-06-07 21:17   ` Silas McCroskey
2019-06-08 16:48     ` Stanley Lieber
  -- strict thread matches above, loose matches on Subject: below --
2019-06-09 20:11 umbraticus
2019-06-09 18:26 vp
2019-06-07  5:55 ori
2019-06-07  5:44 ori
2019-06-07  5:51 ` [9front] " Stanley Lieber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).