xref: /netbsd-src/external/ibm-public/postfix/dist/mantools/mansect (revision 41fbaed053f8fbfdf9d2a4ee0a7386a3c83f8505)
1*41fbaed0Stron#!/bin/sh
2*41fbaed0Stron
3*41fbaed0Stron# mansect - extract manual chapter number from source comment
4*41fbaed0Stron
5*41fbaed0Stron# @(#) mansect.sh 1.2 11/4/89 15:56:37
6*41fbaed0Stron
7*41fbaed0StronLANG=
8*41fbaed0Stron
9*41fbaed0Stron: process arguments
10*41fbaed0Stron
11*41fbaed0Stronwhile :
12*41fbaed0Strondo
13*41fbaed0Stron    case $1 in
14*41fbaed0Stron [0-9]) SECT=$1;;
15*41fbaed0Stron     -) LANG=$1; B='[#:]';;
16*41fbaed0Stron    -a) LANG=$1; B='#';;
17*41fbaed0Stron    -c) LANG=$1; B='\/\*';;
18*41fbaed0Stron    -f) LANG=$1; B='[Cc]';;
19*41fbaed0Stron    -m) LANG=$1; B='#';;
20*41fbaed0Stron -n|-t) LANG=$1; B='\\"';;
21*41fbaed0Stron    -p) LANG=$1; B='{';;
22*41fbaed0Stron    -r) LANG=$1; B='#';;
23*41fbaed0Stron    -C) LANG=$1; B=$2; shift;;
24*41fbaed0Stron    -*) ERROR="unknown option: $1"; break;;
25*41fbaed0Stron    "") ERROR="missing file argument"; break;;
26*41fbaed0Stron     *) break;;
27*41fbaed0Stron    esac
28*41fbaed0Stron    shift
29*41fbaed0Strondone
30*41fbaed0Stron
31*41fbaed0Stron# check error status
32*41fbaed0Stron
33*41fbaed0Stroncase $ERROR in
34*41fbaed0Stron"") ;;
35*41fbaed0Stron *) echo "$0: $ERROR" 1>&2
36*41fbaed0Stron    echo "usage: $0 [-|-a|-c|-f|-m|-n|-p|-t|-r|-C] file(s)" 1>&2; exit 1;;
37*41fbaed0Stronesac
38*41fbaed0Stron
39*41fbaed0Stron# set up for file suffix processing
40*41fbaed0Stron
41*41fbaed0Stroncase $LANG in
42*41fbaed0Stron"") sh='[:#]';	r='#';	rh=$r;	awk='#'; mk='#';
43*41fbaed0Stron    c='\/\*';	d=$c;	h=$c;	y=$c;	l=$c;
44*41fbaed0Stron    f='[Cc]';	fh=$f;	p='{';	ph=$p;
45*41fbaed0Stron    ms='\\"';	nr=$ms;	mn=$ms;	man=$ms;
46*41fbaed0Stronesac
47*41fbaed0Stron
48*41fbaed0Stron# extract chapter number from file
49*41fbaed0Stron
50*41fbaed0Stronfor i
51*41fbaed0Strondo
52*41fbaed0Stron    case $LANG in
53*41fbaed0Stron    "") eval B\="\$`expr $i : '.*\.\([^.]*\)$'`"
54*41fbaed0Stron	test "$B" || { echo "$0: unknown suffix: '$i'; assuming c" 1>&2; B=$c; }
55*41fbaed0Stron    esac
56*41fbaed0Stron    sed -n '
57*41fbaed0Stron    /^'"$B"'++/,/^'"$B"'--/{
58*41fbaed0Stron	s/[ 	]*$//
59*41fbaed0Stron	/^'"$B"' NAME/{
60*41fbaed0Stron	    N
61*41fbaed0Stron	    s/^.*\n'"$B"'.*[ 	]\([0-9]\)[ 	]*$/\1/p
62*41fbaed0Stron	    q
63*41fbaed0Stron	}
64*41fbaed0Stron    }
65*41fbaed0Stron' $i
66*41fbaed0Strondone
67*41fbaed0Stron
68*41fbaed0Stronexit
69*41fbaed0Stron
70*41fbaed0Stron#++
71*41fbaed0Stron# NAME
72*41fbaed0Stron#	mansect 1
73*41fbaed0Stron# SUMMARY
74*41fbaed0Stron#	extract manual chapter number from comment
75*41fbaed0Stron# PACKAGE
76*41fbaed0Stron#	sdetools
77*41fbaed0Stron# SYNOPSIS
78*41fbaed0Stron#	mansect [-|-a|-c|-f|-m|-m|-n|-p|-t|-r|-C] file(s)
79*41fbaed0Stron# DESCRIPTION
80*41fbaed0Stron#	\fImansect\fR extracts the manual chapter number from
81*41fbaed0Stron#	source file comments in the style of \fInewsrc(1)\fR.
82*41fbaed0Stron#	Typically, \fImansect\fR is integrated with \fImake(1)\fR scripts.
83*41fbaed0Stron#
84*41fbaed0Stron#	Source files are processed in the indicated order; if no
85*41fbaed0Stron#	files are specified the command produces no output.
86*41fbaed0Stron#
87*41fbaed0Stron#	The source file language can be specified through a command-line
88*41fbaed0Stron#	option, or can be implied by the filename suffix.
89*41fbaed0Stron#	The expected start-of-comment symbol is shown in the last column.
90*41fbaed0Stron#
91*41fbaed0Stron# .nf
92*41fbaed0Stron# .ft C
93*41fbaed0Stron	option	suffix		language	comment
94*41fbaed0Stron
95*41fbaed0Stron	-	.sh		shell		[:#]
96*41fbaed0Stron	-a	.awk		awk		#
97*41fbaed0Stron	-c	.c .h .l .y	c lex yacc	/*
98*41fbaed0Stron	-f	.f .fh		fortran		[Cc]
99*41fbaed0Stron	-m	.mk		make		#
100*41fbaed0Stron	-n	.man .mn .ms .nr nroff troff	\\"
101*41fbaed0Stron	-p	.p .ph		pascal		{
102*41fbaed0Stron	-r	.r .rh		ratfor		#
103*41fbaed0Stron	-C			any language	next argument
104*41fbaed0Stron# .ft
105*41fbaed0Stron# COMMANDS
106*41fbaed0Stron#	sh(1), sed(1)
107*41fbaed0Stron# SEE ALSO
108*41fbaed0Stron#	newsrc(1), xman(1)
109*41fbaed0Stron#	The earlier commands new(1), mod(1), mkman(1) and dssman(1)
110*41fbaed0Stron#	by Ruud Zwart and Ben Noordzij (Erasmus University, Rotterdam)
111*41fbaed0Stron# DIAGNOSTICS
112*41fbaed0Stron#	The program complaints if an unknown language is specified
113*41fbaed0Stron#	of if the language cannot be deduced from the file suffix.
114*41fbaed0Stron# AUTHOR(S)
115*41fbaed0Stron#	W.Z. Venema
116*41fbaed0Stron#	Eindhoven University of Technology
117*41fbaed0Stron#	Department of Mathematics and Computer Science
118*41fbaed0Stron#	Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
119*41fbaed0Stron# CREATION DATE
120*41fbaed0Stron#	Sun Feb 15 21:40:28 GMT+1:00 1987
121*41fbaed0Stron# LAST MODIFICATION
122*41fbaed0Stron#	11/4/89 15:56:37
123*41fbaed0Stron# VERSION/RELEASE
124*41fbaed0Stron#	1.2
125*41fbaed0Stron#--
126