X-Git-Url: http://git.shiar.nl/descalc.git/blobdiff_plain/7d9af85556b0e64c70e3641764b7b49a306723f3..HEAD:/35_unitconv.pm diff --git a/35_unitconv.pm b/35_unitconv.pm index 1374ccf..a460774 100644 --- a/35_unitconv.pm +++ b/35_unitconv.pm @@ -1,24 +1,30 @@ # unit convertor for DCT, by Shiar -# 1.09.1 200410022305 - moved %unit specs from 1.9 main -# 1.09.2 200410112205 - all code moved here as well +# 1.14.1 200701310504 - exact cd/dvd size +# 1.14.0 200501261830 - units can have different offsets, so we can convert ^C/^F +# 1.13.1 200501071420 - added cd/dvd sizes to data storage +# 1.13.0 200411042100 - changed calls addmenu() and redraw() +# 1.11.0 200410291000 - use redraw() +# 1.10.5 200410151900 - data storage units (8 total, including LOC) +# 1.10.4 200410132300 - hp49 units for mass +# 1.10.3 200410130000 - fix error when run without menu module +# 1.10.2 200410122200 - adds submenus with all units # 1.10.1 200410122030 - hp49 units for area, volume, time, speed, force, energy, power -# .2 2200 - adds submenus with all units -# .3 10130000 - fix error when run without menu module -# .4 10132300 - hp49 units for mass +# 1.09.2 200410112205 - all code moved here as well +# 1.09.1 200410022305 - moved %unit specs from 1.9 main use strict; use warnings; use utf8; -my $menugroup = addmenu(["main", 0], "unit") if defined &addmenu; +addmenu("main", "unit"); my %unit; # unit table (build below) my $i = 0; # unit group counter (temporary) do { $i++; # next group my $title = shift @$_; # first element is group title, no unit - addmenu(["unit", $menugroup], $title, map "_$_->[0]", @$_) if defined &addmenu; + addmenu("unit", $title, map "_$_->[0]", @$_); $unit{$_->[0]} = { type=>$i, name=>$_->[0], val=>$_->[1], desc=>$_->[2], diff=>$_->[3] } for @$_; @@ -177,6 +183,20 @@ do { # [], # light # [], # radiation # [], # viscosity + + [ + "data storage", # memory + ['B', 1, "byte"], + ['kB', 1024, "kilobyte"], + ['MB', 1024**2, "megabyte"], + ['GB', 1024**3, "gigabyte"], + ['TB', 1024**4, "terabyte"], + ['bit', 1/8, "bit/octet"], + ['Mbit', 1024**2/8, "megabit"], + ['LOC', 19e12, 'Library of Congress'], # est. 17-20TB + ['CD', 359_847*2048, 'max CD-ROM (700MB) data'], + ['DVD', 2_295_104*2048, 'max DVD-ROM data'], + ], ); # units table push @{$hook{precmd}}, sub { @@ -184,10 +204,10 @@ push @{$hook{precmd}}, sub { $_ = $unit{substr $_, 1} or next; if (exists $val{unit} and $val{unit}{type}==$_->{type}) { unshift @stack, $val{i} if defined $val{i}; -# $stack[0] -= $_->{diff} if $_->{diff}; -# $stack[0] += $val{unit}{diff}*$val{unit}{val}/$_->{val} if $val{unit}{diff}; + $stack[0] += $val{unit}{diff} if $val{unit}{diff}; $stack[0] *= delete($val{unit})->{val} / $_->{val}; - showstack(); + $stack[0] -= $_->{diff} if $_->{diff}; + redraw(stack=>1); undef %val; } # convert else { @@ -204,6 +224,6 @@ push @{$hook{postentry}}, sub { return { author => "Shiar", title => "unit convertor", - version => "1.10.4", + version => "1.14.01", };