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