From 1d1a175a96a95664e644ca0253b9bbc9a8d3932b Mon Sep 17 00:00:00 2001 From: dondelelcaro Date: Sat, 10 Jun 2006 22:36:49 +0000 Subject: [PATCH] Use newunits git-svn-id: https://svn.code.sf.net/p/infobot/code/branches/don/dpkg@1288 c11ca15a-4712-0410-83d8-924469b57eb5 --- src/CommandStubs.pl | 4 ++-- src/Modules/NewUnits.pl | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Modules/NewUnits.pl diff --git a/src/CommandStubs.pl b/src/CommandStubs.pl index 00e1eba..37f9181 100644 --- a/src/CommandStubs.pl +++ b/src/CommandStubs.pl @@ -453,7 +453,7 @@ sub convert { return; } - &Units::convertUnits($from, $to); + &NewUnits::convertUnits($from, $to); return; } @@ -852,7 +852,7 @@ sub nullski { &addCmdHook('bzfquery', ('CODEREF' => 'BZFlag::query', 'Identifier' => 'BZFlag', 'Cmdstats' => 'BZFlag', 'Forker' => 1, 'Module' => 'BZFlag') ); &addCmdHook('chan(stats|info)', ('CODEREF' => 'chaninfo', ) ); &addCmdHook('cmd(stats|info)', ('CODEREF' => 'cmdstats', ) ); -&addCmdHook('convert', ('CODEREF' => 'convert', 'Forker' => 1, 'Identifier' => 'Units', 'Help' => 'convert') ); +&addCmdHook('convert', ('CODEREF' => 'convert', 'Forker' => 1, 'Identifier' => 'NewUnits', 'Help' => 'convert') ); &addCmdHook('(cookie|random)', ('CODEREF' => 'cookie', 'Forker' => 1, 'Identifier' => 'Factoids') ); &addCmdHook('countdown', ('CODEREF' => 'countdown', 'Module' => 'countdown', 'Identifier' => 'countdown', 'Cmdstats' => 'countdown') ); &addCmdHook('countrystats', ('CODEREF' => 'countryStats') ); diff --git a/src/Modules/NewUnits.pl b/src/Modules/NewUnits.pl new file mode 100644 index 0000000..2e4f25f --- /dev/null +++ b/src/Modules/NewUnits.pl @@ -0,0 +1,31 @@ +# Units.pl: convert units of measurement +# Author: M-J. Dominus (mjd-perl-units-id-iut+buobvys+@plover.com) +# License: GPL, Copyright (C) 1996,1999 +# NOTE: Integrated into blootbot by xk. + +package NewUnits; + +#use strict; # TODO + + +sub convertUnits { + my ($from,$to) = @_; + + if ($from =~ /([+-]?[\d\.]+(?:e[+-]?[\d]+)?)\s+(temp[CFK])/){ + $from = qq|${2}(${1})|; + } + + my $units = new IO::File; + open $units, '-|', 'units', $from, $to or &::DEBUG("Unable to run units: $!") and return; + my $response = readline ($units); + if ($response =~ /\s+\*\s+([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/ or $response =~ /\t([+-]?[\d\.]+(?:e[+-]?[\d]+)?)/){ + &::performStrictReply(sprintf("$from is approximately \002%.6g\002 $to", $1)); + } + else { + &::performStrictReply("$from cannot be converted to ${to}: $response"); + } + return; +} + + +1; -- 2.39.5