chiark / gitweb /
numbered-alias-sheet: wip, run generator test
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 30 Oct 2013 22:04:34 +0000 (22:04 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 3 Nov 2013 15:26:44 +0000 (15:26 +0000)
numbered-alias-sheet

index ef9e2bb12ca59b3dbe52424bea00dcc695ec127f..daac81648895cfe5292e0dcc8db1790b72e8ed06 100755 (executable)
@@ -3,18 +3,19 @@ use strict;
 our $us = $0; $us =~ s#.*/##;
 
 our $papersize =  'creditcard';
-our $fontsize = 10;
-our $font = 'Courier';
+our $count = 10;
+our $fontname = 'Courier';
 
 our $usage = <<END;
 usage: $us [<options>] <foo-mail-pregen> <foo-mail-pregen-opts>...
 options:
-  -p<papersize>     default is $papersize  (for libpaper, or "creditcard")
-  -f<fontsize>      default is ${fontsize}pt
-  -F<font>          default is $font
+  -p<papersize>     for libpaper, or "creditcard"  default is $papersize
+  -F<font>          font name                      default is $fontname
 END
 
-our $paperx, $papery;
+our @paperpts;
+
+sub badusage () { die "bad usage\n\n$usage"; }
 
 for (;;) {
     badusage unless @ARGV;
@@ -24,17 +25,41 @@ for (;;) {
     while (m/^-./) {
        if (s/^-p(\w+)$//) {
            $papersize = $1;
-       } elsif (s/^-f([0-9]+)$//) {
-           eval { $fontsize = $1 
+       } elsif (s/^-n(\d{1,2})$//) {
+           $count = 1;
+       } elsif (s/^-F([^()\\]+)$//) {
+           $fontname = $1;
+       } else {
+           badusage;
+       }
+    }
+}
+
+if ($papersize eq 'creditcard') {
+    # ISO/IEC 7810 ID-1, from en.wikipedia.org/wiki/Payment_card
+    @paperpts = map { $_ * 72.0 / 25.4 } qw(85.60 53.98);
+} else {
+    $!=0; $?=0; my $r = `paperconf -sp $1`;
+    defined $r or die "paperconf failed: $? $!\n";
+    $r =~ m/^([0-9.]+) ([0-9.]+)$/ or die "$_ ?";
+    @paperpts = ($1,$2);
+}
+
+@ARGV >= 2 or badusage;
+
+our @strings;
+
+our $nlen = 0;
 
-       } elsif (s/^-pcreditcard$//) {
+open P, "-|", @ARGV or die $!;
+while (<P>) {
+    chomp or die;
+    m/^(\d+) (\S+)$/ or die "$_ ?";
+    $nlen = length($1) if length($1) > $nlen;
+    push @strings, [ $1, $2 ];
+}
+$!=0; $?=0; close P or die "$us: generator failed: $! $?\n";
 
+$_ = sprintf "%${nlen}s %s", @$_ foreach @strings;
 
-           my $
-           $!=0; $?=0; my $r = `paperconf -sp $1`;
-           defined $r or die "paperconf failed: $? $!\n";
-           $r =~ m/^([0-9.]+) ([0-9.]+)$/ or die "$_ ?";
-       
-p
-while (@ARGV && $ARGV[0] =~ m/^-/) {
-    
+print $_,"\n" or die $! foreach @strings;