diff options
author | rillig <rillig@pkgsrc.org> | 2006-01-27 00:07:07 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2006-01-27 00:07:07 +0000 |
commit | f871e64485cbdb243c30ebcc296b9c95c18888a8 (patch) | |
tree | e84a15afb1afba163b8c39cfd55e71729956aa84 /pkgtools | |
parent | 9d5d5c8f8c6a3970b2e7fa76d7b630e8a79eb8c0 (diff) | |
download | pkgsrc-f871e64485cbdb243c30ebcc296b9c95c18888a8.tar.gz |
- Added the two data types PkgLint::File and PkgLint::Location. I will need
them soon.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkglint/files/pkglint.pl | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/pkgtools/pkglint/files/pkglint.pl b/pkgtools/pkglint/files/pkglint.pl index 2524f55d8f8..d5963760a73 100644 --- a/pkgtools/pkglint/files/pkglint.pl +++ b/pkgtools/pkglint/files/pkglint.pl @@ -1,5 +1,5 @@ #! @PERL@ -# $NetBSD: pkglint.pl,v 1.486 2006/01/26 23:05:49 rillig Exp $ +# $NetBSD: pkglint.pl,v 1.487 2006/01/27 00:07:07 rillig Exp $ # # pkglint - static analyzer and checker for pkgsrc packages @@ -303,6 +303,62 @@ sub set_show_source_flag() { #== End of PkgLint::Logging =============================================== +#========================================================================== +# A File is a structure containing the contents of a file: +# name: string The name of the file. +# lines: array of string The physical lines in the file. +#========================================================================== +package PkgLint::File; + +use constant NAME => 0; +use constant LINES => 1; + +sub new($$$) { + my ($class, $name, $lines) = @_; + my $self = [$name, $lines]; + bless($self, $class); + return $self; +} + +sub name($) { return shift(@_)->[NAME]; } +sub lines($) { return shift(@_)->[LINES]; } + +sub load($$) { + my ($self, $fname) = @_; + my ($lines); + + $lines = []; + open(F, "<", $fname) or return undef; + while (defined(my $line = <F>)) { + push(@{$lines}, $line); + } + close(F) or return undef; + + $self->[NAME] = $fname; + $self->[LINES] = $lines; + return $self; +} + +#========================================================================== +# A Location is a structure containing a location in a file: +# lineno: int The line number in the file +# colno: int The column number in the file +#========================================================================== +package PkgLint::Location; + +use constant LINENO => 0; +use constant COLNO => 1; + +sub new($$$$) { + my ($class, $lineno, $colno) = @_; + my ($self) = ([$lineno, $colno]); + bless($self, $class); + return $self; +} + +sub lineno($) { return shift(@_)->[LINENO]; } +sub colno($) { return shift(@_)->[COLNO]; } + package PkgLint::Line; #========================================================================== # When files are read in by pkglint, they are interpreted in terms of |