#!/usr/bin/env osh : : osh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;; : : " @(#)$Id: dman.osh 534 2008-10-31 21:21:06Z jneitzel $ " : : " The author of this file, J.A. Neitzel , " : " hereby grants it to the public domain. " : : : " NOTE: This command file is no longer used, but reading it may still " : " be useful for some osh scripting ideas. " : : : " Display the manual page specified by the name argument. " : " If PAGER is set in the environment, its value is used as " : " the pagination program when displaying the manual page. " : " Otherwise, more(1) is used. " : : " usage: dman [section] name " : : " Check for correct usage. " : >>$0'' <'' ; : >>$1'' <'' ; : >>$2'' <'' ; killer $0'' dman if $n = 1 -a X$1 != X -o $n = 2 -a X$1 != X -a X$2 != X goto OK1 pusage $0 '"[section] name"' ; exit : OK1 - " Ensure that stdin, stdout, and stderr are connected to a tty. " if X$t != X -a -t 1 -a -t 2 goto OK2 perror $0 '"Not a tty"' ; exit : OK2 - " Change the two positional parameters described below if " : " required for your system. Do the same also for line 61. " : : " | - location of system manual pages " : " | " : " | | - location of local manual pages " : " | | " exec osh -s1 /usr/share/man /usr/local/man $1'' $2'' $$ : " Ignore SIGINT and SIGQUIT, and create temporary directory. " sigign + 2 3 chdir $1 ; chdir $2 ; chdir / if ! { mkdir -m 0700 /tmp/dman-$$ } if { exit } false if X$4 = X goto default if X$3 = X1 -o X$3 = X2 -o X$3 = X3 -o X$3 = X3p -o \ X$3 = X4 -o X$3 = X5 -o X$3 = X6 -o X$3 = X7 -o \ X$3 = X8 -o X$3 = X9 if ! { goto $3 } rm -r /tmp/dman-$5 ; false rmdir /tmp/dman-$$ perror dman $3'": Bad section"' exit : default - " Search all sections for the specified manual page. " exec osh -s2 1 $3 8 $3 6 $3 2 $3 3 $3 4 $3 5 $3 7 $3 9 $3 3p $3 ! $3 : search if ! -e /tmp/dman-$$ exit if $n = 2 goto error-default osh -s3 /usr/share/man /usr/local/man $1'' $2'' $$ ; \ shift ; shift ; goto search goto $3 : error-default rm -r /tmp/dman-$$ perror dman '"No entry for "'$2'" in the manual."' exit : 1 : 8 - " Search an individual section for the specified manual page. " : 6 - " The first page found is displayed, and the search stops. " : 2 - " The search order is as follows: " : 3 : 4 - " 1) system (/usr/share/man): " : 5 - " - Preference is given to cat pages over man pages. " : 7 - " 2) local (/usr/local/man): " : 9 - " - Preference is given to cat pages over man pages. " : 3p : system-cat chdir $1 if ! -r cat$3/$4.0 goto system-man if ! { printenv PAGER } goto more-sc >/dev/null printenv PAGER | sed 's!.*!exec & 'cat$3/$4.0! | osh goto quit : more-sc more -s cat$3/$4.0 ; goto quit : system-man if ! -r man$3/$4.$3 goto local-cat perror dman '"Formatting manual page..."' nroff -mandoc -Tascii /tmp/dman-$5/output if ! { printenv PAGER } goto more-sm >/dev/null printenv PAGER | \ sed 's!.*!exec & '/tmp/dman-$5/output! | osh goto quit : more-sm more -s /tmp/dman-$5/output ; goto quit : local-cat chdir $2 if ! -r cat$3/$4.0 goto local-man if ! { printenv PAGER } goto more-lc >/dev/null printenv PAGER | sed 's!.*!exec & 'cat$3/$4.0! | osh goto quit : more-lc more -s cat$3/$4.0 ; goto quit : local-man if ! -r man$3/$4.$3 goto error-section perror dman '"Formatting manual page..."' nroff -mandoc -Tascii /tmp/dman-$5/output if ! { printenv PAGER } goto more-lm >/dev/null printenv PAGER | \ sed 's!.*!exec & '/tmp/dman-$5/output! | osh goto quit : more-lm more -s /tmp/dman-$5/output ; goto quit : error-section if X$0 != X-s1 exit rm -r /tmp/dman-$5 perror dman \ '"No entry for "'$4'" in section "'$3'" of the manual."' exit : quit rm -r /tmp/dman-$5