manual fix of section c99 6
[c-standard.git] / ann2html.sh
blobecb0411ebda6c2d67e54b4f8dfd4f4a5ce686d2d
1 #!/bin/sh
3 export LC_ALL=C
4 awk '
5 BEGIN {
6 noteid = 1
7 sid = 1
8 ss[sid] = "<pre>"
12 gsub(/\&/, "\\&amp;")
13 gsub(/</, "\\&lt;")
14 gsub(/>/, "\\&gt;")
17 !title && /^[^@]/ {
18 title = $0
19 gsub(/ +/, " ", title)
20 gsub(/Committee Draft --/, "", title)
23 /^@sect Contents/ {
24 ss[sid] = ss[sid] "</pre>\n"
25 seencontents = 1
26 level = 0
29 seencontents && !seenfore && /^[^@]/ {
30 id = $1
31 if (id ~ /Annex/)
32 id = $2
33 sub(/\.$/, "", id)
35 s = $0
36 if (!sub(/ +\. .*/, "", s)) {
37 getline
38 sub(/^ */, " ")
39 s = s $0
40 sub(/ +\. .*/, "", s)
43 if (match(s, /&lt;[a-zA-Z0-9_]*\.h&gt;/)) {
44 h = substr($0,RSTART,RLENGTH)
45 if (!(h in header))
46 header[h] = id
49 s = "<a href=\"#" id "\">" s "</a>\n"
51 s = "<li>" s
52 n = split(id, a, /\./)
53 while (n > level) {
54 s = "<ul>\n" s
55 level++
57 while (n < level) {
58 s = "</ul>\n" s
59 level--
61 ss[sid] = ss[sid] s
62 next
65 /^@sect Foreword/ {
66 while (level--)
67 ss[sid] = ss[sid] "</ul>\n"
68 seenfore = 1
71 /^@sect Index/ {
72 seenindex = 1
75 /^@title/ {
76 if (!seencontents) {
77 ss[sid] = ss[sid] "</pre>\n"
79 sid++
80 getline
81 ss[sid] = ss[sid] "<h1>" $0 "</h1>\n"
82 if (!seencontents) {
83 ss[sid] = ss[sid] "<pre>\n"
85 next
88 /^@sect 3\./ {
89 markdef = 1
92 /^@sect/ {
93 sid++
94 slevel = split($2,a,/\./)+1
95 if (slevel > 5)
96 slevel = 5
97 sect = $2
98 getline
99 # todo hX, back to top
100 ss[sid] = sprintf("<h%s><a name=\"%s\" href=\"#%s\">%s</a></h%s>\n", slevel, sect, sect, $0, slevel)
101 if ($0 == "Index")
102 ss[sid] = ss[sid] "<pre>\n"
103 next
106 /^@ul/ {
107 ss[sid] = ss[sid] "<ul>\n"
108 next
110 /^@end ul/ {
111 ss[sid] = ss[sid] "</ul>\n"
112 next
114 /^@ol/ {
115 ss[sid] = ss[sid] "<ol>\n"
116 next
118 /^@end ol/ {
119 ss[sid] = ss[sid] "</ol>\n"
120 next
123 /^@li/ {
124 ss[sid] = ss[sid] "<li>"
125 next
128 /^@pre/ {
129 pre = "<pre>"
130 next
133 /^@end pre/ {
134 if (!pre)
135 next
136 pre = pre "</pre>\n"
137 if (nn)
138 note[nn] = note[nn] "\n" pre
139 else
140 ss[sid] = ss[sid] pre
141 pre = ""
142 next
145 /^@note/ {
146 nn = $2+0
147 note[nn] = ""
148 next
151 /^@page/ {
152 nn = 0
153 p = $2
154 getline
155 ss[sid] = ss[sid] "<!--page " p " -->\n"
156 next
159 /^@para/ {
160 ss[sid] = ss[sid] "<p><!--para " $2 " -->\n"
161 next
164 /^ *(Syntax|Semantics|Description|Constraints|Synopsis|Returns|Recommended practice|Implementation limits)$/ {
165 ss[sid] = ss[sid] "<h6>" $0 "</h6>\n"
166 next
169 !seenfore {
170 ss[sid] = ss[sid] $0 "\n"
171 next
175 s = $0
176 p = ""
177 if (seenindex)
178 r = " [A-Z1-9][0-9.]*"
179 else
180 r = "[ ([][A-Z1-9]\\.[0-9.]*[0-9]"
181 # hack
182 s = " " s
183 while (match(s, r)) {
184 p = p substr(s,1,RSTART)
185 m = substr(s,RSTART+1,RLENGTH-1)
186 if (m ~ /\.0$/ || m ~ /[4-9][0-9]/ || m ~ /[0-3][0-9][0-9]/ ||
187 substr(s,RSTART+RLENGTH,1) ~ /[a-zA-Z_\-]/)
188 p = p m
189 else
190 p = p "<a href=\"#" m "\">" m "</a>"
191 s = substr(s,RSTART+RLENGTH)
193 s = p s
194 p = ""
195 while (match(s, /[Aa]nnex [A-Z]/)) {
196 p = p substr(s,1,RSTART-1)
197 m = substr(s,RSTART,RLENGTH)
198 p = p "<a href=\"#" substr(m,RLENGTH,1) "\">" m "</a>"
199 s = substr(s,RSTART+RLENGTH)
201 s = p s
202 p = ""
203 while (match(s, /&lt;[a-zA-Z0-9_]*\.h&gt;/)) {
204 p = p substr(s,1,RSTART-1)
205 m = substr(s,RSTART,RLENGTH)
206 if (m in header)
207 p = p "<a href=\"#" header[m] "\">" m "</a>"
208 else
209 p = p m
210 s = substr(s,RSTART+RLENGTH)
212 s = p s
213 p = ""
214 while (match(s, noteid "\\)")) {
215 if (noteid==1 && s !~ /\.1\)/)
216 break
217 p = p substr(s,1,RSTART-1)
218 p = p "<sup><a href=\"#note" noteid "\"><b>" noteid ")</b></a></sup>"
219 snote[sid] = snote[sid] " " noteid
220 noteid++
221 s = substr(s,RSTART+RLENGTH)
223 s = p s
224 sub(/^ *Forward references/, "<p><b>&</b>", s)
225 if (markdef) {
226 s = "<b>" s "</b><br>"
227 markdef = 0
229 if (pre)
230 pre = pre "\n" s
231 else if (nn)
232 note[nn] = note[nn] s "\n"
233 else
234 ss[sid] = ss[sid] s "\n"
237 END {
238 ss[sid] = ss[sid] "</pre>"
240 print "<html><head><title>" title "</title></head><body>"
242 for (i = 1; i <= sid; i++) {
243 print ss[i]
244 n = split(snote[i],a)
245 if (n > 0) {
246 s = "<h6>footnotes</h6>\n"
247 for (j = 1; j <= n; j++) {
248 s = s "<p><small><a name=\"note" a[j] "\" href=\"#note" a[j] "\">" a[j] ")</a>" note[a[j]+0] "</small>\n"
250 print s
254 print "</body></html>"