File: tron.awk
base-0 patch-1
Line 1Line 1
#!/usr/bin/gawk -f
#!/usr/bin/gawk -f

# ex:ts=4 sw=4
# Okay, so I want to be able to have output broken up into
# numerically-indexed files, and for there to be a central
# Okay, so I want to be able to have output broken up into
# numerically-indexed files, and for there to be a central
Line 61Line 62
                outputstem = FILENAME
                sub(/\.txt$/, "", outputstem)

                outputstem = FILENAME
                sub(/\.txt$/, "", outputstem)

                pagestart = "<html><head> <title>" $0 "</title> <link rel=\"stylesheet\" type=\"text/css\" href=\"bbc.css\"></head><body bgcolor=\"black\" text=\"#cccccc\" link=\"#0099cc\" vlink=\"#aaaaaa\"> <br/> <table width=\"100%\" border=\"0\"> <tr height=\"116\" style=\"height:116\"> <th valign=\"top\" align=\"center\"> <span width=\"240\"><a href=\"/\"><img src=\"logo.png\" width=\"200\" alt=\"LNX-BBC\" border=\"0\" style=\"width:200px\"/></a> </span> </th> <td rowspan=\"3\" valign=\"top\" width=\"100%\"> "
                tocstart = "</td></tr><tr height=\"100%\"> <td valign=\"top\" align=\"left\" height=\"100%\"><hr align=\"center\" width=\"25%\"/> "
                pagefinish = "</td></tr><tr height=\"100%\"> <td valign=\"top\" align=\"left\" height=\"100%\"> <a href=\"" outputstem ".txt\">Download this document as plain text</a> </td> </tr> <tr height=\"300\"> <td height=\"300\">   </td> <td height=\"300\">   </td></tr> </table> </div> </body></html>"
pagestart = "<html><head> <title>" $0 "</title>"
pagestart = pagestart "<link rel=\"stylesheet\" type=\"text/css\" href=\"print.css\" media=\"print\" />"
pagestart = pagestart "<link rel=\"stylesheet\" type=\"text/css\" href=\"bbc.css\" media=\"screen\" /></head>"
pagestart = pagestart "<body bgcolor=\"black\" text=\"#cccccc\" link=\"#0099cc\" vlink=\"#aaaaaa\"> <br/> "
pagestart = pagestart "<table width=\"100%\" border=\"0\" class=\"layout\">"
pagestart = pagestart "<tr height=\"116\" style=\"height:116\" class=\"layout\">"
pagestart = pagestart "<th valign=\"top\" align=\"center\" class=\"layout\"> <a href=\"/\"><img src=\"logo.png\" width=\"200\" alt=\"LNX-BBC\" border=\"0\" class=\"logo\"/></a> </span> </th>"
pagestart = pagestart "<td rowspan=\"3\" valign=\"top\" width=\"100%\" class=\"mainbody\"> "

tocstart = "</td></tr><tr height=\"100%\"> <td valign=\"top\" align=\"left\" height=\"100%\" class=\"layout\"><hr align=\"center\" width=\"25%\"/> "
pagefinish = "</td></tr><tr height=\"100%\"> <td valign=\"top\" align=\"left\" height=\"100%\" class=\"layout\"> <a href=\"" outputstem ".txt\">Download this document as plain text</a> </td> </tr> <tr height=\"300\" class=\"layout\"> <td height=\"300\" class=\"layout\">   </td> <td height=\"300\" class=\"layout\">   </td></tr> </table> </div> </body></html>"

                outputfile = outputstem ".html"
                print pagestart > outputfile
                print "<hr align=\"center\" width=\"25%\"/> <h4 class=\"navbar\"><a class=\"navbar\" href=\"" outputfile "\">" $0 "</a></h4><ol class=\"chapter\">" > outputstem ".nav"
                outputfile = outputstem ".html"
                print pagestart > outputfile
                print "<hr align=\"center\" width=\"25%\"/> <h4 class=\"navbar\"><a class=\"navbar\" href=\"" outputfile "\">" $0 "</a></h4><ol class=\"chapter\">" > outputstem ".nav"
Line 122Line 132
# Multiple dlist lines can be had by setting subsequent
# paragraphs with a tab as the first character
$1 ~ /^\t/ && dlist == "on" {
# Multiple dlist lines can be had by setting subsequent
# paragraphs with a tab as the first character
$1 ~ /^\t/ && dlist == "on" {
        fore = "<p><dd>"
        aft = "</dd></p>"
        fore = "<dd><p>"
        aft = "</p></dd>"
        #sub(/^\t/,"")
}

        #sub(/^\t/,"")
}

Line 162Line 172
}

}


# boxological tables made with dashes and pluses and vertical
# pipes.
$1 ~ /^[[:blank:]]*\+[+-]+\+[[:blank:]]*$/ || $1 ~ /^[[:blank:]]*\|/ {
        fore = "<table class=\"boxology\">"
        for( i = 1; i <= NF; i++) {
                if($i ~ /^[[:blank:]]*\+[+-]+\+[[:blank:]]*$/) {
                        $i = ""
                } else {
                        sub(/^[[:blank:]]*\|/, "<tr class=\"boxology\"> <td class=\"boxology\">", $i)
                        sub(/\|[[:blank:]]*$/, "</td> </tr> \n", $i)
                        gsub(/\|/, "</td> <td class=\"boxology\">", $i)
                }
        }
        aft = "</table>"
}

# This is an attempt to turn key-value lists into crude tables.
$1 ~ /^[[:blank:]]*[^=[:blank:]].*:[[:blank:]]+[^[:blank:]]+/ {
        tablep = "yes"
        for( i = 2; i <= NF; i++ ) {
                if($i ~ /:[[:blank:]]+[^[:blank:]]+/) {
                        donada = "nyk nyuk nyuk"
                } else {
                        tablep = "no"
                }
        }
        if( tablep != "no" ) {
                fore = "<table class=\"listy\">"
                aft = "</table>"
                for(i = 1; i <= NF; i++) {
                        sub(/:/, "</th> <td class=\"listy\">", $i)
                        $i = "<tr> <th class=\"listy\">" $i "</td> </tr>"
                }
        }
}
                       

# Citations are pretty inclusive, but do not nest
$1 ~ /^[[:blank:]]*(>|[\#|])[[:blank:]]/ {
        for(i = 1; i <= NF; i++) {
# Citations are pretty inclusive, but do not nest
$1 ~ /^[[:blank:]]*(>|[\#|])[[:blank:]]/ {
        for(i = 1; i <= NF; i++) {
Line 239Line 286
                hlevel = 5
        }
        if(hlevel == 1) {
                hlevel = 5
        }
        if(hlevel == 1) {
                print "<div class=\"next\" align=\"right\"><a class=\"next\" href=\"" outputstem (chnum + 1) ".html\"><b>Next»</b></a></div>" >> outputstem chnum ".html"
                if(chnum > 1) {
                        print "<div class=\"previous\" align=\"left\"><a class=\"previous\" href=\"" chapternames[chnum - 1] "\"><b>«Previous</b></a></div>" >> outputfile
                }
                print "<div class=\"next\" align=\"right\"><a class=\"next\" href=\"" outputstem "-" tocname ".html\"><b>Next»</b></a></div>" >> outputfile
                chnum++
                chnum++
                outputfile = outputstem chnum ".html"
                outputfile = outputstem "-" tocname ".html"
                chapternames[chnum] = outputfile
                print pagestart > outputfile
        }
        tag = "<h" hlevel "><a name=\"" tocname "\">"
                print pagestart > outputfile
        }
        tag = "<h" hlevel "><a name=\"" tocname "\">"
Line 285Line 336
#sidebars
$1 ~ /^[[:space:]]*\[/ && $NF ~ /\][[:space:]]*$/ {
#sidebars
$1 ~ /^[[:space:]]*\[/ && $NF ~ /\][[:space:]]*$/ {
        sub(/<p>/, "<p class=\"sidebar\">", fore)
        sub(/<p>/, "<blockquote class=\"sidebar\">", fore)
        sub(/<\/p>/, "</blockquote>", aft)
        sub(/^[[:space:]]*\[/, "", $1)
        sub(/\][[:space:]]*$/, "", $NF)
}

        sub(/^[[:space:]]*\[/, "", $1)
        sub(/\][[:space:]]*$/, "", $NF)
}


#ed. notes
$1 ~ /^[[:space:]]*\{/ && $NF ~ /\}[[:space:]]*$/ {
        sub(/<p>/, "<blockquote class=\"ednote\">", fore)
        sub(/<\/p>/, "</blockquote>", aft)
        sub(/^[[:space:]]*\{/, "", $1)
        sub(/\}[[:space:]]*$/, "", $NF)
}
# emphasis
# emphasis
Line 336Line 395
        print pagefinish >> zootfile

        for(i=1; i <= chnum; i++) {
        print pagefinish >> zootfile

        for(i=1; i <= chnum; i++) {
                zootfile = outputstem i ".html"
                zootfile = chapternames[i]
                print tocstart >> zootfile
                close("navbar.nav")
                while((getline navline < "navbar.nav") > 0) {
                print tocstart >> zootfile
                close("navbar.nav")
                while((getline navline < "navbar.nav") > 0) {
Line 414Line 473
{
        # add a line to the sidebar
        if(level == 1) {
{
        # add a line to the sidebar
        if(level == 1) {
                print "<li class=\"chapter\"><a class=\"navbar\" href=\"" outputstem chnum ".html\">" name "</a></li>" >> outputstem ".nav"
                print "<li class=\"chapter\"><a class=\"navbar\" href=\"" outputstem "-" maketocname(name) ".html\">" name "</a></li>" >> outputstem ".nav"
                # nix out that obnoxious anchor for the top page
                subheading = ""
        } else {
                subheading = "#" anchor
        }
        # add a line to the table of contents on the master html
        # file
        }
        # add a line to the table of contents on the master html
        # file
Line 427Line 490
                }

                if( lastlevel < level ) {
                }

                if( lastlevel < level ) {
                        print "<li><a href=\"" outputstem chnum ".html#" anchor "\">" name "</a>" >> outputstem ".html"
                        print "<li><a href=\"" chapternames[chnum] subheading "\">" name "</a>" >> outputstem ".html"
                } else {
                } else {
                        print "</li>\n\n<li><a href=\"" outputstem chnum ".html#" anchor "\">" name "</a>" >> outputstem ".html"
                        print "</li>\n\n<li><a href=\"" chapternames[chnum] subheading "\">" name "</a>" >> outputstem ".html"
                }
                lastlevel = level
        }
                }
                lastlevel = level
        }