#! /usr/bin/gawk -f # Last edited on 2000-06-14 04:54:06 by stolfi BEGIN { abort = -1; usage = ( ARGV[0] " [ -v title=STRING ] < INFILE.grx > OUTFILE.html" ); # Reads a grammar in ".grx" format, outputs a nice # HTML rendering of the same. # If the title is specified, outputs the HTML header end trailer, # as well as a

title. Otherwise those items are omitted. if (numcolor == "") { numcolor = "404040"; } if (cmtcolor == "") { cmtcolor = "007f00"; } if (defcolor == "") { defcolor = "600000"; } if (ntscolor == "") { ntscolor = "a00040"; } if (bgcolor == "") { bgcolor = "ffffff"; } if (title != "") { output_html_head(title); } printf "\n", numcolor; printf "
\n";
}

/^ *$/ {
  printf "\n";
  next;
}

/^ *[#] *Data-File *:/ {
  next;
}

/^ *[#]/ {
  cmt = $0; 
  sub(/# =/, "===", cmt); 
  sub(/# -/, "---", cmt); 
  sub(/#/, " ", cmt); 
  printf "%s\n", cmtcolor, html_protect(cmt);
  next;
}

/^[A-Z()].*[:]/ {
  name = $0; gsub(/ *[:] *$/, "", name);
  printf "\n", html_protect(name);
  printf "%s:\n", ntscolor, html_protect(name);
  next;
}

/./ {
  match($0, /[ ][^ ]+[ ]*$/);
  cts = substr($0,1,RSTART);
  def = substr($0,RSTART+1);
  printf "%s%s\n", 
    numcolor, html_protect(cts), 
    defcolor, html_protect(def);
  next;
}

END {
  printf "
\n"; printf "
\n"; if (title != "") { output_html_tail(); } } function output_html_head(title) { printf "\n"; printf "\n"; printf "%s\n", html_protect(title); printf "\n"; printf "\n", bgcolor; printf "

%s

\n", html_protect(title); } function output_html_tail() { printf "\n"; printf "\n"; } function html_protect(txt) { gsub(/&/, "\\&", txt); gsub(//, "\\>", txt); gsub(/\n/, "
", txt); return(txt); }