fix html escape
[c-standard] / ann2html.sh
index 509e3a2..9acba62 100755 (executable)
@@ -1,7 +1,5 @@
 #!/bin/sh
 
-# todo: <sub>opt</sub>
-
 export LC_ALL=C
 awk '
 BEGIN {
@@ -10,12 +8,16 @@ BEGIN {
        ss[sid] = "<pre>"
 }
 
-{
+function esc() {
        gsub(/\&/, "\\&amp;")
        gsub(/</, "\\&lt;")
        gsub(/>/, "\\&gt;")
 }
 
+{
+       esc()
+}
+
 !title && /^[^@]/ {
        title = $0
        gsub(/  +/, "  ", title)
@@ -37,6 +39,7 @@ seencontents && !seenfore && /^[^@]/ {
        s = $0
        if (!sub(/ +\. .*/, "", s)) {
                getline
+               esc()
                sub(/^ */, " ")
                s = s $0
                sub(/ +\. .*/, "", s)
@@ -80,6 +83,7 @@ seencontents && !seenfore && /^[^@]/ {
        }
        sid++
        getline
+       esc()
        ss[sid] = ss[sid] "<h1>" $0 "</h1>\n"
        if (!seencontents) {
                ss[sid] = ss[sid] "<pre>\n"
@@ -98,6 +102,7 @@ seencontents && !seenfore && /^[^@]/ {
                slevel = 5
        sect = $2
        getline
+       esc()
        # todo hX, back to top
        ss[sid] = sprintf("<h%s><a name=\"%s\" href=\"#%s\">%s</a></h%s>\n", slevel, sect, sect, $0, slevel)
        if ($0 == "Index")
@@ -135,7 +140,7 @@ seencontents && !seenfore && /^[^@]/ {
 /^@end pre/ {
        if (!pre)
                next
-       pre = pre "</pre>\n"
+       pre = pre "\n</pre>\n"
        if (nn)
                note[nn] = note[nn] "\n" pre
        else
@@ -164,7 +169,7 @@ seencontents && !seenfore && /^[^@]/ {
 }
 
 /^ ?(Syntax|Semantics|Description|Constraints|Synopsis|Returns|Recommended practice|Implementation limits|Environmental limits)$/ {
-       ss[sid] = ss[sid] "<h6>" $0 "</h6>\n"
+       ss[sid] = ss[sid] "<p><b>" $0 "</b>\n"
        next
 }
 
@@ -213,6 +218,11 @@ seencontents && !seenfore && /^[^@]/ {
        }
        s = p s
        p = ""
+       # TODO: false positives..
+       while (match(s, /[a-z]opt[ )"]/))
+               s = substr(s,1,RSTART) "<sub>opt</sub>" substr(s,RSTART+RLENGTH-1)
+       if (match(s, /[a-z]opt$/))
+               s = substr(s,1,RSTART) "<sub>opt</sub>"
        for (;;) {
                while (match(s, noteid-1 "\\)")) {
                        p = p substr(s,1,RSTART-1)
@@ -252,7 +262,7 @@ END {
                print ss[i]
                n = split(snote[i],a)
                if (n > 0) {
-                       s = "<h6>footnotes</h6>\n"
+                       s = "<p><b>Footnotes</b>\n"
                        for (j = 1; j <= n; j++) {
                                s = s "<p><small><a name=\"note" a[j] "\" href=\"#note" a[j] "\">" a[j] ")</a>" note[a[j]+0] "</small>\n"
                        }