
# ----------------- MAIN ----------------- #

&ReadParse();

$in{'content-type'} = $in{'content_type'} if exists $in{'content_type'};
$in{'reply-to'}     = $in{'reply_to'}     if exists $in{'reply_to'};

print &PrintHeader(),&HeaderHtml($Logo);

# Language Codes
%Lang = (
     en => 'English',
     fr => 'French',
     de => 'German',
     it => 'Italian',
     nl => 'Dutch',
     el => 'Greek',
     es => 'Spanish',
     pt => 'Portuguese',
     ar => 'Arabic',
     he => 'Hebrew',
     ru => 'Russian',
     zh => 'Chinese',
     ja => 'Japanese',
     hi => 'Hindi',
     ur => 'Urdu',
     sa => 'Sanskrit'
);

%Direction = (
    ltr => 'Left-to-right text',
    rtl => 'Right-to-left text'
);

@MetaTags = qw(author keywords description expires copyright generator reply-to content-type other);
@HeaderList = qw(h1 h2 h3 h4 h5 h6);

foreach $i (0..$#MetaTags)   { push(@MTags, $MetaTags[$i])   if $in{$MetaTags[$i]}; }
foreach $i (0..$#HeaderList) { push(@HList, $HeaderList[$i]) if $in{$HeaderList[$i]}; }

if ($in{'dir'}) {

    @filelist = &GetFileList($in{'dir'});

# Build the arrays

    @title = &BuildArray("-c title title",@filelist) if $in{'title'};
    foreach $h (@HList) { @{$h} = &BuildArray("-c $h $h",@filelist); };
    @meta  = &BuildArray("meta",@filelist) if $#MTags >= 0;
    @link  = &BuildArray("link",@filelist) if $in{'links'};

# Process the arrays

    foreach $file (sort @filelist) {
      $Pfiles .= "<li>".$file."</li>";
      $Buf{$file}{name}  = $file;
      $Buf{$file}{name}  =~ s/^$in{'dir'}/\./;
      $Buf{$file}{dir}   = $in{'dir'};
      $Buf{$file}{meta}  = undef;
      $Buf{$file}{title} = undef;

# Handle <TITLE> Tags

      if ($in{'title'}) {
        @titlelist = &GetArray($file,@title);
        $Buf{$file}{title} = &TitleInfo(@titlelist);
      }

# Handle <H1> .. <H6> Tags

    foreach $h (@HList) {
          my @hdr;
          @hdr = &GetArray($file,@{$h});
          chomp @hdr;
          $Buf{$file}{headers}{$h} = \@hdr;
      }

# Handle <META> Tags

      @metalist  = &GetArray($file,@meta) if $#MTags >= 0;

      foreach $line (@metalist) {
        $oline = $line;
        $line =~ s/^\s*<\s*meta\s+(.*)\s*>\s*$/$1/i;
        my %pair = ( 'name'       => undef,
                     'http-equiv' => undef,
                     'content'    => undef,
                     'scheme'     => undef,
                     'lang'       => undef,
                     'dir'        => undef);
        while ($line ne "") {
          ($keyword, $value, $line) = &GetNextPair($line);
          if (exists $pair{lc($keyword)}) { $pair{lc($keyword)} = $value; }
          elsif ($oline =~ /\.\.\.\.\.$/) { $Error .= "Warning: Meta tag exceeds 200 characters in ".$file."\nLine is: $oline\n"; }
          else { $Error .= "Warning: Invalid meta keyword ($keyword) in ".$file."\nLine is: $oline\n"; }
        }
        $pair{name}  = $pair{'http-equiv'} unless $pair{name};
        $pair{lang} .= ' ('.$Lang{$pair{lang}}.')'     if $Lang{$pair{lang}};
        $pair{dir}  .= ' ('.$Direction{$pair{dir}}.')' if $Direction{$pair{dir}};
        $Buf{$file}{meta}{lc($pair{name})} = \%pair;
      }

# Handle <LINK> Tags

      @linklist  = &GetArray($file,@link) if $in{'links'};

      $lt = 1;
      foreach $line (@linklist) {
        $line =~ s/^\s*<\s*link\s+(.*)\s*>\s*$/$1/i;
        my %pair = ( rel      => undef,
                     type     => undef,
                     href     => undef,
                     media    => undef,
                     charset  => undef,
                     hreflang => undef,
                     rev      => undef,
                     lang     => undef,
                     title    => undef,
                     style    => undef,
                     target   => undef,
                     dir      => undef);
        while ($line ne "") {
          ($keyword, $value, $line) = &GetNextPair($line);
          if (exists $pair{lc($keyword)}) { $pair{lc($keyword)} = $value; }
          else { $Error .= "Warning: Invalid link keyword ($keyword) in ".$file."\n"; }
        }
        $pair{lang}     .= '&nbsp;('.$Lang{$pair{lang}}.')'     if $Lang{$pair{lang}};
        $pair{hreflang} .= '&nbsp;('.$Lang{$pair{hreflang}}.')' if $Lang{$pair{hreflang}};
        $pair{dir}      .= '&nbsp;('.$Direction{$pair{dir}}.')' if $Direction{$pair{dir}};
        $Buf{$file}{'link'}{$lt++} = \%pair;
      }
    }

# Generate and print the HTML page

    print &GenHtml($in{'dir'},%Buf);

} else {

# Print the opening page

    print &Opening(&MyBaseUrl());

}

1;

__END__
#------------------------------------------------------------------------------
#
# Start of POD
#
#------------------------------------------------------------------------------
=pod

=head1 NAME

htaz - Web-enabled HTML File Analysis Tool


=head1 SYNOPSIS

 http://localhost/htaz.html
 Displays an HTML options page to setup and call htaz.cgi.
 Recursively examines HTML pages for title, meta, link, and header tags.

=cut

=head1 DESCRIPTION

B<HTML Tag Analyzer> (htaz) is a cross-browser, web-based HTML file analysis application. 
It takes as input a directory name and examines each of the HTML, HTM, and SHTML files 
in the directory and all subdirectories. This tool can be quite useful on large sites 
that need a quick way to determine missing elements and to check for consistency.

=head1 OPTIONS

The tags analyzed are

=over 4

 <title>, <meta>, <link>,
 <h1>, <h2> .. <h6>

=back

The recognized <meta> tag attributes are

=over 4

 Author, Keywords, Description, Expires,
 Copyright, Generator, Reply-to, Content-type,
 All Meta Tags (even if not in list above)

=back

The recognized E<lt>metaE<gt> tag sub-attributes are

=over 4

 name, http-equiv, content, scheme,
 lang, dir

=back

The recognized E<lt>linkE<gt> tag attributes are

=over 4

 rel, type, href, media,
 charset, hreflang, rev, lang,
 title, style, target, dir

=back

The contents of the E<lt>titleE<gt> and E<lt>h1E<gt>..E<lt>h6E<gt> 
tags are also processed.

=head1 PREREQUISITES

 HTML Tag Analyzer is written in Perl 5
 Some JavaScript is used in the buttons on the home page
 CGI capable web server
 taggrep OR HTML::TokeParser

=head1 BUGS

It has been tested only on some Linux, Windows, and Irix systems.

=head1 AUTHOR

Steve Horsburgh E<lt>shorsburgh@horsburgh.comE<gt>

=head1 COPYRIGHT

Copyright (c) 2000, Horsburgh.com. All rights reserved.

This script is free software; you can redistribute it and/or modify
it under GNU GPL. (See the file COPYING)

=cut
