# Format an HTML table from my booklog. # Input: lines like "ISBN author, title" # optionally prefixed with a '*' for entries to bold. # Nonexistent ISBNs appear as '-'. # Meta-notes appear in [brackets]. BEGIN { printf ""; } END { printf "
"; } #/reread/ { next } { bold = 0; } /^[*]/ { bold = 1; sub(/^./, ""); } { printf ""; isbn = $1; $1 = ""; sub(/^ /, ""); i = index($0, ","); author = substr($0, 1, i-1); title = substr($0, i+2); note = ""; if (match(title, /\[.*\]/)) { note = substr(title, RSTART, RLENGTH); sub(/ \[.*\]/, "", title); } printf "%s", wrap("td", embolden(author)); printf "%s", wrap("td", abut(link(isbn, embolden(title)), note)); printf "" } function link(isbn, text) { if (isbn == "-") return text; else return sprintf("%s ", isbn, text); } function abut(s1, s2) { return s2 == "" ? s1 : s1 " " s2; } function embolden(x) { return bold ? wrap("b", x) : x; } function wrap(tag, x) { return sprintf("<%s>%s", tag, x, tag); }