#! /usr/bin/gawk -f # Usage: "$0 [ -v CODE=c ] < EVTIN > EVTOUT" # Reads a text in EVT format and adds an empty line with ";S" # transcription code after the last version of each transcribed line. # Used to massage th einput of show-occurrences. function error(msg) { printf "%s\n", msg > "/dev/stderr" abort = 1 exit } function getloc(lin, recno) { # Extracts a location code <...> from the beginning of "lin" match(lin, /^<[^>]*>/); if (RSTART == 0) { error((recno ": bad location = \"" substr(lin,1,19) "\"")); return "" } else { return substr(lin,RSTART,RLENGTH) } } BEGIN { abort = 0 usage = (ARGV[0] " [ -v CODE=c ] < EVTIN > EVTOUT") if (ARGC != 1) { error(("usage: " usage)); } oloc = "" if (CODE == "") { CODE = "S" } repl = (";" CODE ">") } /#/ { if (abort) exit; print; next } /./ { if (abort) exit; tloc = getloc($0, ("tx line " NR)) gsub(/;[A-Z]>/, repl, tloc) if ((tloc != oloc) && (oloc != "")) { print oloc } print oloc = tloc next } END { if(abort) exit; if(oloc != "") { print tloc } }