#!/usr/bin/perl -w
use PARI::822;

$class=$ARGV[0];

%secnumber=(
  'operators'          =>  1 ,
  'conversions'        =>  2 ,
  'transcendental'     =>  3 ,
  'number_theoretical' =>  4 ,
  'elliptic_curves'    =>  5 ,
  'number_fields'      =>  6 ,
  'polynomials'        =>  7 ,
  'linear_algebra'     =>  8 ,
  'sums'               =>  9 ,
  'graphic'            => 10 ,
  'programming/control'        => 11 ,
  'programming/specific'       => 11 ,
  'symbolic_operators' => 13 ,
  'member_functions'   => 14 ,
  'programming/internals'      => 15
);

print <<EOF;
/* This file is autogenerated from the database. */
/* See src/desc/gen_proto */
/* Do not edit*/
entree functions_${class}[]={
EOF
PARI::822::read(\%funcs,$ARGV[1]);
foreach my $name (sort keys %funcs)
{
      my %func=%{$funcs{$name}};
      next if ($func{'Class'} ne $class);
      my $gpname=$func{'Function'};
      $gpname =~ s/\\/\\\\/g;
      defined($func{'Section'})
        or die("$name: mandatory field Section is missing");
      my $sec=$secnumber{$func{'Section'}};
      defined($sec)
        or die("$name: Section field has unknown value $func{'Section'}");
      my $proto=$func{'Prototype'};
      my $cname=$func{'C-Name'};
      my $help=$func{'Help'};
      defined($help) or die("$name: mandatory field Help is missing");
      $help =~ s/\n/ /g;
      $help =~ s/\\/\\\\/g;
      $help =~ s/"/\\"/g;
      $help = "\"$help\"";

      if (defined($cname))
      {
        $proto =~ s/"/\\"/g;
        print "{\"$gpname\",0,(void*)$cname,$sec,\"$proto\",$help},\n";
      }
      else
      {
        print "{\"$gpname\",0,NULL,$sec,NULL,$help},\n";
      }
}
print <<'EOF';
{NULL,0,NULL,0,NULL,NULL} /* sentinel */
};
EOF
