X-Git-Url: http://git.shiar.net/descalc.git/blobdiff_plain/4e1d9535fda6685e53ce570ca4e4cd6c260f55d3..090ac304afe801cb3e72ced0941ff2a874a98cc9:/35_unitconv.pm diff --git a/35_unitconv.pm b/35_unitconv.pm index 3cf2540..2cb181f 100644 --- a/35_unitconv.pm +++ b/35_unitconv.pm @@ -1,5 +1,8 @@ # unit convertor for DCT, by Shiar +# 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 @@ -13,14 +16,14 @@ 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 @$_; @@ -190,6 +193,8 @@ do { ['bit', 1/8, "bit/octet"], ['Mbit', 1024**2/8, "megabit"], ['LOC', 19e12, 'Library of Congress'], # est. 17-20TB + ['CD', 735e6, 'max CD-ROM data'], + ['DVD', 47e8, 'max DVD-ROM data'], ], ); # units table @@ -198,10 +203,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}; - redraw(1); + $stack[0] -= $_->{diff} if $_->{diff}; + redraw(stack=>1); undef %val; } # convert else { @@ -218,6 +223,6 @@ push @{$hook{postentry}}, sub { return { author => "Shiar", title => "unit convertor", - version => "1.11", + version => "1.14", };