From 3470d4d118e79d5ec6bac11706e59d26a2596cd1 Mon Sep 17 00:00:00 2001 From: Raphael Hertzog Date: Sun, 1 Jun 2008 12:07:17 +0200 Subject: [PATCH] dpkg-gencontrol: accept "-c-" to read the control file from stdin * scripts/Dpkg/Control.pm (parse, parse_fh, new): Add a new function parse_fh() to be able to parse the control file from an arbitrary file handle. Change parse() to use it and modify new() to parse STDIN instead of a real file if the parameter is "-". --- ChangeLog | 7 +++++++ debian/changelog | 2 ++ scripts/Dpkg/Control.pm | 31 ++++++++++++++++++++++--------- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3da94553..f0bcd2c2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-06-01 Raphael Hertzog + + * scripts/Dpkg/Control.pm (parse, parse_fh, new): Add a new function + parse_fh() to be able to parse the control file from an arbitrary + file handle. Change parse() to use it and modify new() to parse + STDIN instead of a real file if the parameter is "-". + 2008-06-01 Daniel Hahler * src/archives.c (tarobject): Improve error message stating that diff --git a/debian/changelog b/debian/changelog index 26c5271a..1194fdf2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -23,6 +23,8 @@ dpkg (1.15.0) UNRELEASED; urgency=low * Improve error message stating that dpkg is unable to create a file so that it also refers to the real filename instead of the non-diverted name only. Thanks to Daniel Hahler for the patch. Closes: #457135 + * dpkg-gencontrol can now again read the control file from its standard + input with "-c-". Closes: #465340 [ Pierre Habouzit ] * Add a --query option to update-alternatives. Closes: #336091, #441904 diff --git a/scripts/Dpkg/Control.pm b/scripts/Dpkg/Control.pm index b9e4c941..fd0c27ec 100644 --- a/scripts/Dpkg/Control.pm +++ b/scripts/Dpkg/Control.pm @@ -39,7 +39,7 @@ syntax than debian/control. =item $c = Dpkg::Control->new($file) Create a new Dpkg::Control object for $file. If $file is omitted, it parses -debian/control. +debian/control. If file is "-", it parses the standard input. =cut sub new { @@ -51,7 +51,11 @@ sub new { }; bless $self, $class; if ($arg) { - $self->parse($arg); + if ($arg eq "-") { + $self->parse_fh(\*STDIN); + } else { + $self->parse($arg); + } } else { $self->parse("debian/control"); } @@ -76,24 +80,33 @@ Parse the content of $file. Exits in case of errors. =cut sub parse { my ($self, $file) = @_; - $self->reset(); - # Parse open(CDATA, "<", $file) || syserr(_g("cannot read %s"), $file); - my $cdata = parsecdata(\*CDATA, $file); + $self->parse_fh(\*CDATA); + close(CDATA); +} + +=item $c->parse_fh($fh) + +Parse a control file from the given filehandle. Exits in case of errors. + +=cut +sub parse_fh { + my ($self, $fh) = @_; + $self->reset(); + my $cdata = parsecdata($fh, _g("standard input")); return if not defined $cdata; $self->{source} = $cdata; unless (exists $cdata->{Source}) { - syntaxerr($file, _g("first block lacks a source field")); + syntaxerr(_g("standard input"), _g("first block lacks a source field")); } while (1) { - $cdata = parsecdata(\*CDATA, $file); + $cdata = parsecdata($fh, _g("standard input")); last if not defined $cdata; push @{$self->{packages}}, $cdata; unless (exists $cdata->{Package}) { - syntaxerr($file, _g("block lacks a package field")); + syntaxerr(_g("standard input"), _g("block lacks a package field")); } } - close(CDATA); } =item $c->get_source() -- 2.39.5