Преглед изворни кода

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 "-".
Raphael Hertzog пре 18 година
родитељ
комит
3470d4d118
3 измењених фајлова са 31 додато и 9 уклоњено
  1. 7 0
      ChangeLog
  2. 2 0
      debian/changelog
  3. 22 9
      scripts/Dpkg/Control.pm

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2008-06-01  Raphael Hertzog  <hertzog@debian.org>
+
+	* 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  <debian-bugs@thequod.de>
 
 	* src/archives.c (tarobject): Improve error message stating that

+ 2 - 0
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

+ 22 - 9
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()