chiark / gitweb /
canon: break out alencodenum
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 25 Jan 2011 14:14:25 +0000 (14:14 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 25 Jan 2011 14:14:25 +0000 (14:14 +0000)
yarrg/canon

index 529a314edfa2d5851fb750ae3caf67088e6b0ea1..e70e6467ab4011f80197d50e5899f898d8c7b582 100755 (executable)
@@ -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;