#! /usr/bin/gawk -f
# Last edited on 2004-02-05 05:30:04 by stolfi
BEGIN {
abort = -1;
chnum = 0;
}
(abort >= 0) { exit abort; }
/[\#][ ][=][=][=]/ { print; next; }
/^ *$/ { next; }
// {
gsub(/<[Bb][Rr]>/, " ");
gsub(/<[\/]*[Bb]>/, " ");
gsub(/<[\/]*sera>/, " ");
gsub(/[&]nbsp;/, " ");
gsub(/^[\011 ]+/, "");
gsub(/[\011 ]+$/, "");
gsub(/[\011 ][\011 ]+/, " ");
}
/^<[\/]*(html|head)>$/ {
next;
}
/^
[^<>]*<[\/]title>$/ {
title = $0;
gsub(/ */, "", title);
gsub(/ *<[\/]title>/, "", title);
chnum++;
printf "# Title {%s}\n", title;
printf "@sec{2}{chapter}{%d}\n", chnum;
next;
}
/^<(META|meta)[^<>]*>$/ {
next;
}
/^<[\/]*body[^<>]*>$/ {
next;
}
/^[^<>]*<[\/]h[123]>$/ {
title = $0;
gsub(/ */, "", title);
gsub(/ *<[\/]h[123]>/, "", title);
if (title ~ /[.]/) { data_error("oops - input uses \".\""); }
gsub(/ *[:][:] *$/, ".", title);
printf "@text{gchnum}\n\n %s\n\n@text{g}\n\n", title;
next;
}
// {
lin = $0;
# Turn \-numbers into {}-comments:
lin = gensub(/ *[\\] *([0-9]+[a-z]*) *[\\] */, " {\\1} ", "g", lin);
# Normalize internal spaces:
gsub(/ *[:][:] */, ":: ", lin);
gsub(/[ ]+$/, "", lin);
gsub(/[ ][ ]+/, " ", lin);
gsub(/^[ ]*/, " ", lin);
# Insert blank lines between apparent paragraphs:
gsub(/ *<[\/]*[Pp]> */, "\n\n ", lin);
gsub(/ *[:][:] *$/, "::\n\n ", lin);
# Replace SERA full stop "::" by ".":
# But first make sure that there is no "." already!
if (lin ~ /[.]/) { data_error("oops - input uses \".\""); }
gsub(/[:][:]/, ".", lin);
print lin;
next;
}
function data_error(msg){
printf "%d: error: %s\n", FNR, msg > "/dev/stderr";
abort = 1;
exit abort;
}