#!/usr/bin/perl
#
# $Cambridge: hermes/src/prayer/templates/src/build_index.pl,v 1.4 2010/07/26 08:48:28 dpc22 Exp $

$prefix = shift(@ARGV);
$count = 0;

@templates = ();
foreach $i (@ARGV) {
  if  ($i =~ /(\S+)\.t/) {
    push(@templates, $1);
  } else {
    push(@templates, $i);
  }
  $count++;
}
@ARGV = ();
@templates = sort(@templates);

print <<'EOM';
#include "misc.h"
#include "template_structs.h"
EOM

foreach $i (@templates) {
  print "struct template _template_${prefix}_${i};\n";
}

print <<"EOM";

struct template_map template_map_${prefix}[] = {
EOM

foreach $i (@templates) {
  print <<"EOM";
    { "${i}", &_template_${prefix}_${i} },
EOM
}

print <<"EOM";
    { NIL, NIL }
};

unsigned long template_map_${prefix}_count = ${count};
EOM
