#!/usr/bin/perl -w # Copyright 2001 Bjorn Bringert # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use strict; my $f = $ARGV[0]; my $o; if ($f =~ /\.java$/){ $o = java($f); }elsif ($f =~ /\.hs$/){ $o = haskell($f); }elsif ($f =~ /\.c$/){ $o = c($f); }elsif ($f =~ /\.pl$/){ $o = perl($f); }elsif (-x $f){ $o = run($f); }else{ die "Unknown program type." } my $p = `cat $f`; if ($o eq $p){ print "quine, ".(length $o)." characters\n"; }else{ print "Not quine\ncode:\n'$p'\noutput:\n'$o'\n"; } sub toAbsolute{ $_[0] =~ s/^([^\/].*)/.\/$1/; return $_[0]; } sub java{ (my $c = $_[0]) =~ s/\.java//; system("javac $_[0]"); return `java $c`; } sub haskell{ return `runhugs $_[0]`; } sub c{ (my $c = $_[0]) =~ s/\.c//; system("gcc -o $c $_[0]"); return `./$c`; } sub perl{ return `perl $_[0]`; } sub run{ my $c = toAbsolute($_[0]); return `$c`; }