summaryrefslogtreecommitdiffstats
path: root/mantools/mansect
blob: 60262be593505a805d935a744d71e0b66262adbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh

# mansect - extract manual chapter number from source comment

# @(#) mansect.sh 1.2 11/4/89 15:56:37

LANG=

: process arguments

while :
do
    case $1 in
 [0-9]) SECT=$1;;
     -) LANG=$1; B='[#:]';;
    -a) LANG=$1; B='#';;
    -c) LANG=$1; B='\/\*';;
    -f) LANG=$1; B='[Cc]';;
    -m) LANG=$1; B='#';;
 -n|-t) LANG=$1; B='\\"';;
    -p) LANG=$1; B='{';;
    -r) LANG=$1; B='#';;
    -C) LANG=$1; B=$2; shift;;
    -*) ERROR="unknown option: $1"; break;;
    "") ERROR="missing file argument"; break;;
     *) break;;
    esac
    shift
done

# check error status

case $ERROR in
"") ;;
 *) echo "$0: $ERROR" 1>&2
    echo "usage: $0 [-|-a|-c|-f|-m|-n|-p|-t|-r|-C] file(s)" 1>&2; exit 1;;
esac

# set up for file suffix processing

case $LANG in
"") sh='[:#]';	r='#';	rh=$r;	awk='#'; mk='#';
    c='\/\*';	d=$c;	h=$c;	y=$c;	l=$c;
    f='[Cc]';	fh=$f;	p='{';	ph=$p;
    ms='\\"';	nr=$ms;	mn=$ms;	man=$ms;
esac

# extract chapter number from file

for i
do
    case $LANG in
    "") eval B\="\$`expr $i : '.*\.\([^.]*\)$'`"
	test "$B" || { echo "$0: unknown suffix: '$i'; assuming c" 1>&2; B=$c; }
    esac
    sed -n '
    /^'"$B"'++/,/^'"$B"'--/{
	s/[ 	]*$//
	/^'"$B"' NAME/{
	    N
	    s/^.*\n'"$B"'.*[ 	]\([0-9]\)[ 	]*$/\1/p
	    q
	}
    }
' $i
done

exit

#++
# NAME
#	mansect 1
# SUMMARY
#	extract manual chapter number from comment
# PACKAGE
#	sdetools
# SYNOPSIS
#	mansect [-|-a|-c|-f|-m|-m|-n|-p|-t|-r|-C] file(s)
# DESCRIPTION
#	\fImansect\fR extracts the manual chapter number from 
#	source file comments in the style of \fInewsrc(1)\fR.
#	Typically, \fImansect\fR is integrated with \fImake(1)\fR scripts.
#
#	Source files are processed in the indicated order; if no
#	files are specified the command produces no output.
#
#	The source file language can be specified through a command-line
#	option, or can be implied by the filename suffix.
#	The expected start-of-comment symbol is shown in the last column.
#
# .nf
# .ft C
	option	suffix		language	comment

	-	.sh		shell		[:#]
	-a	.awk		awk		#
	-c	.c .h .l .y	c lex yacc	/*
	-f	.f .fh		fortran		[Cc]
	-m	.mk		make		#
	-n	.man .mn .ms .nr nroff troff	\\"
	-p	.p .ph		pascal		{
	-r	.r .rh		ratfor		#
	-C			any language	next argument
# .ft
# COMMANDS
#	sh(1), sed(1)
# SEE ALSO
#	newsrc(1), xman(1)
#	The earlier commands new(1), mod(1), mkman(1) and dssman(1)
#	by Ruud Zwart and Ben Noordzij (Erasmus University, Rotterdam) 
# DIAGNOSTICS
#	The program complaints if an unknown language is specified
#	of if the language cannot be deduced from the file suffix.
# AUTHOR(S)
#	W.Z. Venema
#	Eindhoven University of Technology
#	Department of Mathematics and Computer Science
#	Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
# CREATION DATE
#	Sun Feb 15 21:40:28 GMT+1:00 1987
# LAST MODIFICATION
#	11/4/89 15:56:37
# VERSION/RELEASE
#	1.2
#--