summaryrefslogtreecommitdiff
path: root/dis/man
diff options
context:
space:
mode:
Diffstat (limited to 'dis/man')
-rwxr-xr-xdis/man114
1 files changed, 114 insertions, 0 deletions
diff --git a/dis/man b/dis/man
new file mode 100755
index 00000000..ebd13f4f
--- /dev/null
+++ b/dis/man
@@ -0,0 +1,114 @@
+#!/dis/sh.dis
+# Plan 9 man script adaptation for Inferno
+# for more details see the real man(1)
+load std
+
+fils=''
+cmd=n
+sec=()
+S=/man
+d=0
+
+x=$* # see sh(1) for details about s/$*/$x/.
+x=`{echo $x|tr A-Z a-z|tr -dc 'a-z0-9_ \012-/'} # fold case, delete funny chars
+
+search=yes
+while {~ $d 0}{
+ #echo d$d search$search cmd$cmd fils$fils: $"x
+ if {no $x}{
+ echo 'Usage: man [-bnSwpf] [0-9] [0-9] ... name1 name2 ...'
+ exit
+ }
+ if{ftest -d $S/${hd $x}}{
+ sec=($sec ${hd $x}); x=${tl $x};
+ }{
+ if{~ ${hd $x} '-n'}{
+ cmd=n; x=${tl $x};
+ }{~ ${hd $x} '-w'}{
+ cmd=w; x=${tl $x};
+ }{~ ${hd $x} '-b'}{
+ cmd=b; x=${tl $x};
+ }{~ ${hd $x} '-p'}{
+ cmd=p; x=${tl $x};
+ }{~ ${hd $x} '-s'}{
+ search=no; x=${tl $x};
+ }{~ ${hd $x} '-f'}{
+ search=no; x=${tl $x};
+ if {ftest -f ${hd $x}}{
+ fils=(${hd $x});
+ }{
+ echo 'man: bad option -f '${hd $x}
+ exit 'no file'
+ }
+ }{
+ d=1;
+ }
+
+ if{no $x}{
+ d=1;
+ }
+ }
+}
+if{no $sec} {
+ sec=`{ls -pd $S/[0-9]* }
+}
+
+ix=$S/$sec/INDEX
+if{~ $#x 1} {pat='^'^$x^' '}
+{pat='^('^`{echo $x | sed 's/ /|/g'}^') '}
+
+if{~ $search yes} {
+ for i in $S/$sec {
+ if {ftest -f $i/INDEX}{
+ try=`{grep -i $pat $i/INDEX | sed 's/^[^ ]*//'}
+ if {! no $try}{
+ fils=($fils $i/$try)
+ }
+ }
+ }
+}
+
+if{no $fils} {
+ # nothing in INDEX. try for file or given name
+ for i in $x {
+ if{~ $i intro} {i=0intro}
+ for n in $sec {
+ try=`{echo $S/$n/$i | tr A-Z a-z}
+ if {ftest -f $try} {
+ fils=($fils $try)
+ }
+ }
+ }
+ if{~ $#fils 0} {
+ echo 'man: no manual page'
+ exit 'no man'
+ }
+}
+
+for i in $fils {
+ if {~ $i ''}{
+ #echo bug ignore ''
+ }{! ftest -f $i}{
+ echo need:$i
+ }{
+ if {~ $cmd n}{
+ man2txt $i
+ }{~ $cmd w}{
+ echo $i
+ }{~ $cmd p}{
+ wm/man -f $i
+ }{~ $cmd b}{
+ if{~ $i '/man/*/*'}{
+ x=`{echo $i | sed 's;/man/(.*)/(.*);\1 \2;'}
+ if{~ ${index 2 $x} 0intro}{
+ x=(${index 1 $x} intro)
+ }
+ }{ x=($i ''); }
+
+ man2txt $i |
+ plumb -i -d edit -a action showdata -a filename '/man/'^${tl $x}^'('^${hd $x}^')'
+
+ }
+ }
+
+}