| File: tron.awk | |
|---|---|
| patch-4 | patch-5 |
| Line 37 | Line 37 |
| # B (short circuit), R (same), C, L, H, U, E BEGIN { | # B (short circuit), R (same), C, L, H, U, E BEGIN { |
| # load in acronym daturbase before we munge RS. while((getline acronym < "acronyms.tron") > 0) { if(acronym ~ /=/) { split(acronym, ttt, "=") gsub(/"/, "''", ttt[2]) acronyms[ttt[1]] = ttt[2] } } close("acronyms.tron") | |
| # Use arbitrary numbers of blank lines to separate records | # Use arbitrary numbers of blank lines to separate records |
| RS = "\n[[:space:]]*\n+" | RS = "\n[[:space:]]*\n+" |
| FS = "\n" ORS = "\n\n" OFS = "\n" | FS = "\n" ORS = "\n\n" OFS = "\n" |
| Line 51 | Line 61 |
| gsub(/>/, "\\>") | gsub(/>/, "\\>") |
| fore = "<p>" aft = "</p>" | |
| # This stuff only runs at the start of the input .txt # file. It sets up filename vars and fills out some of # the ugly HTML-storing variables. Also slurps the title | # This stuff only runs at the start of the input .txt # file. It sets up filename vars and fills out some of # the ugly HTML-storing variables. Also slurps the title |
| Line 62 | Line 69 |
| outputstem = FILENAME sub(/\.txt$/, "", outputstem) | outputstem = FILENAME sub(/\.txt$/, "", outputstem) |
| 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>" | pagestart = "<html>\n<head>\n <title>" $0 "</title>\n" pagestart = pagestart " <link rel=\"stylesheet\" type=\"text/css\" href=\"print.css\" media=\"print\" />\n" pagestart = pagestart " <link rel=\"stylesheet\" type=\"text/css\" href=\"color-scheme.css\" media=\"screen\" />\n" pagestart = pagestart " <link rel=\"stylesheet\" type=\"text/css\" href=\"layout.css\" media=\"screen\" />\n</head>\n" pagestart = pagestart "<body bgcolor=\"black\" text=\"#cccccc\" link=\"#00cc00\" vlink=\"#aaaaaa\"> \n" # Note that this table is ignored by the div layout if you have # CSS. It exists only to support non-CSS browsers. mainstart = "<table valign=\"top\" border=\"0\" width=\"100%\"><tr valign=\"top\" height=\"15\"><td valign=\"top\" height=\"15\"> </td><td rowspan=\"2\">" mainstart = mainstart " <div class=\"mainbody\">" # notice the table data in these as well. tocstart = " </div>\n</td></tr><tr valign=\"top\" height=\"100%\"><td valign=\"top\" height=\"100%\">\n <div class=\"toc\">" pagefinish = " </div>\n</td></tr></table>\n\n</body>\n</html>" |
| outputfile = outputstem ".html" | outputfile = outputstem ".html" |
| printerfile = outputstem "_printable.html" | |
| print pagestart > outputfile | print pagestart > outputfile |
| print mainstart > outputfile print pagestart > printerfile | |
| print "<hr align=\"center\" width=\"25%\"/> <h4 class=\"navbar\"><a class=\"navbar\" href=\"" outputfile "\">" $0 "</a></h4><ol class=\"chapter\">" > outputstem ".nav" print "<h1>" $0 "</h1>" >> outputfile | print "<hr align=\"center\" width=\"25%\"/> <h4 class=\"navbar\"><a class=\"navbar\" href=\"" outputfile "\">" $0 "</a></h4><ol class=\"chapter\">" > outputstem ".nav" print "<h1>" $0 "</h1>" >> outputfile |
| print "<h1>" $0 "</h1>" >> printerfile | |
| next | next |
| } | } # # get a nice mouseover on the number of words in each # # paragraph, so that we can better estimate card capacity. # # Not likely to be useful in the general tron.awk distro. # countwords = "/usr/bin/wc -w | xargs echo" # print $0 |& countwords # close(countwords, "to") # wc prints output only when you close input # countwords |& getline numwords # close(countwords) # through with this paragraph # fore = "<p title=\"" numwords " words\">" |
| fore = "<p>" aft = "</p>" | |
| } | } |
| Line 99 | Line 125 |
| blockquotemode = "on" } print >> outputfile | blockquotemode = "on" } print >> outputfile |
| print >> printerfile | |
| next } | next } |
| Line 107 | Line 134 |
| sub(/^-+(8<|>8)-+$/, "</pre></p>", $NF) blockquotemode = "off" print >> outputfile | sub(/^-+(8<|>8)-+$/, "</pre></p>", $NF) blockquotemode = "off" print >> outputfile |
| print >> printerfile | |
| next } blockquotemode == "on" { print >> outputfile | next } blockquotemode == "on" { print >> outputfile |
| print >> printerfile | |
| next } | next } |
| Line 172 | Line 201 |
| } | } |
| # centered blocks. $1 ~ /^[[:blank:]]*-\| .* \|-[[:blank:]]*$/ { sub(/^[[:blank:]]*-\|/, "<div align=\"center\">") sub(/\|-[[:blank:]]*$/, "</div>") } # and left-flush blocks $1 ~ /^[[:blank:]]*\| .* \|-[[:blank:]]*$/ { sub(/^[[:blank:]]*\|/, "<div align=\"left\" style=\"float:left; clear:left;\">") sub(/\|-[[:blank:]]*$/, "</div>") } # and right-flush blocks $1 ~ /^[[:blank:]]*-\| .* \|[[:blank:]]*$/ { sub(/^[[:blank:]]*-\|/, "<div align=\"right\" style=\"float:right; clear:right;\">") sub(/\|[[:blank:]]*$/, "</div>") } | |
| # 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++) { | # 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:]]*$/) { firstrow = "true" } } for( i = 1; i <= NF; i++) { if($i ~ /^[[:blank:]]*\+[+=]+\+[[:blank:]]*$/) { firstrow = "true" $i = "" } | |
| if($i ~ /^[[:blank:]]*\+[+-]+\+[[:blank:]]*$/) { $i = "" | if($i ~ /^[[:blank:]]*\+[+-]+\+[[:blank:]]*$/) { $i = "" |
| } else if (firstrow == "true") { sub(/^[[:blank:]]*\|/, "<tr class=\"boxology\"> <th class=\"boxology\">", $i) sub(/\|[[:blank:]]*$/, "</th> </tr> \n", $i) gsub(/[|+]/, "</th> <th class=\"boxology\">", $i) firstrow = "false" | |
| } else { | } else { |
| sub(/^[[:blank:]]*\|/, "<tr class=\"boxology\"> <td class=\"boxology\">", $i) | if($i ~ /^[[:blank:]]*\|[^|]+\+/) { sub(/^[[:blank:]]*\|/, "<tr class=\"boxology\"> <th class=\"boxology\">", $i) } else { sub(/^[[:blank:]]*\|/, "<tr class=\"boxology\"> <td class=\"boxology\">", $i) } |
| sub(/\|[[:blank:]]*$/, "</td> </tr> \n", $i) gsub(/\|/, "</td> <td class=\"boxology\">", $i) | sub(/\|[[:blank:]]*$/, "</td> </tr> \n", $i) gsub(/\|/, "</td> <td class=\"boxology\">", $i) |
| gsub(/\+/, "</th> <td class=\"boxology\">", $i) | |
| } } aft = "</table>" | } } aft = "</table>" |
| Line 215 | Line 281 |
| sub(/^[[:blank:]]*(>|[\#\|])[[:blank:]]/, "", $i) } gsub(RS, "<p/>") | sub(/^[[:blank:]]*(>|[\#\|])[[:blank:]]/, "", $i) } gsub(RS, "<p/>") |
| fore = fore "<blockquote type=\"cite\">" | fore = fore "<blockquote type=\"cite\" style=\"font-style: italic;\">" |
| aft = "</blockquote> " aft } | aft = "</blockquote> " aft } |
| # Likewise centered blocks. $1 ~ /^[[:blank:]]*-\| .* \|-[[:blank:]]*$/ { sub(/^[[:blank:]]*-\|/, "<div align=\"center\">") sub(/\|-[[:blank:]]*$/, "</div>") } | |
| # lists can have a lot too $1 ~ /^[[:blank:]]+[-\*o[:digit:]\.]+[[:blank:]]/ { indentlevel = 0 | # lists can have a lot too $1 ~ /^[[:blank:]]+[-\*o[:digit:]\.]+[[:blank:]]/ { indentlevel = 0 |
| Line 294 | Line 354 |
| outputfile = outputstem "-" tocname ".html" chapternames[chnum] = outputfile print pagestart > outputfile | outputfile = outputstem "-" tocname ".html" chapternames[chnum] = outputfile print pagestart > outputfile |
| print mainstart > outputfile | |
| } tag = "<h" hlevel "><a name=\"" tocname "\">" closetag = "</a></h" hlevel ">" | } tag = "<h" hlevel "><a name=\"" tocname "\">" closetag = "</a></h" hlevel ">" |
| Line 318 | Line 379 |
| $0 = gensub(/<([^[:space:]]+\.html?)>/, "<a href=\"\\1\">\\1</a>", "g") } | $0 = gensub(/<([^[:space:]]+\.html?)>/, "<a href=\"\\1\">\\1</a>", "g") } |
| # do that funky acronym thing, awk boy { # This is a low-down dirty hack, but at least it doesn't # break so much. for (term in acronyms) { gsub(term, "<acronym title=\"" acronyms[term] "\">" term "</acronym>") #search = "([^[:alnum:]><&]|^)" term "([^[:alnum:]><&]|$)" #while(match($0, search, extras) != 0) { #gsub(extras[1] term extras[2], extras[1] "<acronym title=\"" acronyms[term] "\">" term "</acronym>" extras[2]) #} } } | |
| ## old-style URLs #/\[[^\[]+\]/ { # # images! | ## old-style URLs #/\[[^\[]+\]/ { # # images! |
| Line 336 | Line 410 |
| #sidebars $1 ~ /^[[:space:]]*\[/ && $NF ~ /\][[:space:]]*$/ { | #sidebars $1 ~ /^[[:space:]]*\[/ && $NF ~ /\][[:space:]]*$/ { |
| sub(/<p>/, "<blockquote class=\"sidebar\">", fore) | sub(/<p[^>]*>/, "<blockquote class=\"sidebar\">", fore) |
| sub(/<\/p>/, "</blockquote>", aft) sub(/^[[:space:]]*\[/, "", $1) sub(/\][[:space:]]*$/, "", $NF) } | sub(/<\/p>/, "</blockquote>", aft) sub(/^[[:space:]]*\[/, "", $1) sub(/\][[:space:]]*$/, "", $NF) } |
| #ed. notes $1 ~ /^[[:space:]]*\{/ && $NF ~ /\}[[:space:]]*$/ { | #ed. notes $1 ~ /^[[:space:]]*\{/ && $NF ~ /\}[[:space:]]*$/ { |
| sub(/<p>/, "<blockquote class=\"ednote\">", fore) | sub(/<p[^>]*>/, "<blockquote class=\"ednote\">", fore) |
| sub(/<\/p>/, "</blockquote>", aft) sub(/^[[:space:]]*\{/, "", $1) sub(/\}[[:space:]]*$/, "", $NF) | sub(/<\/p>/, "</blockquote>", aft) sub(/^[[:space:]]*\{/, "", $1) sub(/\}[[:space:]]*$/, "", $NF) |
| Line 353 | Line 428 |
| # emphasis /\*[^\*]+\*/ || /\/[^\/]+\// || /_[^_]+_/ || /{[^}]+}/ { | # emphasis /\*[^\*]+\*/ || /\/[^\/]+\// || /_[^_]+_/ || /{[^}]+}/ { |
| #print "chillin on " $0 $0 = gensub(/([[:space:]_\*])\/([[:punct:][:alpha:]][^\/]+[[:punct:][:alpha:]])\/([[:space:][:punct:]])/, "\\1<em>\\2</em>\\3", "g") $0 = gensub(/([[:space:]_\/])\*([[:punct:][:alpha:]][^\*]+[[:punct:][:alpha:]])\*([[:space:][:punct:]])/, "\\1<strong>\\2</strong>\\3", "g") | $0 = gensub(/([[:space:]_\/])\*([[:punct:][:alpha:]][^\*]+[[:punct:][:alpha:]])\*([[:space:][:punct:]])/, "\\1<em>\\2</em>\\3", "g") |
| $0 = gensub(/([[:space:]\/\*])_([[:punct:][:alpha:]][^_]+[[:punct:][:alpha:]])_([[:space:][:punct:]])/, "\\1<u>\\2</u>\\3", "g") $0 = gensub(/{([^}]+)}/, "<tt>\\1</tt>", "g") } | $0 = gensub(/([[:space:]\/\*])_([[:punct:][:alpha:]][^_]+[[:punct:][:alpha:]])_([[:space:][:punct:]])/, "\\1<u>\\2</u>\\3", "g") $0 = gensub(/{([^}]+)}/, "<tt>\\1</tt>", "g") } |
| Line 368 | Line 441 |
| # print the paragraph now { | # print the paragraph now { |
| print fore $0 aft >> outputfile | print " " fore $0 aft >> outputfile print " " fore $0 aft >> printerfile |
| } # wrap up the indices and finish off the html | } # wrap up the indices and finish off the html |
| Line 380 | Line 454 |
| print "</ol>" >> zootfile } print tocstart >> zootfile | print "</ol>" >> zootfile } print tocstart >> zootfile |
| close("navbar.nav") while((getline navline < "navbar.nav") > 0) { | close("navbar.tron") while((getline navline < "navbar.tron") > 0) { |
| if(navline ~ zootfile "\">") { sub(/class="navbar"/, "class=\"activenavbar\"", navline) } print navline >> zootfile } | if(navline ~ zootfile "\">") { sub(/class="navbar"/, "class=\"activenavbar\"", navline) } print navline >> zootfile } |
| print "</ol>" >> navfile | print "</ol>\n" >> navfile #print "<hr align=\"center\" width=\"25%\"/>\n" >> navfile print "<h4 class=\"navbar\">Other Formats</h4>\n" >> navfile print "<ul class=\"navbar\">\n" >> navfile print "<li class=\"navbar\"><a class=\"navbar\" href=\"" outputstem "_printable.html\">All One File</a></li>\n" >> navfile print "<li class=\"navbar\"><a class=\"navbar\" href=\"" outputstem ".txt\">Plain ASCII Text</a></li>\n" >> navfile print "</ul>\n<br/>\n" >> navfile |
| close(navfile) while((getline navline < navfile) > 0) { print navline >> zootfile | close(navfile) while((getline navline < navfile) > 0) { print navline >> zootfile |
| Line 397 | Line 477 |
| for(i=1; i <= chnum; i++) { zootfile = chapternames[i] print tocstart >> zootfile | for(i=1; i <= chnum; i++) { zootfile = chapternames[i] print tocstart >> zootfile |
| close("navbar.nav") while((getline navline < "navbar.nav") > 0) { | close("navbar.tron") while((getline navline < "navbar.tron") > 0) { |
| print navline >> zootfile } close(navfile) | print navline >> zootfile } close(navfile) |