#! /usr/bin/gawk -f # Last edited on 1998-12-31 04:42:05 by stolfi BEGIN { abort = -1; usage = ( \ "show-discrepancies \\\n" \ " -f tuple-procs.gawk \\\n" \ " -v title=TITLE \\\n" \ " -v dir=DIR \\\n" \ " < EVTFILE " \ ); # Reads an interlinear file in EVMT format (EVA encoding) # and writes an HTML file that shows the differences # position by position. if (dir == "") { arg_error("must define \"dir\""); } if (title == "") { arg-error("must define \"title\""); } tup_clear_current_batch(); # Colors bg_color = "\"#000000\""; maj_color = "\"#ffff77\""; text_color = "\"#ffdd55\""; link_color = "\"#77ffff\""; vlink_color = "\"#55ff77\""; cons_color = "\"#ddff11\""; loc_color = "\"#77dd99\""; header_color = "\"#ff7755\""; comment_color = "\"#77dd99\""; page = ""; ofile = (dir "/legend.html"); print_html_header(); print_legend(); print_html_tailer(); ofile = (dir "/junk.html"); print_html_header(); npages = 0; } //{ if (abort >= 0) { exit abort; } } # Blank line /^ *$/ { next; } # `##'-comment (page header) /^([#][#] *|)<[^<>;.]*>/ { txt = $0; gsub(/^## */, "", txt); gsub(/[<>]/, "", txt); gsub(/{[^{}]*}/, "", txt); gsub(/[ ]/, "", txt); tup_process_current_batch(""); print_html_tailer(); page = txt; pglist[npages] = page; npages++; ofile = (dir "/" page ".html"); print_html_header() print_page_header(("page " txt)); printf "page = \"%s\"\n", page > "/dev/stderr"; next; } # Other `#'-comment /^[#]/ { if (tup_nb == 0) { print_comment($0); } else { tup_append_line_to_batch($0); } next; } # Text line /^=0) { exit abort; } tup_process_current_batch(""); print_html_tailer(); # Generate index page: ofile = (dir "/index.html"); print_html_header(); print_page_header("Index"); printf "\n", header_color > ofile; print_index_entry("legend", "trans codes"); for (i=0; i
\n" > ofile;
  print_html_tailer();
}

# Client functions called by tup_process_current_batch:

function process_batch_texts(loc,txt,trn,nv,nc,   i,col)
{
  # Print them nicely formatted
  compare_versions(txt,nv,nc);
  if (last_type != "loc") { printf "", loc_color > ofile; }
  printf "\n" > ofile;
  printf "\n" > ofile;
  if (substr(loc,1,length(page)+1) == (page ".")) 
    { loc = substr(loc,length(page)+2); }
  if (match(loc, /[0-9]$/)) { loc = (loc " "); }
  loc = sprintf("%-7s", loc);
  for(i=0; i%s|\n", \
        loc, substr("ABCDEFGHIJKLMNOPQRSTUVWXYZ",trn[i],1), col, protect(txt[i]) \
        > ofile;
      loc = "";
    }
  last_type = "loc";
}

function process_batch_lines(batch,nb, i)
{
  # Called with the original (and new) lines, including comments.
  # Print the comments only
  for (i=0; i\n" >> ofile;
  printf "\n" > ofile;
  printf "%s\n", protect(title) > ofile;
  printf "\n" > ofile;
  printf "\n", \
    bg_color, comment_color, link_color, vlink_color > ofile;
  printf "

Created %s by J. Stolfi

\n", \ protect(strftime("%Y-%m-%d %H:%M:%S")) > ofile; printf "

%s

\n", header_color, protect(title) > ofile; printf "
\n", comment_color > ofile;
  last_type = "comment";
}

function print_html_tailer()
{
  printf "\n" > ofile;
  printf "
\n" > ofile; printf "\n" > ofile; printf "\n" > ofile; close(ofile); } function print_legend() { print_page_header("Transcription codes") > ofile; printf " A = majority of independent versions.\n", maj_color > ofile; printf "\n" > ofile; printf " C: Second Study Group punchcards (P. Currier, M. D'Imperio, et al.).\n", text_color > ofile; printf " F: First Study Group punchcards (W. Friedman et al.).\n", text_color > ofile; printf " H: Takeshi Takahashi.\n", text_color > ofile; printf " J: Jim Reeds.\n", text_color > ofile; printf " K: Karl Kluge.\n", text_color > ofile; printf " L: Don Latham.\n", text_color > ofile; printf " N: Gabriel Landini.\n", text_color > ofile; printf " P: Father Th. Petersen (reported by K. Kluge).\n", text_color > ofile; printf " R: Mike Roe.\n", text_color > ofile; printf " T: John Tiltman.\n", text_color > ofile; printf " U: Jorge Stolfi.\n", text_color > ofile; printf " V: John Grove.\n", text_color > ofile; printf " X: Denis V. Mardle.\n", text_color > ofile; printf " Z: Rene Zandbergen.\n", text_color > ofile; printf "\n" > ofile; printf " D: second choice from [|] in "C" lines.\n", text_color > ofile; printf " G: second choice from [|] in "F" lines.\n", text_color > ofile; printf " I: second choice from [|] in "J" lines.\n", text_color > ofile; printf " M: second choice from [|] in "L" lines.\n", text_color > ofile; printf " Q: second choice from [|] in "K" lines.\n", text_color > ofile; printf "\n" > ofile; printf " Y = consensus of all versions.\n", cons_color > ofile; printf "\n" > ofile; } function print_page_header(title) { printf "
\n" > ofile; printf "

%s

\n", header_color, protect(title) > ofile; printf "
\n", comment_color > ofile;
  last_type = "comment";
}

function print_comment(lin)
{
  if (last_type != "comment") 
    { printf "\n", comment_color > ofile; }
  gsub(/^#[ ]?/, "", lin);
  printf "%s\n", protect(lin) > ofile;
  last_type = "comment";
}

function print_index_entry(fname, title)
{
  printf "[%s] ", fname, title > ofile;
}

function protect(lin)
{
  gsub(/[&]/, "\\&", lin);
  gsub(/[<]/, "\\<", lin);
  gsub(/[>]/, "\\>", lin);
  return(lin);
}

function compare_versions(txt,nv,nc,  i,j,new,m,c,d,and,tup)
{
  # For each character position, compares the versions "ver[i]", "i=0..ntr-1".
  # If all versions agree, erases all characters except that of "ver[0]". 
  # If there is any disagreement, leaves that character unchanged in all versions.
  
  # Initialize all "new" entries
  split("", new);
  new[0] = "";
  for (i=0; i "/dev/stderr"; 
  printf "usage: %s\n", usage > "/dev/stderr"; 
  abort = 1; exit abort;
}

function fatal_error(msg)
{
  printf "file %s, line %d: *** %s\n", FILENAME, FNR, msg > "/dev/stderr"; 
  abort = 1; exit abort;
}
    
function format_error(msg)
{
  printf "file %s, line %d: %s\n", FILENAME, FNR, msg > "/dev/stderr";
}

function print_line()
{
  printf "file %s, line %d: %s\n", FILENAME, FNR, $0 > "/dev/stderr";
  printf "\n" > "/dev/stderr";
}