#!xsh2
# -*- cperl -*-

quiet;

my $manual = { shift @ARGV };
open --xinclude $manual;
$ids = //@id;
perl { @ids = map literal($_), @$ids };

echo "# !! DO NOT EDIT !!";
echo "# this file was automatically generated by devel/make_help_map.xsh";
echo;
echo "package TrEd::Help;";
echo;
echo "%HELP_MAP = (";
echo "  '_TOC_' => 'ar01-toc.html',";

for my $f in { @ARGV } {
  for &{open --format html $f} {
    my $names={{}};
    my $n=(//@id|//@name);
    perl { 
      @{$names}{map {literal($_)} @$n} = ();
      for my $id (@ids) {
	if (exists($names->{$id})) {
	  echo "  '$id' => '$f',\n";
	}
      }
    };
  }
}

echo ");";
echo;
echo "1;";
