fix formula for logb in n1570.html
[c-standard] / tohtml.pre.sh
1 #!/bin/sh
2
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
9
10         while (getline == 1) {
11                 if ($0 ~ /^Contents/)
12                         break
13                 print
14         }
15         print "<a name=\"Contents\" href=\"#Contents\">Contents</a>"
16
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
26                         }
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>"
36                         }
37                         if (id == "Index")
38                                 break
39                 } else
40                         print
41         }
42         note = 1
43 }
44
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
58         }
59 }
60
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
65 }
66
67 /^ *(Syntax|Semantics|Description|Constraints|Synopsis|Returns)$/ {
68         print "<b>" $0 "</b>"
69         next
70 }
71
72 {
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)
87         }
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)
95         }
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)
106         }
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)
116         }
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)
121         }
122         print s
123 }
124
125 END { print "</pre></body></html>" }'