]> git.donarmstrong.com Git - infobot.git/commitdiff
Use newunits
authordondelelcaro <dondelelcaro@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 10 Jun 2006 22:36:49 +0000 (22:36 +0000)
committerdondelelcaro <dondelelcaro@c11ca15a-4712-0410-83d8-924469b57eb5>
Sat, 10 Jun 2006 22:36:49 +0000 (22:36 +0000)
git-svn-id: https://svn.code.sf.net/p/infobot/code/branches/don/dpkg@1288 c11ca15a-4712-0410-83d8-924469b57eb5

src/CommandStubs.pl
src/Modules/NewUnits.pl [new file with mode: 0644]

index 00e1ebab8a99aa879832cb1f75762d6e7ed919d3..37f918104602f2ffd25a78a94e6a49185be4309f 100644 (file)
@@ -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 (file)
index 0000000..2e4f25f
--- /dev/null
@@ -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;