diff options
Diffstat (limited to 'mantools/mansect')
-rwxr-xr-x | mantools/mansect | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/mantools/mansect b/mantools/mansect new file mode 100755 index 0000000..60262be --- /dev/null +++ b/mantools/mansect @@ -0,0 +1,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 +#-- |