#!/usr/bin/env -S awk -f ## rcshist.awk -- Generate an html log with diffs from rcs # Proudly non-POSIX conformant ## $Id: rcshist.awk,v 1.8 2024/08/16 15:27:26 oc45ujef Exp $ ## Author: Florian Guthmann ## URL: https://wwwcip.cs.fau.de/~oc45ujef/misc/src/rcshist.awk ### Usage # $ rcs log [file] | rcshist ## Code function diff(r1, r2, file, date) { buffer = "" cmd = "rcs diff -kk -r" r1 " -r" r2 " " file while ((cmd | getline output) > 0){ switch(output) { case /^" html_escape(output) "" break case /^>/: output = "" html_escape(output) "" break } buffer = buffer output "\n" } close(cmd) return buffer } function html_escape(string) { gsub(/&/, "\\&", string) gsub(//, "\\>", string) gsub(/"/, "\\"", string) return string } function gen_tag(tag, body) { print "<" tag ">" html_escape(body) "" } function diff_to_html(message, date, dif) { # print "
" gen_tag("h2", message) gen_tag("time", fix_date(date)) print "
" gen_tag("summary", "Diff") print "
" dif "
" print "
" } function fix_date(date) { split("", date_parts) split(date, date_parts, "/") return date_parts[1] "-" date_parts[2] "-" date_parts[3] } /^Working file/ { file = $3 print "" print "" print "" gen_tag("title", "History of " file) print "" print "" print "" print "" gen_tag("h1", "History of " file) rev_i = 0 } /^revision/ { revs[++rev_i] = $2 getline metadata getline message messages[rev_i] = message split(metadata, a, " ") date[rev_i] = a[2] if(rev_i > 1){ d = diff(revs[rev_i], revs[rev_i - 1], file, date[rev_i - 1]) diff_to_html(messages[rev_i - 1], date[rev_i - 1],d) } } END { print "" print "" print "" }