fix manual n1256 (para, notes)
[c-standard.git] / tohtml.pre.sh
blob75e4e7d57b9e5ed17eb0e846a858bd2f7aebc2c8
1 #!/bin/sh
3 export LC_ALL=C
4 sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g' | awk '
5 BEGIN {
6 getline
7 print "<html><head><title>" $0 "</title></head><body><pre>"
8 print
10 while (getline == 1) {
11 if ($0 ~ /^Contents/)
12 break
13 print
15 print "<a name=\"Contents\" href=\"#Contents\">Contents</a>"
17 while (getline == 1) {
18 id = $1
19 if (id ~ /Annex/)
20 id = $2
21 if (id ~ /^([1-9A-Z]|Index|Foreword|Introduction|Bibliography)/) {
22 if (match($0, /&lt;[a-zA-Z0-9_]*\.h&gt;/)) {
23 h=substr($0,RSTART,RLENGTH)
24 if (!(h in header))
25 header[h] = id
27 if (id ~ /\.$/)
28 id = substr(id,1,length(id)-1)
29 s = "<a href=\"#" id "\">" $0
30 if ($(NF-1) == ".")
31 print s "</a>"
32 else{
33 print s
34 getline
35 print $0 "</a>"
37 if (id == "Index")
38 break
39 } else
40 print
42 note = 1
45 !seenindex && /^ *([1-9A-Z]\.|Annex|Index|Foreword|Introduction|Bibliography)/ {
46 id = $1
47 if (id ~ /Annex/)
48 id = $2
49 if (($0 ~ /^ [1-9]\./ || id ~ /^([A-Z]|[1-9A-Z]\.[1-9][0-9.]*|Index|Foreword|Introduction|Bibliography)$/) &&
50 (NF==1 || $2 ~ /^[A-Zv]/) &&
51 ($0 !~ /^ *[0-9.]+[^0-9]$/)) {
52 if (id ~ /\.$/)
53 id = substr(id,1,length(id)-1)
54 print "<a name=\"" id "\" href=\"#" id "\"><b>" $0 "</b></a>"
55 if (id == "Index")
56 seenindex=1
57 next
61 /^\[page / {
62 p = substr($2,1,length($2)-1)
63 print "[<a name=\"p" p "\" href=\"#p" p "\">page " p "</a>] (<a href=\"#Contents\">Contents</a>)"
64 next
67 /^ *(Syntax|Semantics|Description|Constraints|Synopsis|Returns)$/ {
68 print "<b>" $0 "</b>"
69 next
73 s = $0
74 p = ""
75 if (seenindex)
76 r = "[ (][A-Z1-9][0-9.]*"
77 else
78 r = "[ (][A-Z1-9]\\.[0-9.]*[0-9]"
79 while (match(s, r)) {
80 p = p substr(s,1,RSTART)
81 m = substr(s,RSTART+1,RLENGTH-1)
82 if (m ~ /\.0$/ || m ~ /[4-9][0-9]/ || m ~ /[0-3][0-9][0-9]/ || substr(s,RSTART+RLENGTH,1) ~ /[a-zA-Z\-]/)
83 p = p m
84 else
85 p = p "<a href=\"#" m "\">" m "</a>"
86 s = substr(s,RSTART+RLENGTH)
88 s = p s
89 p = ""
90 while (match(s, /[Aa]nnex [A-Z]/)) {
91 p = p substr(s,1,RSTART-1)
92 m = substr(s,RSTART,RLENGTH)
93 p = p "<a href=\"#" substr(m,RLENGTH,1) "\">" m "</a>"
94 s = substr(s,RSTART+RLENGTH)
96 s = p s
97 p = ""
98 while (match(s, /&lt;[a-zA-Z0-9_]*\.h&gt;/)) {
99 p = p substr(s,1,RSTART-1)
100 m = substr(s,RSTART,RLENGTH)
101 if (m in header)
102 p = p "<a href=\"#" header[m] "\">" m "</a>"
103 else
104 p = p m
105 s = substr(s,RSTART+RLENGTH)
107 s = p s
108 p = ""
109 while (match(s, note "\\)")) {
110 if (note==1 && s !~ /\.1\)/)
111 break
112 p = p substr(s,1,RSTART-1)
113 p = p "<sup><a href=\"#note" note "\"><b>" note ")</b></a></sup>"
114 note++
115 s = substr(s,RSTART+RLENGTH)
117 s = p s
118 if (s ~ /^ *[1-9][0-9]*\) /) {
119 sub(/\)/,"",s)
120 sub(/[0-9]+/,"<sup><a name=\"note&\" href=\"#note&\"><b>&)</b></a></sup>",s)
122 print s
125 END { print "</pre></body></html>" }'