#!/usr/bin/perl

my $freqs = $ARGV[0]; shift;
if (!defined $freqs) {
  die "usage: markup-rules-file-with-freqs freqs < rulesfile.cf > markedup.cf\n";
}

my %freqs = ();
open (IN, "<$freqs") or die "cannot read $freqs";
while (<IN>) {
  /^(\s*\d\S+.*\s+\d+\.\d+\s+)([A-Z_][A-Z_0-9]+)$/ or next;
  $freqs{$2} = $1;
}
close IN;

while (<>) {
  next if /^#freqs:/;

  my $orig = $_;
  s/#.*$//g; s/^\s+//; s/\s+$//;

  my $lang = '';
  if (s/^lang\s+(\S+)\s+//) {
    $lang = $1;
  }

  if (/^(header|rawbody|body|full|uri|meta)\s+(\S+)\s+/) {
    my $type = $1;
    my $name = $2;
    if (defined $freqs{$name}) {
      print "#freqs:", $freqs{$name}, $name, "\n";
    }
  }

  print $orig;
}



