X-Git-Url: https://git.distorted.org.uk/~mdw/distorted-bits/blobdiff_plain/2920e7ba11655d5849763f79633130f2858685fc..HEAD:/mkaptsrc diff --git a/mkaptsrc b/mkaptsrc index 684f964..102d598 100755 --- a/mkaptsrc +++ b/mkaptsrc @@ -112,9 +112,8 @@ sub cset_lookup (\@$$;$) { last CSET if defined $val; } if (defined $val) { - $PAINT{$tag} = 1; + local $PAINT{$tag} = 1; my $exp = cset_expand @$cset, $ix, $val; - $PAINT{$tag} = 0; return $exp; } elsif ($mustp) { fail "variable `$tag\[$ix]' undefined"; } else { return undef; } @@ -164,14 +163,14 @@ sub parse ($) { my $ln = 0; ## Report a syntax error, citing the offending file and line. - sub syntax { fail "$fn:$ln: $_[0]"; } + my $syntax = sub { fail "$fn:$ln: $_[0]" }; ## Report an error about an indented line with no stanza header. - sub nomode { syntax "missing stanza header" }; - my $mode = \&nomode; + my $nomode = sub { $syntax->("missing stanza header") }; + my $mode = $nomode; ## Parse an assignment LINE and store it in CSET. - sub assign { + my $assign = sub { my ($cset, $line) = @_; $line =~ m{ ^ \s* @@ -180,19 +179,19 @@ sub parse ($) { \s* = \s* (?P | \S | \S.*\S) \s* $ - }x or syntax "invalid assignment"; + }x or $syntax->("invalid assignment"); cset_store $cset, $+{TAG}, $+{IX} // "*", $+{VALUE}; - } + }; ## Parse a subscription LINE and store it in @SUB. - sub subscribe { + my $subscribe = sub { my ($line) = @_; my @w = shellwords $line; my @dist = (); while (my $w = shift @w) { last if $w eq ":"; push @dist, $w; } - @w and @dist or syntax "empty distribution or release list"; + @w and @dist or $syntax->("empty distribution or release list"); push @SUB, [\@dist, \@w]; - } + }; for (;;) { @@ -212,19 +211,19 @@ sub parse ($) { ## Split the header line into tokens and determine an action. my @w = shellwords $line; - $mode = \&nomode; + $mode = $nomode; if ($w[0] eq "distribution") { - @w == 2 or syntax "usage: distribution NAME"; + @w == 2 or $syntax->("usage: distribution NAME"); my $cset = $CSET{$w[1]} //= cset_new; - $mode = sub { assign $cset, @_ }; + $mode = sub { $assign->($cset, @_) }; } elsif ($w[0] eq "default") { - @w == 1 or syntax "usage: default"; - $mode = sub { assign \%DEFAULT, @_ }; + @w == 1 or $syntax->("usage: default"); + $mode = sub { $assign->(\%DEFAULT, @_) }; } elsif ($w[0] eq "subscribe") { - @w == 1 or syntax "usage: subscribe"; - $mode = \&subscribe; + @w == 1 or $syntax->("usage: subscribe"); + $mode = $subscribe; } else { - syntax "unknown toplevel directive `$w[0]'"; + $syntax->("unknown toplevel directive `$w[0]'"); } } @@ -327,7 +326,7 @@ for my $pair (@SUB) { ## Build an output line. my $out = ""; - defined (my $opt = $a{options}) and $out .= "[ $opt ] "; + if (defined (my $opt = $a{options})) { $out .= "[ $opt ] "; } $out .= "$a{uri} $a{release} $a{components}"; ## Canonify whitespace.