#!/usr/bin/perl -wT
# $Id: weblint,v 1.5 2002/05/29 15:09:59 petdance Exp $

use strict;

use lib qw( /home/alester/html-lint/lib );

use HTML::Lint;
use HTML::Lint::HTML4;

my $currfile = "";
my $lint = new HTML::Lint;

if ( !@ARGV ) {
    print "weblint v$HTML::Lint::VERSION\n";
    print "Usage: weblint [filename-or-url...]\n";
    exit 1;
}

for my $url ( @ARGV ) {
    $lint->newfile( $url );
    if ( $url =~ /^https?:/ ) {
	eval { require LWP::Simple };
	if ( $@ ) {
	    warn "Can't retrieve URLs without LWP::Simple installed";
	    next;
	}

	my $content = LWP::Simple::get( $url );
	if ( $content ) {
	    $lint->parse( $content );
	} else {
	    warn "Unable to fetch $url\n";
	}
    } else {
	open( my $fh, "<", $url ) or die "Can't open $url: $!";
	local $/ = undef;
	$lint->parse( <$fh> );
	$lint->eof();
	close $fh;
    }
} # for files

for my $error ( $lint->errors() ) {
    print $error->as_string(), "\n";
}
