1#!/bin/sh 2 3# srctoman - extract manual page from source file comment 4 5# @(#) srctoman.sh 1.2 11/4/89 15:56:22 6 7LANG= 8 9# process arguments 10 11while : 12do 13 case $1 in 14 [0-9]) SECT=$1;; 15 -) LANG=$1; B='[#:]';; 16 -awk) LANG=$1; B='#';; 17 -c) LANG=$1; B='\/\*';; 18 -f) LANG=$1; B='[Cc]';; 19 -mk) 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 [-|-awk|-c|-f|-mk|-n|-p|-t|-r|-C] [section] 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='\/\*'; 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 comments 49 50for i in $* 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 ' 57 /^'"$B"'++/,/^'"$B"'--/!d 58 /^'"$B"'++/d 59 /^'"$B"'--/d 60 s/[ ]*$// 61 /^'"$B"' \([A-Z]\)/{ 62 s//\1/ 63 /^NAME[ ]*$/{ 64 N 65 s/^.*\n'"$B"'[ ]*// 66 h 67 y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/ 68 s/^.*$/.TH & '"$SECT"'\ 69.ad\ 70.fi\ 71.SH NAME/ 72 p 73 g 74 s/[ ][ ]*[0-9][ ]*$// 75 a\ 76\\- 77 p 78 d 79 } 80 /^SUMMARY/d 81 /^DESCRIPTION/s//.SH &\ 82.ad\ 83.fi/ 84 /^BUGS/s//.SH &\ 85.ad\ 86.fi/ 87 /^DIAGNOSTICS/s//.SH &\ 88.ad\ 89.fi/ 90 /^[A-Z][A-Z][A-Z][^a-z]*$/s//.SH "&"\ 91.na\ 92.nf/ 93 p 94 d 95 } 96 s/^'"$B"' *// 97 s/^ // 98 s/^[ ]*$// 99 /^\\"/d 100' $i 101done | expand 102 103exit 104 105#++ 106# NAME 107# srctoman 1 108# SUMMARY 109# extract manual page from source file comment 110# PACKAGE 111# sdetools 112# SYNOPSIS 113# srctoman [-|-awk|-c|-f|-mk|-m|-n|-p|-t|-r|-C] [section] file(s) 114# DESCRIPTION 115# \fIsrctoman\fR converts comments in various programming languages to 116# UNIX-style manual pages. 117# The command processes comments in the style of newsrc(1); 118# its standard output is suitable for formatting with nroff(1) or 119# troff(1) using the "-man" macro package. 120# Typically, srctoman is invoked from make(1) scripts. 121# 122# Source files are processed in the indicated order; if no 123# files are specified the command produces no output. 124# 125# The source file language can be specified through a command-line 126# option, or can be implied by the filename suffix. 127# The expected start-of-comment symbol is shown in the last column. 128# 129# .nf 130# .ft C 131 option language comment 132 133 - shell [:#] 134 -awk awk # 135 -c c /* 136 -f fortran [Cc] 137 -mk make # 138 -n nroff \\" 139 -p pascal { 140 -t troff \\" 141 -r ratfor # 142 -C any language next argument 143# 144 suffix language comment 145 146 .awk awk # 147 .c c /* 148 .f fortran [Cc] 149 .fh fortran [Cc] 150 .h c /* 151 .l lex /* 152 .man nroff,troff \\" 153 .mk make # 154 .me nroff,troff \\" 155 .ms nroff,troff \\" 156 .nr nroff,troff \\" 157 .p pascal { 158 .ph pascal { 159 .r ratfor # 160 .rh ratfor # 161 .sh shell [:#] 162 .y yacc /* 163# .ft 164# .PP 165# .fi 166# 167# The required format of comments is discussed below, where SOC 168# stands for the start-of-comment symbol of the language being used. 169# .IP o 170# Start of manual: SOC, followed by `++'. 171# .IP o 172# Section heading: SOC, blank, section name in upper case. 173# .IP o 174# All other text: SOC and subsequent blanks or tabs are removed. 175# Lines that do not start with SOC are left unchanged (useful for 176# inclusion of program text). 177# .IP o 178# End of manual: SOC, followed by `--'. 179# An end-of-comment may follow if the source file language requires this. 180# .PP 181# The following manual sections receive a special treatment: 182# NAME and SUMMARY should appear at the beginning and in 183# this order; DESCRIPTION, DIAGNOSTICS and BUGS will be 184# right-margin adjusted. 185# Other sections may be added freely without confusing srctoman. 186# COMMANDS 187# sh(1), sed(1), expand(1) 188# SEE ALSO 189# newsrc(1) 190# DIAGNOSTICS 191# The program complains if an unknown language is specified 192# of if the language cannot be deduced from the file suffix. 193# AUTHOR(S) 194# W.Z. Venema 195# Eindhoven University of Technology 196# Department of Mathematics and Computer Science 197# Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands 198# CREATION DATE 199# Fri Jan 17 22:59:27 MET 1986 200# STATUS 201# srctoman.sh 1.2 11/4/89 15:56:22 (draft) 202#-- 203