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