home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / LANGUAGE / ADA / LOVELACE / nolink < prev    next >
Text File  |  1996-10-01  |  2KB  |  69 lines

  1. #!/usr/local/bin/perl -w
  2. #
  3. # nolink - reports HTML files that don't have "local" links.
  4. #
  5. # Input is a list of HTML filenames (on the argument list).
  6. # Output is nothing if each file has a local link, otherwise a warning
  7. # message is displayed.
  8. #
  9. # Options:
  10. #  -i  ignore  the name of a hypertext link to ignore.
  11. #
  12. # A "local" link is a hypertext link to another file in the same
  13. # system.  A file without a local link probably needs one.
  14. #
  15. # BUGS:
  16. #   If the only internal hypertext links occur on the same line after
  17. #   an ignored internal link, an extraneous warning will be printed.
  18.  
  19. ############### Process Options ##############################
  20.  
  21. require 'getopts.pl';
  22.  
  23. undef $opt_i;
  24.  
  25. $valid_options = &Getopts('i:');
  26.  
  27. if (! $valid_options ) {
  28.  print '
  29. Usage: nolink [options] -- [filename]*
  30. Nolink reports HTML files without local hypertext links.
  31.   Usage: nolink {options} filename*
  32.     where options can be:
  33.  -i  ignore - name of file to ignore.
  34. ';
  35.  exit 1;
  36. }
  37.  
  38.  
  39. if      (defined($opt_i))  {$ignore = $opt_i;}
  40. else                       {$ignore = "";}
  41.  
  42.  
  43. ############### Perform Check ################################
  44.  
  45. while (<>) {
  46.  # Loop through all input file(s).
  47.  # $. is current line, $ARGV is current filename.
  48.  
  49.  if (m/<A\s+HREF="(file:)?([^:"]+)"/i) {
  50.    # We found a local link.  Should we ignore it?
  51.    $local_link = $2;
  52.    if ($local_link ne $ignore) {
  53.      # This is not an ignored local link, so this file's okay.
  54.      # Let's stop and look at the next file.
  55.      close(ARGV);
  56.      next;             # Restart processing the next file.
  57.    }
  58.  }
  59.  
  60.  if (eof) {
  61.     # Close file on end of each file to reset line numbering.
  62.     # Use "eof", NOT "eof()", or this won't work due to a perl oddity.
  63.     print "WARNING: file $ARGV has no local links.\n";
  64.     close(ARGV);
  65.  }
  66.  
  67. }
  68.  
  69.