summaryrefslogtreecommitdiffstats
path: root/scripts/calc.pl
diff options
context:
space:
mode:
authorAlexander Færøy2014-05-31 13:10:46 +0200
committerAlexander Færøy2014-05-31 13:10:46 +0200
commit2d0759e6ca5767b48bcc85bf38c2c43d5f0b63b1 (patch)
tree1c5e6d817c88e67b46e216a50e0aef5428bf63df /scripts/calc.pl
parent2d080422d79d1fd49d6c5528593ccaaff9bfc583 (diff)
downloadscripts.irssi.org-2d0759e6ca5767b48bcc85bf38c2c43d5f0b63b1.tar.bz2
Import scripts from scripts.irssi.org
Diffstat (limited to 'scripts/calc.pl')
-rw-r--r--scripts/calc.pl30
1 files changed, 30 insertions, 0 deletions
diff --git a/scripts/calc.pl b/scripts/calc.pl
new file mode 100644
index 0000000..21aa7de
--- /dev/null
+++ b/scripts/calc.pl
@@ -0,0 +1,30 @@
+use strict;
+use vars qw($VERSION %IRSSI);
+
+use Irssi qw(command_bind active_win);
+$VERSION = '1.10';
+%IRSSI = (
+ authors => 'Juerd',
+ contact => 'juerd@juerd.nl',
+ name => 'Calculator',
+ description => 'Simple /calc mechanism',
+ license => 'Public Domain',
+ url => 'http://juerd.nl/irssi/',
+ changed => 'Thu Mar 19 11:00 CET 2002',
+);
+
+command_bind(
+ calc => sub {
+ my ($msg) = @_;
+ for ($msg) {
+ s/,/./g;
+ s/[^*.+0-9&|)(x\/^-]//g;
+ s/\*\*/^/g;
+ s/([*+\\.\/x-])\1*/$1/g;
+ s/\^/**/g;
+ s/(?<!0)x//g;
+ }
+ my $answer = eval("($msg) || 0");
+ active_win->print($@ ? "$msg = ERROR (${\ (split / at/, $@, 2)[0]})" : "$msg = $answer");
+ }
+);