xref: /netbsd-src/share/man/man0/tocrc (revision 3cf0dd87799edd2419a4c674fc7a1248df86ade7)
1d5172fe0Smrg#!/bin/sh -
2d5172fe0Smrg#
3*3cf0dd87Ssnj#	$NetBSD: tocrc,v 1.4 2004/03/31 02:10:00 snj Exp $
43fe138c1Sperry#
5d5172fe0Smrg# Copyright (c) 1993
6d5172fe0Smrg#	The Regents of the University of California.  All rights reserved.
7d5172fe0Smrg#
8d5172fe0Smrg# Redistribution and use in source and binary forms, with or without
9d5172fe0Smrg# modification, are permitted provided that the following conditions
10d5172fe0Smrg# are met:
11d5172fe0Smrg# 1. Redistributions of source code must retain the above copyright
12d5172fe0Smrg#    notice, this list of conditions and the following disclaimer.
13d5172fe0Smrg# 2. Redistributions in binary form must reproduce the above copyright
14d5172fe0Smrg#    notice, this list of conditions and the following disclaimer in the
15d5172fe0Smrg#    documentation and/or other materials provided with the distribution.
16d5172fe0Smrg# 3. All advertising materials mentioning features or use of this software
17d5172fe0Smrg#    must display the following acknowledgement:
18d5172fe0Smrg#	This product includes software developed by the University of
19d5172fe0Smrg#	California, Berkeley and its contributors.
20d5172fe0Smrg# 4. Neither the name of the University nor the names of its contributors
21d5172fe0Smrg#    may be used to endorse or promote products derived from this software
22d5172fe0Smrg#    without specific prior written permission.
23d5172fe0Smrg#
24d5172fe0Smrg# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25d5172fe0Smrg# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26d5172fe0Smrg# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27d5172fe0Smrg# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28d5172fe0Smrg# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29d5172fe0Smrg# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30d5172fe0Smrg# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31d5172fe0Smrg# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32d5172fe0Smrg# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33d5172fe0Smrg# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34d5172fe0Smrg# SUCH DAMAGE.
35d5172fe0Smrg#
36d5172fe0Smrg#       @(#)tocrc	8.2 (Berkeley) 5/5/94
37d5172fe0Smrg#
38d5172fe0Smrgtmp=/tmp/toc$$
39d5172fe0Smrgtrap "rm $tmp ; exit" 2 3 15
40d5172fe0Smrg:   tocx files for all sections and everything else
41d5172fe0Smrg
42d5172fe0Smrgif [ ! -f tocx8 ]; then
43d5172fe0Smrg	for x in 1 2 3 4 5 6 7 8; do
44d5172fe0Smrg		/usr/libexec/getNAME -t `cat man$x` |
45d5172fe0Smrg			sed \
46d5172fe0Smrg				-e 's/.s-2//g' \
47d5172fe0Smrg				-e 's/.s-1//g' \
48d5172fe0Smrg				-e 's/.s0//g' \
49d5172fe0Smrg				-e 's/.s+1//g' \
50d5172fe0Smrg				-e 's/  *.-  */: /' \
51d5172fe0Smrg				-e 's/ *$/./' \
52d5172fe0Smrg				-e 's/.TH.*	//' \
53d5172fe0Smrg				-e 's/@g@//' \
54d5172fe0Smrg				-e 's/@G@//' \
55d5172fe0Smrg			> tocx$x
56d5172fe0Smrg	done
57d5172fe0Smrgfi
58d5172fe0Smrg:   permuted index and toc files
59d5172fe0Smrg
60d5172fe0Smrgcat tocx* cshcmd > /tmp/cattoc
61d5172fe0Smrg
62*3cf0dd87Ssnj# If this fails, try gptx from GNU coreutils (pkgsrc/sysutils/coreutils)
63d5172fe0Smrgptx -r -t -b break -f -w 108 -i ignore /tmp/cattoc ptxx
64d5172fe0Smrg
65d5172fe0Smrgfor x in 1 2 3 4 5 6 7 8; do
66d5172fe0Smrg	grep '^intro' <tocx$x >$tmp
67d5172fe0Smrg	sed \
68d5172fe0Smrg		-e '2,${' \
69d5172fe0Smrg		-e '/^intro/d' \
70d5172fe0Smrg		-e '}' \
71d5172fe0Smrg		-e 's/ .*://' \
72d5172fe0Smrg		-e 's/.$//' \
73d5172fe0Smrg		-e 's/([^)]*) /" "/' \
74d5172fe0Smrg		-e 's/.*/.xx "&"/' \
75d5172fe0Smrg		-e '/""/d' \
76d5172fe0Smrg		$tmp tocx$x \
77d5172fe0Smrg	>toc$x
78d5172fe0Smrgdone
79d5172fe0Smrgexit
80