ca6eefcba4c4671f6113bc8b31fdca83ed010345
[cql-java-moved-to-github.git] / test / regression / mkanswers
1 #!/usr/bin/perl -w
2
3 # $Id: mkanswers,v 1.5 2002-11-21 09:57:28 mike Exp $
4
5 use IO::File;
6 use strict;
7
8 $ENV{CLASSPATH} .= ":../../lib/cql-java.jar";
9
10 if (@ARGV != 1) {
11     print STDERR "Usage: $0 <trusted-CQL-compiler>\n";
12     exit(1);
13 }
14 my $compiler = $ARGV[0];
15
16 while (<sections/*>) {
17     my $sdir = $_;
18     s@sections/@@;
19     next if /^CVS$/ || /^10$/;  # I _can't_ get CVS to stop extracting "10"
20     print "answering section $_ - ", read_file("$sdir/name"), "\n";
21
22     while (<$sdir/*.cql>) {
23         my $qfile = $_;
24         s@sections/([0-9]+/.*)\.cql@$1@;
25         my $query = read_file($qfile);
26         my $afile = $qfile;
27         $afile =~ s/\.cql$/.xcql/;
28         print "  wrote $_ - $query\n";
29         my $fh = new IO::File("| $compiler > $afile")
30             or die "can't run compiler '$compiler': $!";
31         print $fh $query;
32         $fh->close();
33     }
34 }
35
36 sub read_file {
37     my($name) = @_;
38
39     my $fh = new IO::File("<$name")
40         or die "can't read '$name': $!";
41     my $contents = join('', <$fh>);
42     $fh->close();
43     return $contents;
44 }