#!/bin/awk -f BEGIN { ostate = state = count = 0; _emit("HEAD") } END { emit_("BODY") } function trim(s) { sub("^ +", "", s) sub(" +$", "", s) return s } function _emit(t, s, a) { print "<" t ">" (a ? "<" a s "\">" s "" : s) } function emit_(t, s) { print s "" } function emit(t, s, a) { _emit(t, s, a); emit_(t) } /ress/&&/F1/{next} {_=""} /./ { _ = trim($0) } {print "state="state, "count="count, length($0), $0} ( state == 2 || state == 3 ) && /^ *$/ { state++; emit_("HEAD"); _emit("BODY"); next } state <= 4 && /^(Excerpted|Alice.s)/ { titles[_] = "" } state <= 4 && _ in titles { state = 5 } state == 4 && count > 3 { state = 5; next } /^ *$/ { _ = ""; count++; next } state == 0 && /./ { state++; emit("Title", _); next } state <= 3 && /:$/ { state = 4; emit_("HEAD"); _emit("BODY") } state == 1 && /./ { state++; emit("Author", _); next } state == 2 && /./ { state++; emit("Copyright", _); next } state == 4 && /:$/ { _emit("LI", _); next } state == 4 && /./ { count=0; titles[_] = ""; _emit("LI", _, "A href=\"#"); sub(/^\[/,"",_); sub(/\]$/,"",_); titles[_] = ""; next } state < 5 { next } { l = length($0) } state == 6 && /^ \.+$/ && !listing { state--; emit_("PRE", $0); next } state == 6 && l > 80 && !listing { state--; emit_("PRE") } _ in titles { if (state > 5) { state--; listing--; emit_("PRE") }; emit("H1", _, "A name=\""); if (/(Exemple|Figure).*:|LISTING/) { state++; listing++; _emit("PRE") }; next } state == 6 { print; next } /: *$/ { state++; emit("P", $0); _emit("PRE"); next } /-----$/ { sub("-+$", "", $0); emit("P", $0); sub("[^-]+", "", _); $0 = _ } /^-+ *$/ { state++; _emit("PRE", $0); next } { emit("P", $0); next }