From 09a07f14a09400eb6f5a98110097f3651cc55f7e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 25 Jan 2011 14:14:25 +0000 Subject: [PATCH] canon: break out alencodenum --- yarrg/canon | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/yarrg/canon b/yarrg/canon index 529a314..e70e646 100755 --- a/yarrg/canon +++ b/yarrg/canon @@ -21,18 +21,24 @@ foreach my $ab (qw(0 1)) { my $nextcommod=0; my %commodmap; -sub findcommod ($) { - my ($cname) = @_; - my $me= $commodmap{$cname}; return $me if defined $me; - my $val= $nextcommod++; +sub alencodenum ($) { + my ($val) = @_; my $res= ''; while ($val || !length($res)) { my $dig= $val % 62; $val= ($val-$dig) / 62; - $res .= chr($dig + ($dig<10 ? 48 : - $dig<36 ? 97-10 : - $dig<62 ? 65-36 : die $dig)); + $res = chr($dig + ($dig<10 ? 48 : + $dig<36 ? 97-10 : + $dig<62 ? 65-36 : die $dig)) . $res; } + return $res; +} + +sub findcommod ($) { + my ($cname) = @_; + my $me= $commodmap{$cname}; return $me if defined $me; + my $val= $nextcommod++; + my $res= alencodenum($val); $commodmap{$cname}= $res; # printf "%s:%s\n", $res,$cname; return $res; -- 2.30.2