summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2013-01-24 03:14:17 +0100
committerGuillem Jover <guillem@debian.org>2013-11-24 05:54:26 +0100
commit9a1e6db62b37c76f609e012ae4e86018def587de (patch)
tree6509c7a7bdbc287f8b79dd9e17534835ddfdf226
parent4b8be5b817eed7950010192f83afc544d5f688cd (diff)
downloaddpkg-9a1e6db62b37c76f609e012ae4e86018def587de.tar.gz
Dpkg::ErrorHandling: Move syntaxerr to Dpkg::Control::HashCore::parse_error
This places the function where it belongs.
-rw-r--r--scripts/Dpkg/Control/HashCore.pm43
-rw-r--r--scripts/Dpkg/Control/Info.pm8
-rw-r--r--scripts/Dpkg/ErrorHandling.pm11
3 files changed, 38 insertions, 24 deletions
diff --git a/scripts/Dpkg/Control/HashCore.pm b/scripts/Dpkg/Control/HashCore.pm
index 51cfc5a33..009eb1012 100644
--- a/scripts/Dpkg/Control/HashCore.pm
+++ b/scripts/Dpkg/Control/HashCore.pm
@@ -18,7 +18,7 @@ package Dpkg::Control::HashCore;
use strict;
use warnings;
-our $VERSION = '1.00';
+our $VERSION = '1.01';
use Dpkg::Gettext;
use Dpkg::ErrorHandling;
@@ -157,6 +157,19 @@ sub get_option {
Parse the content of $file. Exits in case of errors. Returns true if some
fields have been parsed.
+=item $c->parse_error($file, $fmt, ...)
+
+Prints an error message and dies on syntax parse errors.
+
+=cut
+
+sub parse_error {
+ my ($self, $file, $msg) = (shift, shift, shift);
+
+ $msg = sprintf($msg, @_) if (@_);
+ error(_g('syntax error in %s at line %d: %s'), $file, $., $msg);
+}
+
=item $c->parse($fh, $description)
Parse a control file from the given filehandle. Exits in case of errors.
@@ -183,7 +196,7 @@ sub parse {
$parabody = 1;
if (exists $self->{$1}) {
unless ($$self->{allow_duplicate}) {
- syntaxerr($desc, sprintf(_g('duplicate field %s found'), $1));
+ $self->parse_error($desc, _g('duplicate field %s found'), $1);
}
}
$self->{$1} = $2;
@@ -191,7 +204,7 @@ sub parse {
} elsif (m/^\s(\s*\S.*)$/) {
my $line = $1;
unless (defined($cf)) {
- syntaxerr($desc, _g('continued value line not in field'));
+ $self->parse_error($desc, _g('continued value line not in field'));
}
if ($line =~ /^\.+$/) {
$line = substr $line, 1;
@@ -205,19 +218,19 @@ sub parse {
last if m/^\s*$/;
}
} else {
- syntaxerr($desc, _g('PGP signature not allowed here'));
+ $self->parse_error($desc, _g('PGP signature not allowed here'));
}
} elsif (m/^$/ || ($expect_pgp_sig && m/^-----BEGIN PGP SIGNATURE-----$/)) {
if ($expect_pgp_sig) {
# Skip empty lines
$_ = <$fh> while defined($_) && $_ =~ /^\s*$/;
length($_) ||
- syntaxerr($desc, _g('expected PGP signature, found EOF ' .
- 'after blank line'));
+ $self->parse_error($desc, _g('expected PGP signature, ' .
+ 'found EOF after blank line'));
s/\s*\n$//;
unless (m/^-----BEGIN PGP SIGNATURE-----$/) {
- syntaxerr($desc, sprintf(_g('expected PGP signature, ' .
- "found something else \`%s'"), $_));
+ $self->parse_error($desc, _g('expected PGP signature, ' .
+ "found something else \`%s'"), $_);
}
# Skip PGP signature
while (<$fh>) {
@@ -225,7 +238,7 @@ sub parse {
last if m/^-----END PGP SIGNATURE-----$/;
}
unless (defined($_)) {
- syntaxerr($desc, _g('unfinished PGP signature'));
+ $self->parse_error($desc, _g('unfinished PGP signature'));
}
# This does not mean the signature is correct, that needs to
# be verified by gnupg.
@@ -233,13 +246,13 @@ sub parse {
}
last; # Finished parsing one block
} else {
- syntaxerr($desc,
- _g('line with unknown format (not field-colon-value)'));
+ $self->parse_error($desc,
+ _g('line with unknown format (not field-colon-value)'));
}
}
if ($expect_pgp_sig and not $$self->{is_pgp_signed}) {
- syntaxerr($desc, _g('unfinished PGP signature'));
+ $self->parse_error($desc, _g('unfinished PGP signature'));
}
return defined($cf);
@@ -503,6 +516,12 @@ sub NEXTKEY {
=back
+=head1 CHANGES
+
+=head2 Version 1.01
+
+New method: parse_error().
+
=head1 AUTHOR
Raphaƫl Hertzog <hertzog@debian.org>.
diff --git a/scripts/Dpkg/Control/Info.pm b/scripts/Dpkg/Control/Info.pm
index 1ca2580ee..03875b0dc 100644
--- a/scripts/Dpkg/Control/Info.pm
+++ b/scripts/Dpkg/Control/Info.pm
@@ -100,17 +100,19 @@ sub parse {
return if not $cdata->parse($fh, $desc);
$self->{source} = $cdata;
unless (exists $cdata->{Source}) {
- syntaxerr($desc, _g('first block lacks a source field'));
+ $cdata->parse_error($desc, _g('first block lacks a source field'));
}
while (1) {
$cdata = Dpkg::Control->new(type => CTRL_INFO_PKG);
last if not $cdata->parse($fh, $desc);
push @{$self->{packages}}, $cdata;
unless (exists $cdata->{Package}) {
- syntaxerr($desc, _g("block lacks the '%s' field"), 'Package');
+ $cdata->parse_error($desc, _g("block lacks the '%s' field"),
+ 'Package');
}
unless (exists $cdata->{Architecture}) {
- syntaxerr($desc, _g("block lacks the '%s' field"), 'Architecture');
+ $cdata->parse_error($desc, _g("block lacks the '%s' field"),
+ 'Architecture');
}
}
diff --git a/scripts/Dpkg/ErrorHandling.pm b/scripts/Dpkg/ErrorHandling.pm
index f9aeeef81..62b5be2dc 100644
--- a/scripts/Dpkg/ErrorHandling.pm
+++ b/scripts/Dpkg/ErrorHandling.pm
@@ -16,14 +16,14 @@ package Dpkg::ErrorHandling;
use strict;
use warnings;
-our $VERSION = '0.01';
+our $VERSION = '0.02';
use Dpkg ();
use Dpkg::Gettext;
use Exporter qw(import);
our @EXPORT = qw(report_options info warning error errormsg
- syserr internerr subprocerr usageerr syntaxerr);
+ syserr internerr subprocerr usageerr);
our @EXPORT_OK = qw(report);
my $quiet_warnings = 0;
@@ -109,11 +109,4 @@ sub usageerr(@)
exit(2);
}
-sub syntaxerr {
- my ($file, $msg) = (shift, shift);
-
- $msg = sprintf($msg, @_) if (@_);
- error(_g('syntax error in %s at line %d: %s'), $file, $., $msg);
-}
-
1;