Initial import from FreeBSD RELENG_4:
[dragonfly.git] / gnu / usr.bin / ptx / examples / luke / xxroff.sh
1 #!/bin/sh
2 #
3 # Author: Luke Kendall
4 #
5 MYNAME=`basename $0`
6 usage="usage: $MYNAME [man-directory]
7         (generates permuted index of -man files in directory)"
8 md=/usr/man
9 #
10 if [ $# = 0 ]
11 then
12     echo "$MYNAME: no man directory specified: assuming $md"
13 elif [ $# != 1 ]
14 then
15     echo "$usage"
16     exit 1
17 elif [ -d $1 ]
18 then
19     md="$1"
20 else
21     echo "$usage"
22     exit 1
23 fi
24 echo "Permuted index of $md:"
25 out=ptx.tr
26 # ------ clumsy permuted index macros (replaced by stuff below) ------------
27 cat <<'EOF' > $out
28 .pn 1
29 .de xx
30 \\$1 \\$2  \\fB\\$3\\fR  \\$4\ 1  \\s-1\\$5\\s0
31 ..
32 .pl 10i
33 .de NP
34 .ev 1
35 .ft 1
36 .ps 10
37 .sp 0.75c
38 .tl '\s-2\\fIpermuted index\\fP\s0'\- \\n% \-'\s-2\\fIpermuted index\\fP\s0'
39 .pn +1
40 .bp
41 .ev
42 ..
43 .wh 9i NP
44 .nf
45 .na
46 .ta 6.5i-1.1iR 6.5iR 6.51iR 6.52R
47 .ll 6.0i
48 .po 0i
49 .sp 0.25i
50 '\"
51 EOF
52 # ------  -------  -------  -------  -------  -------
53 # ------ alternate permuted index macros  (from net) ------------
54 cat <<'EOF' > $out
55 .pl 10i
56 .de NP
57 .ev 1
58 .ft 1
59 .ps 10
60 .sp 0.75c
61 .tl '\s-2\\fIpermuted index\\fP\s0'\- \\n% \-'\s-2\\fIpermuted index\\fP\s0'
62 .pn +1
63 .bp
64 .ev
65 ..
66 .wh 9i NP
67 .po 0.5i
68 .sp 0.25i
69 .tr ~               \" tildes will translate to blanks
70 '\".ll 80              \" line length of output
71 .ll 6.0i            \" line length of output
72 .nf                 \" must be in no-fill mode
73 .nr )r \n(.lu-10n   \" set position of reference in line (10 less than length)
74 .nr )k \n()ru/2u    \" set position of keyword (approx. centered)
75 .ds s2 ~~~          \" this is the center gap -- 3 spaces
76 .de xx              \"definition of xx macro
77 .ds s1\"            \" initialise to null string
78 .if \w@\\$2@ .ds s1 ~\"       \"set to single blank if there is second arg
79 .ds s3\"                      \" initialise to null string
80 .if \w@\\$4@ .ds s3 ~\"       \"set to single blank if there is second arg
81 .ds s4 ~\"                    \" set to single blank
82 .ds s5 ~\"                    \" set to single blank
83 .ds y \\*(s4\a\\*(s5\"        \" blank, leader, blank
84 .ta \\n()ru-\w@\\*(s5@u       \" set tab just to left of ref
85 \h@\\n()ku-\w@\\$1\\*(s1\\$2\\*(s2@u@\\$1\\*(s1\\$2\\*(s2\\$3\\*(s3\\$4\\*y\\$5
86 ..
87  ~
88 EOF
89 # ------  -------  -------  -------  -------  -------
90 find $md -type f -name "*.[1-8nl]*" -print |
91 while read f
92 do
93     man=`basename $f`
94     man=`expr "$man" : "\(.*\)\.[^\.]*"`
95 echo $man:
96     #
97     # Use 1st non-"." and non-"'" started line as input to ptx (this
98     # should be the synopsis after the `.SH NAME');
99     # strip any "\-" from it (a silly sort key for ptx to avoid);
100     # insert a leading man page name for the -r option to find
101     #
102     sed -n '/^[^.]/s/\\-//g;/^[^.]/p;/^[^.]/q' $f | sed "s/^/($man) /"
103 done  | ptx -t -f -r  >> $out
104 #
105 # Turn the troff'able permuted index file into PostScript
106 #
107 psroff -t -rL10i $out > ptx.ps
108 echo "$out and ptx.ps produced from man directory $md."