) { $format = $1 if m/\schangelog-format:\s+([0-9a-z]+)\W/; } close(P) or subprocerr(_g("tail of %s"), $changelogfile); } # Find the right changelog parser my $parser; foreach my $dir (@parserpath) { my $candidate = "$dir/$format"; next if not -e $candidate; if (-x _) { $parser = $candidate; last; } else { warning(_g("format parser %s not executable"), $candidate); } } error(_g("changelog format %s is unknown"), $format) if not defined $parser; # Create the arguments for the changelog parser my @exec = ($parser, "-l$changelogfile"); foreach (keys %options) { if (m/^-/) { # Options passed untouched push @exec, $_; } else { # Non-options are mapped to long options push @exec, "--$_"; } push @exec, $options{$_} if defined($options{$_}); } # Fork and call the parser my $pid = open(P, "-|"); syserr(_g("cannot fork for %s"), $parser) unless defined $pid; if (not $pid) { if ($changelogfile ne "-") { open(STDIN, "<", $changelogfile) or syserr(_g("cannot open %s"), $changelogfile); } exec(@exec) || syserr(_g("cannot exec format parser: %s"), $parser); } # Get the output into several Dpkg::Control objects my (@res, $fields); while (1) { $fields = Dpkg::Control::Changelog->new(); last unless $fields->parse(\*P, _g("output of changelog parser")); push @res, $fields; } close(P) or subprocerr(_g("changelog parser %s"), $parser); if (wantarray) { return @res; } else { return $res[0] if (@res); return undef; } } 1;