#!/usr/bin/perl

my ($filename, $enumname) = @ARGV;

open(FILE, $filename) or die("Could not open input file\n");
my @fconts = <FILE>;
close(FILE);

%StatusCodes = ();
my $str = "#include <idc.idc>

static main(void)
{
\tauto id;
";

foreach $i (@fconts)
{
  if($i =~ /^#define\s+?((?:IO|STATUS|DBG)_[^\t\s]+)[\s\t]+?\(\(NTSTATUS\)0x([0-9A-F]{1,8})L\)/i) # )
  {
    my ($key, $value) = ($1, $2);
    if(($StatusCodes{$key} ne '') && ($StatusCodes{$key} ne $value))
    {
      $str .= "\t// CONFLICT: $key == $value (currently ".$StatusCodes{$key}.")\n";
    }
    $StatusCodes{$key} = $value;
#    print "$key == $value\n";
  }
}

$str .= "\tid = AddEnum(-1,\"$enumname\",0x100000);\n";

foreach $x (keys %StatusCodes)
{
  $str .= "\tAddConstEx(id,\"$x\", 0x".$StatusCodes{$x}.", -1);\n";
}
$str .= "}\n";
print $str;
__END__