Lots of changes, mostly to documentation, towards initial release.
[cql-java-moved-to-github.git] / test / mkanswers
1 #!/usr/bin/perl -w
2
3 use IO::File;
4 use strict;
5
6 if (@ARGV != 1) {
7     print STDERR "Usage: $0 <trusted-CQL-compiler>\n";
8     exit(1);
9 }
10 my $compiler = $ARGV[0];
11
12 while (<sections/*>) {
13     my $sdir = $_;
14     s@sections/@@;
15     print "answering section $_ - ", read_file("$sdir/name"), "\n";
16
17     while (<$sdir/*.cql>) {
18         my $qfile = $_;
19         s@sections/([0-9]+/.*)\.cql@$1@;
20         my $query = read_file($qfile);
21         my $afile = $qfile;
22         $afile =~ s/\.cql$/.xcql/;
23         print "  query $_ - $query\n";
24         my $fh = new IO::File("| $compiler > $afile")
25             or die "can't run compiler '$compiler': $!";
26         print $fh $query;
27         $fh->close();
28     }
29 }
30
31 sub read_file {
32     my($name) = @_;
33
34     my $fh = new IO::File("<$name")
35         or die "can't read '$name': $!";
36     my $contents = join('', <$fh>);
37     $fh->close();
38     return $contents;
39 }