X-Git-Url: http://nsz.repo.hu/git/?p=c-standard;a=blobdiff_plain;f=ann2html.sh;h=f7edb9b77959ee31df1e072694467717959c3d8a;hp=7b3bcac9024068f673f8caabec38e907e4284aaf;hb=a195b77776bc262f52deca83fea5d60b1f7953e7;hpb=dd0127cddb03b6a5ed3079cb1f0dd57bd098c579 diff --git a/ann2html.sh b/ann2html.sh index 7b3bcac..f7edb9b 100755 --- a/ann2html.sh +++ b/ann2html.sh @@ -8,19 +8,68 @@ BEGIN { ss[sid] = "
"
 }
 
-{
+function esc() {
 	gsub(/\&/, "\\&")
 	gsub(//, "\\>")
 }
 
+{
+	esc()
+}
+
+!title && /^[^@]/ {
+	title = $0
+	gsub(/  +/, "  ", title)
+	gsub(/Committee Draft --/, "", title)
+}
+
 /^@sect Contents/ {
 	ss[sid] = ss[sid] "
\n" seencontents = 1 + level = 0 +} + +seencontents && !seenfore && /^[^@]/ { + id = $1 + if (id ~ /Annex/) + id = $2 + sub(/\.$/, "", id) + + s = $0 + if (!sub(/ +\. .*/, "", s)) { + getline + esc() + sub(/^ */, " ") + s = s $0 + sub(/ +\. .*/, "", s) + } + + if (match(s, /<[a-zA-Z0-9_]*\.h>/)) { + h = substr($0,RSTART,RLENGTH) + if (!(h in header)) + header[h] = id + } + + s = "" s "\n" + + s = "
  • " s + n = split(id, a, /\./) + while (n > level) { + s = "\n" s + level-- + } + ss[sid] = ss[sid] s + next } /^@sect Foreword/ { - ss[sid] = ss[sid] "\n" + while (level--) + ss[sid] = ss[sid] "\n" seenfore = 1 } @@ -34,14 +83,18 @@ BEGIN { } sid++ getline + esc() ss[sid] = ss[sid] "

    " $0 "

    \n" - title = $0 if (!seencontents) { ss[sid] = ss[sid] "
    \n"
     	}
     	next
     }
     
    +/^@sect 3\./ {
    +	markdef = 1
    +}
    +
     /^@sect/ {
     	sid++
     	slevel = split($2,a,/\./)+1
    @@ -49,9 +102,10 @@ BEGIN {
     		slevel = 5
     	sect = $2
     	getline
    +	esc()
     	# todo hX, back to top
    -	ss[sid] = sprintf("%s\n", sect, sect, slevel, $0, slevel)
    -	if ($0 ~ /^(Index|Contents)/)
    +	ss[sid] = sprintf("%s\n", slevel, sect, sect, $0, slevel)
    +	if ($0 == "Index")
     		ss[sid] = ss[sid] "
    \n"
     	next
     }
    @@ -86,7 +140,7 @@ BEGIN {
     /^@end pre/ {
     	if (!pre)
     		next
    -	pre = pre "
    \n" + pre = pre "\n
    \n" if (nn) note[nn] = note[nn] "\n" pre else @@ -105,18 +159,17 @@ BEGIN { nn = 0 p = $2 getline - i = $2 - ss[sid] = ss[sid] "\n" + ss[sid] = ss[sid] "\n" next } /^@para/ { - ss[sid] = ss[sid] "

    \n" + ss[sid] = ss[sid] sprintf("

    %s\n", sect, $2, sect, $2, $2) next } -/^ *(Syntax|Semantics|Description|Constraints|Synopsis|Returns)$/ { - ss[sid] = ss[sid] "

    " $0 "
    \n" +/^ ?(Syntax|Semantics|Description|Constraints|Synopsis|Returns|Recommended practice|Implementation limits|Environmental limits)$/ { + ss[sid] = ss[sid] "

    " $0 "\n" next } @@ -158,14 +211,26 @@ BEGIN { p = p substr(s,1,RSTART-1) m = substr(s,RSTART,RLENGTH) if (m in header) - p = p "" m "" + p = p "" m "" else p = p m s = substr(s,RSTART+RLENGTH) } s = p s p = "" - while (match(s, noteid "\\)")) { + # TODO: false positives.. + while (match(s, /[a-z]opt[ )"]/)) + s = substr(s,1,RSTART) "opt" substr(s,RSTART+RLENGTH-1) + if (match(s, /[a-z]opt$/)) + s = substr(s,1,RSTART) "opt" + for (;;) { + while (match(s, noteid-1 "\\)")) { + p = p substr(s,1,RSTART-1) + p = p "" noteid-1 ")" + s = substr(s,RSTART+RLENGTH) + } + if (!match(s, noteid "\\)")) + break if (noteid==1 && s !~ /\.1\)/) break p = p substr(s,1,RSTART-1) @@ -175,11 +240,11 @@ BEGIN { s = substr(s,RSTART+RLENGTH) } s = p s -# if (s ~ /^ *[1-9][0-9]*\) /) { -# sub(/\)/,"",s) -# sub(/[0-9]+/,"&)",s) -# } - + sub(/^ *Forward references/, "

    &", s) + if (markdef) { + s = "" s "
    " + markdef = 0 + } if (pre) pre = pre "\n" s else if (nn) @@ -191,19 +256,19 @@ BEGIN { END { ss[sid] = ss[sid] "" - print "C" + print "" title "" for (i = 1; i <= sid; i++) { print ss[i] -# if (slev[i] < 4) n = split(snote[i],a) if (n > 0) { - s = "

    footnotes
    \n" + s = "

    Footnotes\n" for (j = 1; j <= n; j++) { - s = s "

    " a[j] ")" note[a[j]+0] "\n" + s = s "

    " a[j] ")" note[a[j]+0] "\n" } print s } + print "

    Contents" } print ""