chiark / gitweb /
pregen: wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 27 Oct 2013 20:12:36 +0000 (20:12 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 3 Nov 2013 15:26:23 +0000 (15:26 +0000)
evade-mail-pregen

index a3754375ba105b019309117db186015661ad2f53..9fcafc66fbbc2e93ac8857192cea01cde14782a7 100755 (executable)
@@ -45,7 +45,7 @@ sub comment_make ($) {
 
 sub run_generator {
     my @genargs = @_;
-    open P, "-!", $generator, @genargs or fail "fork $generator: $!";
+    open P, "-|", $generator, @genargs or fail "fork $generator: $!";
     while (<P>) {
        my ($alias,$comment);
        if (m/^\# user/) {
@@ -70,6 +70,7 @@ sub run_generator {
            $by_number[$row->{Number}] = $row;
            $min_number = $row->{Number} if
                (!defined $min_number) || $min_number > $row->{Number};
+       }
     }
     $?=0; $!=0; close P or fail "$generator $genargs[0] failed ($! $?)\n";
 }
@@ -126,8 +127,8 @@ $us: Losing track of next number ($wanted), due to use of -N;
 $us: will start next alias at #0, unless you say (e.g.) "range $wanted".
 END
     }
-    exec $generator, qw(update), $target->{Alias}, @ARGV;
-    fail "exec $generator: $!";
+    exec $generator, qw(update), $target->{Alias}, @ARGV
+       or fail "exec $generator: $!";
 }
 
 sub action_assign {
@@ -185,12 +186,12 @@ for (;;) {
     last unless $ARGV[0] =~ m/^-/;
     my $arg = shift @ARGV;
     last if $arg =~ m/^--?$/;
-    while ($arg !~ m/^-$/) {
+    while ($arg =~ m/^-./) {
        if ($arg =~ s/^-[ldFm]/-/) {
            push @genopts, $arg;
-       } elsif ($arg =~ s/^-G//) {
-           $generator = $'; #';
-       } elsif ($arg =~ s/^-N//) {
+       } elsif ($arg =~ s/^-G(.*)//) {
+           $generator = $1;
+       } elsif ($arg =~ s/^-N/-/) {
            $no_generate = 1;
        } else {
            badusage "unknown option \`$arg'";
@@ -209,16 +210,18 @@ $comment_pattern =~ m/^#/s
     or badusage "comment pattern must start with \`#'";
 $comment_re = $comment_pattern;
 $comment_re =~ s/\W/\\$&/g;
-($comment_re =~ s'\<number\>'([1-9]\d{0,8})'g) == 1 #'
-    or badusage "comment pattern must contain \`<number>' exactly once";
+($comment_re =~ s'\\<number\\>'([1-9]\d{0,8})'g) == 1 #'
+    or badusage "comment pattern (\`$comment_pattern')".
+         " must contain \`<number>' exactly once";
 
-@ARGV or badusage "missing action\n";
+@ARGV or badusage "missing action";
 my $action = shift @ARGV;
 
 fetch_list();
 
 $action =~ y/-/_/;
-my $actionsub = { no strict qw(refs); \&{"action_$action"}; }
+my $actionsub;
+{ no strict qw(refs); $actionsub = \&{"action_$action"}; }
 defined $actionsub or badusage "unknown action $action";
 $actionsub->();