More clean up, update readme
[cql-java-moved-to-github.git] / util / regression / mkanswers
diff --git a/util/regression/mkanswers b/util/regression/mkanswers
new file mode 100755 (executable)
index 0000000..16e7dd2
--- /dev/null
@@ -0,0 +1,43 @@
+#!/usr/bin/perl -w
+
+
+use IO::File;
+use strict;
+
+$ENV{CLASSPATH} .= ":../../lib/cql-java.jar";
+
+if (@ARGV != 1) {
+    print STDERR "Usage: $0 <trusted-CQL-compiler>\n";
+    exit(1);
+}
+my $compiler = $ARGV[0];
+
+while (<sections/*>) {
+    my $sdir = $_;
+    s@sections/@@;
+    next if /^CVS$/ || /^10$/; # I _can't_ get CVS to stop extracting "10"
+    print "answering section $_ - ", read_file("$sdir/name"), "\n";
+
+    while (<$sdir/*.cql>) {
+       my $qfile = $_;
+       s@sections/([0-9]+/.*)\.cql@$1@;
+       my $query = read_file($qfile);
+       my $afile = $qfile;
+       $afile =~ s/\.cql$/.xcql/;
+       print "  wrote $_ - $query\n";
+       my $fh = new IO::File("| $compiler > $afile")
+           or die "can't run compiler '$compiler': $!";
+       print $fh $query;
+       $fh->close();
+    }
+}
+
+sub read_file {
+    my($name) = @_;
+
+    my $fh = new IO::File("<$name")
+       or die "can't read '$name': $!";
+    my $contents = join('', <$fh>);
+    $fh->close();
+    return $contents;
+}