2007-05-02 01:07:00 +00:00
|
|
|
/*
|
2007-09-07 23:14:00 +00:00
|
|
|
* $Id: doc.awk,v 1.4 2007/09/06 09:05:32 bacon Exp $
|
2007-05-02 01:07:00 +00:00
|
|
|
*
|
|
|
|
* {License}
|
|
|
|
*/
|
|
|
|
|
|
|
|
global header, mode;
|
|
|
|
global empty_line_count;
|
|
|
|
global para_started;
|
|
|
|
global list_count;
|
2007-12-13 01:07:10 +00:00
|
|
|
global table_row_count;
|
|
|
|
global table_row_line_count;
|
|
|
|
global table_in_th;
|
2007-12-24 01:20:10 +00:00
|
|
|
global tabs;
|
2007-05-02 01:07:00 +00:00
|
|
|
|
2007-12-12 08:05:58 +00:00
|
|
|
function print_text (full)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
local fra1, fra2, link, idx, t1, t2;
|
|
|
|
|
|
|
|
gsub ("<", "\\<", full);
|
|
|
|
gsub (">", "\\>", full);
|
2007-12-24 01:20:10 +00:00
|
|
|
gsub (/\t/, tabs, full);
|
2007-05-02 01:07:00 +00:00
|
|
|
|
|
|
|
while (match (full, /\{[^{},]+,[^{},]+\}/) > 0)
|
|
|
|
{
|
|
|
|
fra1 = substr (full, 1, RSTART-1);
|
|
|
|
link = substr (full, RSTART, RLENGTH);
|
|
|
|
fra2 = substr (full, RSTART+RLENGTH, length(full)-RLENGTH);
|
|
|
|
|
|
|
|
idx = index(link, ",");
|
|
|
|
t1 = substr (link, 2, idx-2);
|
|
|
|
t2 = substr (link, idx+1, length(link)-idx-1);
|
|
|
|
|
|
|
|
full = sprintf ("%s<a href='%s'>%s</a>%s", fra1, t2, t1, fra2);
|
|
|
|
}
|
|
|
|
|
2007-12-24 01:20:10 +00:00
|
|
|
while (match (full, /##\/[^\[\][:space:]]+\/##/) > 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
fra1 = substr (full, 1, RSTART-1);
|
2007-12-24 01:20:10 +00:00
|
|
|
link = substr (full, RSTART+3, RLENGTH-6);
|
2007-05-02 01:07:00 +00:00
|
|
|
fra2 = substr (full, RSTART+RLENGTH, length(full)-RLENGTH);
|
|
|
|
|
|
|
|
full = sprintf ("%s<i>%s</i>%s", fra1, link, fra2);
|
|
|
|
}
|
|
|
|
|
2007-12-24 01:20:10 +00:00
|
|
|
while (match (full, /##=[^#[:space:]]+=##/) > 0)
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
fra1 = substr (full, 1, RSTART-1);
|
2007-12-24 01:20:10 +00:00
|
|
|
link = substr (full, RSTART+3, RLENGTH-6);
|
2007-05-02 01:07:00 +00:00
|
|
|
fra2 = substr (full, RSTART+RLENGTH, length(full)-RLENGTH);
|
|
|
|
|
|
|
|
full = sprintf ("%s<b>%s</b>%s", fra1, link, fra2);
|
|
|
|
}
|
|
|
|
|
2007-12-24 01:20:10 +00:00
|
|
|
while (match (full, /##-[^#[:space:]]+-##/) > 0)
|
|
|
|
{
|
|
|
|
fra1 = substr (full, 1, RSTART-1);
|
|
|
|
link = substr (full, RSTART+3, RLENGTH-6);
|
|
|
|
fra2 = substr (full, RSTART+RLENGTH, length(full)-RLENGTH);
|
|
|
|
|
|
|
|
full = sprintf ("%s<strike>%s</strike>%s", fra1, link, fra2);
|
|
|
|
}
|
|
|
|
|
2007-05-02 01:07:00 +00:00
|
|
|
print full;
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN {
|
|
|
|
header = 1;
|
|
|
|
mode = 0;
|
|
|
|
empty_line_count = 0;
|
|
|
|
para_started = 0;
|
|
|
|
|
2007-12-24 01:20:10 +00:00
|
|
|
tabs = "\\ \\ \\ \\ \\ \\ \\ \\ ";
|
|
|
|
|
2007-09-07 23:14:00 +00:00
|
|
|
#output=ARGV[1];
|
2007-05-02 01:07:00 +00:00
|
|
|
#gsub (/\.man/, ".html", output);
|
|
|
|
#print "OUTPUT TO: " output;
|
|
|
|
|
|
|
|
print "</html>";
|
|
|
|
print "</head>";
|
|
|
|
print "<meta http-equiv='content-type' content='text/html; charset=UTF-8'>";
|
|
|
|
print "<link href='doc.css' rel='stylesheet' type='text/css' />";
|
|
|
|
}
|
|
|
|
|
|
|
|
header && /^\.[[:alpha:]]+[[:space:]]/ {
|
|
|
|
if ($1 == ".title")
|
|
|
|
{
|
|
|
|
local i;
|
|
|
|
|
|
|
|
printf "<title>";
|
|
|
|
for (i = 2; i <= NF; i++) printf "%s ", $i;
|
|
|
|
print "</title>";
|
|
|
|
}
|
2007-12-24 01:20:10 +00:00
|
|
|
else if ($1 == ".tabstop")
|
|
|
|
{
|
|
|
|
if (NF >= 2)
|
|
|
|
{
|
|
|
|
local i;
|
|
|
|
for (i = 0; i < $2; i++) tabs = tabs . "\\ ";
|
|
|
|
}
|
|
|
|
}
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
header && !/^\.[[:alpha:]]+[[:space:]]/ {
|
|
|
|
|
|
|
|
header = 0;
|
|
|
|
print "</head>";
|
|
|
|
print "<body>";
|
|
|
|
}
|
|
|
|
|
|
|
|
!header {
|
|
|
|
local text;
|
|
|
|
|
|
|
|
if (mode == 0)
|
|
|
|
{
|
|
|
|
if (/^$/)
|
|
|
|
{
|
|
|
|
# empty line
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
para_started = 0;
|
|
|
|
print "</p>";
|
|
|
|
}
|
|
|
|
empty_line_count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (/^= [^=]+ =$/)
|
|
|
|
{
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
print "</p>";
|
|
|
|
para_started = 0;
|
|
|
|
}
|
|
|
|
text=substr($0, 2, length($0)-2);
|
2007-12-13 01:07:10 +00:00
|
|
|
print "<h1>" . text . "</h1>";
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else if (/^== [^=]+ ==$/)
|
|
|
|
{
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
print "</p>";
|
|
|
|
para_started = 0;
|
|
|
|
}
|
|
|
|
text=substr($0, 3, length($0)-4);
|
2007-12-13 01:07:10 +00:00
|
|
|
print "<h2>" . text . "</h2>";
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else if (/^=== [^=]+ ===$/)
|
|
|
|
{
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
print "</p>";
|
|
|
|
para_started = 0;
|
|
|
|
}
|
|
|
|
text=substr($0, 4, length($0)-6);
|
2007-12-13 01:07:10 +00:00
|
|
|
print "<h3>" . text . "</h3>";
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
else if (/^==== [^=]+ ====$/)
|
|
|
|
{
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
print "</p>";
|
|
|
|
para_started = 0;
|
|
|
|
}
|
|
|
|
text=substr($0, 5, length($0)-8);
|
2007-12-13 01:07:10 +00:00
|
|
|
print "<h4>" . text . "</h4>";
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
2007-12-13 01:07:10 +00:00
|
|
|
else if (/^\{\{\{$/) # {{{
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
# {{{
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
print "</p>";
|
|
|
|
para_started = 0;
|
|
|
|
}
|
2007-12-13 03:45:15 +00:00
|
|
|
print "<pre class='ase'>";
|
2007-05-02 01:07:00 +00:00
|
|
|
mode = 1;
|
|
|
|
}
|
2007-12-13 01:07:10 +00:00
|
|
|
else if (/^\[\[\[$/) # [[[
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
print "</p>";
|
|
|
|
para_started = 0;
|
|
|
|
}
|
|
|
|
print "<ul>";
|
|
|
|
mode = 2;
|
|
|
|
list_count = 0;
|
|
|
|
}
|
2007-12-13 01:07:10 +00:00
|
|
|
else if (/^\(\(\($/) # (((
|
2007-05-02 01:07:00 +00:00
|
|
|
{
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
print "</p>";
|
|
|
|
para_started = 0;
|
|
|
|
}
|
|
|
|
print "<ol>";
|
|
|
|
mode = 3;
|
|
|
|
list_count = 0;
|
|
|
|
}
|
2007-12-13 01:07:10 +00:00
|
|
|
else if (/^\{\{\|$/) # {{|
|
|
|
|
{
|
|
|
|
if (para_started)
|
|
|
|
{
|
|
|
|
print "</p>";
|
|
|
|
para_started = 0;
|
|
|
|
}
|
|
|
|
|
2007-12-13 03:45:15 +00:00
|
|
|
print "<table class='ase'>";
|
2007-12-13 01:07:10 +00:00
|
|
|
mode = 4;
|
|
|
|
table_row_count = 0;
|
2007-12-24 01:20:10 +00:00
|
|
|
|
|
|
|
print "<tr class='ase'>";
|
|
|
|
table_row_count++;
|
|
|
|
table_row_line_count = 0;
|
2007-12-13 01:07:10 +00:00
|
|
|
}
|
2007-05-02 01:07:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!para_started > 0)
|
|
|
|
{
|
|
|
|
print "<p>";
|
|
|
|
para_started = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
gsub ("<", "\\<");
|
|
|
|
gsub (">", "\\>");
|
|
|
|
print $0;
|
|
|
|
*/
|
|
|
|
|
|
|
|
print_text ($0);
|
|
|
|
print "<br>";
|
|
|
|
}
|
|
|
|
|
|
|
|
empty_line_count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == 1)
|
|
|
|
{
|
|
|
|
if (/^}}}$/)
|
|
|
|
{
|
|
|
|
# }}}
|
|
|
|
print "</pre>";
|
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gsub ("<", "\\<");
|
|
|
|
gsub (">", "\\>");
|
|
|
|
print $0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == 2)
|
|
|
|
{
|
|
|
|
if (/^]]]$/)
|
|
|
|
{
|
|
|
|
# ]]]
|
|
|
|
print "</li>";
|
|
|
|
print "</ul>";
|
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
else if (/^\* [^[:space:]]+/)
|
|
|
|
{
|
|
|
|
gsub ("<", "\\<");
|
|
|
|
gsub (">", "\\>");
|
|
|
|
if (list_count > 0) print "</li>";
|
|
|
|
print "<li>";
|
|
|
|
|
|
|
|
print_text (substr ($0, 3, length($0)-2));
|
|
|
|
list_count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_text ($0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (mode == 3)
|
|
|
|
{
|
|
|
|
if (/^\)\)\)$/)
|
|
|
|
{
|
|
|
|
# )))
|
|
|
|
print "</li>";
|
|
|
|
print "</ol>";
|
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
else if (/^\* [^[:space:]]+/)
|
|
|
|
{
|
|
|
|
gsub ("<", "\\<");
|
|
|
|
gsub (">", "\\>");
|
|
|
|
if (list_count > 0) print "</li>";
|
|
|
|
print "<li>";
|
|
|
|
|
|
|
|
print_text (substr ($0, 3, length($0)-2));
|
|
|
|
list_count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_text ($0);
|
|
|
|
}
|
|
|
|
}
|
2007-12-13 01:07:10 +00:00
|
|
|
else if (mode == 4)
|
|
|
|
{
|
|
|
|
if (/^\|}}$/) # |}}
|
|
|
|
{
|
|
|
|
if (table_row_line_count > 0)
|
|
|
|
print ((table_in_th)? "</th>": "</td>");
|
|
|
|
if (table_row_count > 0) print "</tr>";
|
|
|
|
print "</table>";
|
|
|
|
mode = 0;
|
|
|
|
}
|
|
|
|
else if (/^\|-+$/) # |-
|
|
|
|
{
|
|
|
|
if (table_row_line_count > 0)
|
|
|
|
print ((table_in_th)? "</th>": "</td>");
|
|
|
|
if (table_row_count > 0) print "</tr>";
|
2007-12-13 03:45:15 +00:00
|
|
|
print "<tr class='ase'>";
|
2007-12-13 01:07:10 +00:00
|
|
|
table_row_count++;
|
|
|
|
table_row_line_count = 0;
|
|
|
|
}
|
|
|
|
else if (table_row_count == 1 && /^![[:space:]]*$/) # !
|
|
|
|
{
|
|
|
|
if (table_row_line_count > 0)
|
|
|
|
print ((table_in_th)? "</th>": "</td>");
|
2007-12-13 03:45:15 +00:00
|
|
|
print "<th class='ase'>";
|
2007-12-13 01:07:10 +00:00
|
|
|
print " ";
|
|
|
|
table_in_th = 1;
|
|
|
|
table_row_line_count++;
|
|
|
|
}
|
|
|
|
else if (table_row_count == 1 && /^! .+/) # ! text
|
|
|
|
{
|
|
|
|
if (table_row_line_count > 0)
|
|
|
|
print ((table_in_th)? "</th>": "</td>");
|
2007-12-13 03:45:15 +00:00
|
|
|
print "<th class='ase'>";
|
2007-12-13 01:07:10 +00:00
|
|
|
print_text (substr ($0, 3, length($0)-2));
|
|
|
|
table_in_th = 1;
|
|
|
|
table_row_line_count++;
|
|
|
|
}
|
|
|
|
else if (/^\|[[:space:]]*$/) # |
|
|
|
|
{
|
|
|
|
if (table_row_line_count > 0)
|
|
|
|
print ((table_in_th)? "</th>": "</td>");
|
2007-12-13 03:45:15 +00:00
|
|
|
print "<td class='ase'>";
|
2007-12-13 01:07:10 +00:00
|
|
|
print " ";
|
|
|
|
table_in_th = 0;
|
|
|
|
table_row_line_count++;
|
|
|
|
}
|
|
|
|
else if (/^\| .+/) # | text
|
|
|
|
{
|
|
|
|
if (table_row_line_count > 0)
|
|
|
|
print ((table_in_th)? "</th>": "</td>");
|
2007-12-13 03:45:15 +00:00
|
|
|
print "<td class='ase'>";
|
2007-12-24 01:20:10 +00:00
|
|
|
|
2007-12-13 01:07:10 +00:00
|
|
|
print_text (substr ($0, 3, length($0)-2));
|
|
|
|
table_in_th = 0;
|
|
|
|
table_row_line_count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print "<br>";
|
|
|
|
print_text ($0);
|
|
|
|
table_row_line_count++;
|
|
|
|
}
|
|
|
|
}
|
2007-05-02 01:07:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
print "</body>";
|
|
|
|
print "</html>";
|
|
|
|
}
|