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