2007-05-20 22:44:44 +02:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
|
|
|
# Quick and dirty by :pragma
|
|
|
|
|
2014-03-24 03:25:37 +01:00
|
|
|
my ($arguments, $response, $invalid);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2014-03-24 03:25:37 +01:00
|
|
|
my @valid_keywords = (
|
|
|
|
'sin', 'cos', 'tan', 'atan', 'exp', 'int', 'hex', 'oct', 'log', 'sqrt',
|
|
|
|
'floor', 'ceil', 'asin', 'acos', 'log10', 'sinh', 'cosh', 'tanh', 'abs',
|
2015-01-23 22:40:33 +01:00
|
|
|
'pi', 'deg2rad', 'rad2deg', 'atan2', 'cbrt'
|
2014-03-24 03:25:37 +01:00
|
|
|
);
|
2007-05-20 22:44:44 +02:00
|
|
|
|
|
|
|
if ($#ARGV < 0)
|
|
|
|
{
|
|
|
|
print "Dumbass.\n";
|
2014-03-24 03:25:37 +01:00
|
|
|
exit 0;
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
|
|
|
|
2014-03-24 03:25:37 +01:00
|
|
|
$arguments = join(' ', @ARGV);
|
2014-08-13 18:55:04 +02:00
|
|
|
my $orig_arguments = $arguments;
|
|
|
|
|
2015-01-23 22:40:33 +01:00
|
|
|
$arguments =~ s/(the )*answer.*question of life(,? the universe and everything)?\s?/42/gi;
|
2014-08-13 18:55:04 +02:00
|
|
|
$arguments =~ s/meaning of (life|existence|everything)?/42/gi;
|
2007-05-20 22:44:44 +02:00
|
|
|
|
2014-08-31 22:27:40 +02:00
|
|
|
if($arguments =~ m/([\$`\|{}"'#@=?\[\]])/ or $arguments =~ m/(~~)/) {
|
2014-03-24 03:25:37 +01:00
|
|
|
$invalid = $1;
|
|
|
|
} else {
|
2014-03-24 04:05:48 +01:00
|
|
|
while($arguments =~ /([a-zA-Z0-9]+)/g) {
|
2014-03-24 03:25:37 +01:00
|
|
|
my $keyword = $1;
|
2014-03-24 04:10:08 +01:00
|
|
|
next if $keyword =~ m/^[0-9]+$/;
|
2014-03-24 03:25:37 +01:00
|
|
|
$invalid = $keyword and last if not grep { /^$keyword$/ } @valid_keywords;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($invalid) {
|
|
|
|
print "Illegal symbol '$invalid' in equation\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2014-03-24 04:05:48 +01:00
|
|
|
$response = eval("use POSIX qw/ceil floor/; use Math::Trig; use Math::Complex;" . $arguments);
|
2014-03-24 03:25:37 +01:00
|
|
|
|
|
|
|
if($@) {
|
|
|
|
my $error = $@;
|
|
|
|
$error =~ s/[\n\r]+//g;
|
2014-04-26 17:22:46 +02:00
|
|
|
$error =~ s/ at \(eval \d+\) line \d+.//;
|
|
|
|
$error =~ s/ at EOF$//;
|
2014-03-24 04:05:48 +01:00
|
|
|
$error =~ s/Died at .*//;
|
2014-03-24 03:25:37 +01:00
|
|
|
print $error;
|
|
|
|
exit 1;
|
2007-05-20 22:44:44 +02:00
|
|
|
}
|
|
|
|
|
2014-08-13 18:55:04 +02:00
|
|
|
print "$orig_arguments = $response\n";
|