summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorrillig <rillig@pkgsrc.org>2005-10-30 23:03:41 +0000
committerrillig <rillig@pkgsrc.org>2005-10-30 23:03:41 +0000
commit6e9dde0fd454c815eaba7039a7efb4126744eda2 (patch)
tree4a2462abf5c2f8d1a3e893d47f00fdf237dae725 /pkgtools
parent41fe22047cae51d7f33e1a5654cbeb6ba4470b2a (diff)
downloadpkgsrc-6e9dde0fd454c815eaba7039a7efb4126744eda2.tar.gz
Added three methods insert_before(), insert_after() and delete() to a
Pkglint::FileUtil::Line, which will be used for the --autofix option. No user-visible changes.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkglint/files/pkglint.pl46
1 files changed, 38 insertions, 8 deletions
diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl
index d98f0189249..619666dcc98 100644
--- a/pkgtools/pkglint/files/pkglint.pl
+++ b/pkgtools/pkglint/files/pkglint.pl
@@ -11,7 +11,7 @@
# Freely redistributable. Absolutely no warranty.
#
# From Id: portlint.pl,v 1.64 1998/02/28 02:34:05 itojun Exp
-# $NetBSD: pkglint.pl,v 1.309 2005/10/30 22:11:38 rillig Exp $
+# $NetBSD: pkglint.pl,v 1.310 2005/10/30 23:03:41 rillig Exp $
#
# This version contains lots of changes necessary for NetBSD packages
# done by:
@@ -210,6 +210,12 @@ BEGIN {
false true
);
}
+
+use constant FILE => 0;
+use constant LINES => 1;
+use constant TEXT => 2;
+use constant PHYSLINES => 3;
+use constant CHANGED => 4;
sub new($$$$) {
my ($class, $file, $lines, $text, $physlines) = @_;
@@ -218,31 +224,55 @@ sub new($$$$) {
return $self;
}
sub file($) {
- return shift(@_)->[0];
+ return shift(@_)->[FILE];
}
sub lineno($) {
- return shift(@_)->[1];
+ return shift(@_)->[LINES];
}
sub text($) {
- return shift(@_)->[2];
+ return shift(@_)->[TEXT];
}
sub log_error($$) {
my ($self, $text) = @_;
- PkgLint::Logging::log_error($self->file, $self->lineno, $text);
+ PkgLint::Logging::log_error($self->[FILE], $self->[LINES], $text);
}
sub log_warning($$) {
my ($self, $text) = @_;
- PkgLint::Logging::log_warning($self->file, $self->lineno, $text);
+ PkgLint::Logging::log_warning($self->[FILE], $self->[LINES], $text);
}
sub log_info($$) {
my ($self, $text) = @_;
- PkgLint::Logging::log_info($self->file, $self->lineno, $text);
+ PkgLint::Logging::log_info($self->[FILE], $self->[LINES], $text);
}
sub to_string($) {
my ($self) = @_;
- return sprintf("%s:%s: %s", $self->file, $self->lineno, $self->text);
+ return sprintf("%s:%s: %s", $self->[FILE], $self->[LINES], $self->[TEXT]);
+}
+
+sub insert_before($$) {
+ my ($self, $text) = @_;
+ unshift(@{$self->[PHYSLINES]}, [0, "$text\n"]);
+ $self->[CHANGED] = true;
+}
+sub insert_after($$) {
+ my ($self, $text) = @_;
+ push(@{$self->[PHYSLINES]}, [0, "$text\n"]);
+ $self->[CHANGED] = true;
+}
+sub delete($) {
+ my ($self) = @_;
+ my ($newlines) = ([]);
+
+ foreach my $line (@{$self->[PHYSLINES]}) {
+ if ($line->[0] == 0) {
+ push(@{$newlines}, $line);
+ }
+ }
+ $self->[PHYSLINES] = $newlines;
+ $self->[CHANGED] = true;
}
+
#== End of PkgLint::FileUtil::Line ========================================
package PkgLint::FileUtil;