xref: /netbsd/share/man/tools/tocrc (revision 6550d01e)
1MANDIR=/usr/man
2TMPDIR=/usr/man/tmp
3TOOLS=$MANDIR/tools
4
5trap "rm $TMPDIR/tmp.$$ ; exit" 2 3 15
6
7P=108
8p=""
9if test "$1" = "-p"
10then
11	P=65
12	p=-p
13	shift
14fi
15
16if test $# -eq 0
17then
18	echo "tocrc: no argument"
19	exit
20fi
21
22if test $# -eq 2
23then
24	: create toc input file for one section only
25
26	> $TMPDIR/tocx$1
27	for file in $MANDIR/man$1/*.$1*
28	do
29		if test ! -s $file
30		then
31			continue
32		fi
33		so=`line < $file | sed "s/ .*//"`
34		if test "$so" = ".so"
35		then
36			continue
37		fi
38		ed - $file > $TMPDIR/tmp.$$ <<!
39			H
40			/^\.TH/p
41			q
42!
43		loc=`cat $TMPDIR/tmp.$$ | sed "s/.*local.*/local/"`
44		if test "$loc" = "local"
45		then
46			continue
47		fi
48		name=`basename $file`
49		name=`echo $name | sed "s/\.\(.\{1,2\}\)\$/(\1)/"`
50		ed - $file > $TMPDIR/tmp.$$ <<!
51			/^.SH NAME/+p
52			q
53!
54		desc=`line < $TMPDIR/tmp.$$`
55		desc=`echo $desc | sed -e "s/.s-1//g" -e "s/.s0//g"  -e "s/.s+1//g"   -e "s/ .- /: /"  -e "s/^/$name /"  -e "s/$/./"`
56		if test -n "$desc"
57		then
58			echo $desc >> $TMPDIR/tocx$1
59		fi
60		rm -f $TMPDIR/tmp.$$
61	done
62else case $1 in
63	all )
64		:   tocx files for all sections and everything else
65
66		for x in 1 2 3 4 5 6 7 8
67		do
68			$0 $p $x $x
69		done
70		$0 $p t
71		;;
72	t )
73		:   permuted index and toc files
74
75		if test ! -f $TMPDIR/tocx1
76		then
77			echo "tocrc: some tocx? files missing"
78			exit
79		fi
80		cat $TMPDIR/tocx? > $TMPDIR/cattoc
81		ed - $TMPDIR/cattoc <<!
82			H
83			g/(1c)/s//(1C)/
84			g/(1m)/s//(1M)/
85			g/(1g)/s//(1G)/
86			g/(3c)/s//(3C)/
87			g/(3m)/s//(3M)/
88			g/(3s)/s//(3S)/
89			g/(3x)/s//(3X)/
90			g/"\."/d
91			w
92			q
93!
94		ptx -r -t -b $TOOLS/break -f -w $P -i $TOOLS/ignore $TMPDIR/cattoc $MANDIR/man0/ptxx
95		for x in 1 2 3 4 5 6 7 8
96		do
97			ed - $TMPDIR/tocx$x << !
98			H
99				/^intro/m0
100				1,\$s/ .*://
101				1,\$s/.$//
102				1,\$s/([1-8][a-z]\{0,1\}) /" "/
103				1,\$s/.*/.xx "&"/
104				g/""/d
105				w $MANDIR/man0/toc$x
106				q
107!
108		done
109		;;
110	* )
111		$0 $p $1 $1
112		;;
113	esac
114fi
115