#!/usr/bin/perl -w
-# Copyright (C) 2007 Apple Inc. All rights reserved.
+# Copyright (C) 2007 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use strict;
+use Getopt::Long;
use File::Basename;
+my $showHelp = 0;
+my $jsShellPath;
+
my $programName = basename($0);
my $usage = <<EOF;
-Usage: $programName [file 1] [file 2]
+Usage: $programName --shell=[path] [options] FILE FILE
+ --help Show this help message
+ --shell Path to javascript shell
EOF
-if (scalar @ARGV < 2) {
- print STDERR $usage;
- exit 1;
+GetOptions('shell=s' => \$jsShellPath,
+ 'help' => \$showHelp);
+
+if (scalar @ARGV < 2 || !$jsShellPath || $showHelp) {
+ print STDERR $usage;
+ exit 1;
}
sub readResultsFile($)
{
my ($filename) = @_;
- open FILE, "<${filename}";
+ open FILE, "<", $filename or die;
my $foundStart = 0;
+ my $foundOutput = 0;
my $foundEnd = 0;
my $result = "";
while (<FILE>) {
if (!$foundStart) {
- if (/^[[][{]$/) {
- $foundStart = 1;
- $result .= $_;
- }
- } else {
- if (/^[}][]]$/) {
- $foundEnd = 1;
- chomp;
- $result .= $_;
- last;
- } else {
- $result .= $_;
- }
- }
+ if (/^\[\{$/) {
+ $foundStart = 1;
+ $result .= $_;
+ } elsif (/^var \w+ = \[$/) {
+ $foundOutput = 1;
+ } elsif ($foundOutput && /^\{$/) {
+ $foundOutput = 0;
+ $foundStart = 1;
+ $result = "[{\n";
+ }
+ } else {
+ if (/\];?$/) {
+ $foundEnd = 1;
+ chomp;
+ s/;$//;
+ $result .= $_;
+ last;
+ } else {
+ $result .= $_;
+ }
+ }
}
close FILE;
sub dumpToFile($$)
{
my ($contents, $path) = @_;
- open FILE, ">$path";
+ open FILE, ">", $path or die;
print FILE $contents;
close FILE;
}
dumpToFile($output, "tmp/sunspider-comparison-data.js");
-my $jsShellPath = "/Users/mjs/Work/symroots/Release/testkjs";
-
-system("$jsShellPath", "-f", "tmp/sunspider-test-prefix.js", "-f", "tmp/sunspider-comparison-data.js", "-f", "resources/sunspider-compare-results.js");
-
-
+system($jsShellPath, "-f", "tmp/sunspider-test-prefix.js", "-f", "tmp/sunspider-comparison-data.js", "-f", "resources/sunspider-compare-results.js");