aboutsummaryrefslogtreecommitdiff
path: root/bin/man
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-14 03:45:44 +0000
committerrsc <devnull@localhost>2005-01-14 03:45:44 +0000
commit78e51a8c6678b6e3dff3d619aa786669f531f4bc (patch)
tree015e00fde4fc837fd31b705e18d17dc913829388 /bin/man
parent2634795b5f0053bc0ff08e5d7bbc0eda8efea061 (diff)
downloadplan9port-78e51a8c6678b6e3dff3d619aa786669f531f4bc.tar.gz
plan9port-78e51a8c6678b6e3dff3d619aa786669f531f4bc.tar.bz2
plan9port-78e51a8c6678b6e3dff3d619aa786669f531f4bc.zip
checkpoint
Diffstat (limited to 'bin/man')
-rwxr-xr-xbin/man139
1 files changed, 88 insertions, 51 deletions
diff --git a/bin/man b/bin/man
index f11fd04d..dd4e042d 100755
--- a/bin/man
+++ b/bin/man
@@ -2,11 +2,9 @@
. $PLAN9/man/fonts
-cmd=n
-sec=()
-S=$PLAN9/man
-d=0
-
+#
+# formatters
+#
fn roff {
preproc=()
x=`{doctype $2}
@@ -38,6 +36,46 @@ fn roff {
}
}
+fn doecho { echo $1 }
+fn dotroff { roff t $1 }
+fn doproof { roff t $1 | proof }
+fn dopage { roff t $1 | page }
+fn donroff {
+ roff n $1 | sed '
+ ${
+ /^$/p
+ }
+ //N
+ /^\n$/D
+ '
+}
+seq=0
+fn dohtml {
+ MAN=manhtml
+ b=`{echo $1 | sed 's/\.[0-9].*//'}
+ if(test -f $b.html)
+ web $b.html
+ if not{
+ roff t $1 | troff2html >/tmp/man.$pid.$seq.html
+ web /tmp/man.$pid.$seq.html
+ seq=`{echo 1+$seq | hoc}
+ }
+}
+
+
+#
+# setup
+#
+if(! ~ $path(1) $PLAN9/bin)
+ path=($PLAN9/bin $path)
+cmd=donroff
+sec=()
+S=$PLAN9/man
+
+#
+# parse flags and sections
+#
+d=0
while(~ $d 0) {
if(~ $#* 0) {
echo 'Usage: man [-ntp] [-s sec] [0-9] [0-9] ... name1 name2 ...' >[1=2]
@@ -48,63 +86,62 @@ while(~ $d 0) {
shift
}
if not switch($1) {
- case -t ; cmd=t ; shift
- case -n ; cmd=n ; shift
- case -p ; cmd=p ; shift
- case -P ; cmd=P ; shift
+ case -t ; fmt=dotroff ; shift
+ case -n ; cmd=donroff ; shift
+ case -p ; cmd=doproof ; shift
+ case -P ; cmd=dopage ; shift
+ case -w ; cmd=doecho ; shift
+ case -h ; cmd=dohtml ; shift
+ case -- ; d=1 ; shift
case * ; d=1
}
}
if(~ $#sec 0) {
sec=`{ls -pd $S/man[0-9]* | sed 's/man//'}
}
-ix=$S/man$sec/INDEX
-if(~ $#* 1) pat='^'^$1^' '
-if not pat='^('^`{echo $* | 9 sed 's/ /|/g'}^') '
-fils=()
-for(i in $S/man$sec){
- if(test -f $i/INDEX){
- try=`{grep $pat $i/INDEX | 9 sed 's/^[^ ]* //'}
- if(! ~ $#try 0)
- fils=($fils $i/$try)
+
+#
+# search index
+#
+allfiles=()
+missing=no
+for(word){
+ files=()
+ regexp='^'^$word^' '
+ for(i in $S/man$sec){
+ if(test -f $i/INDEX){
+ try=`{grep $regexp $i/INDEX | sed 's/^[^ ]* //'}
+ if(! ~ $#try 0)
+ files=($files $i/$try)
+ }
}
-}
-# bug: should also do following loop if not all pages found
-if(~ $#fils 0) {
- # nothing in INDEX. try for file of given name
- for(i) {
- for(n in $sec) {
- try=$S/man$n/$i.$n*
- if (test -f $try)
- fils=($fils $try)
+ if(~ $#files 0){
+ for(i in $S/man$sec){
+ if(test -f $i/$word.[0-9]*)
+ files=($files $i/$word.[0-9]*)
}
}
- if(~ $#fils 0) {
- echo 'man: no manual page' >[1=2]
- exit 'no man'
+ if(~ $#files 0){
+ echo 'man: no manual page' $word >[1=2]
+ missing=yes
}
+ allfiles=($allfiles $files)
}
-for(i in $fils) {
- if(! test -f $i)
- echo need $i >[1=2]
- if not {
- switch($cmd) {
- case t
- roff t $i
+if(~ $#allfiles 0)
+ exit 'no man'
+allfiles=`{ls $allfiles | sort -u >[2]/dev/null}
- case p
- roff t $i | proof
+files=()
+for(i in $allfiles){
+ if(test -f $i)
+ files=($files $i)
+ if not
+ echo need $i >[1=2]
+}
- case P
- roff t $i |tr2post |psfonts |page
+#
+# format pages
+#
+for(i in $files)
+ $cmd $i
- case n
- roff n $i | 9 sed '
- ${
- /^$/p
- }
- //N
- /^\n$/D'
- }
- }
-}