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