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