home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 November / SGI IRIX 6.5 Applications 1999 November.iso / dev / insight_dev.idb / usr / share / Insight / bin / xref.z / xref
Encoding:
Text File  |  1998-10-28  |  2.4 KB  |  89 lines

  1. #!/usr/sbin/perl
  2.  
  3. # test command line syntax
  4. $SGMLFILE=$ARGV[0];
  5. if ($SGMLFILE eq "") {
  6.   print "Usage : xref <input-file-name>\n";
  7.   exit;
  8. }
  9.  
  10. # make an array of targets (with text as content of each entry);
  11. # push any repeated targets into a list for later use
  12. open(F,$SGMLFILE);
  13. while (<F>) {
  14.   while (s/<XREFTARGET ID=\"([^\"]+)\">/$1/) {
  15.     $SAVED_PATTERNSPACE = $_;
  16.     $TARGET = $1;
  17.     s/<[^>]+>([^>]*)$TARGET([^>]*)<[^>]+>/$1 $2/;
  18.     if (! $TARGETS{$TARGET}) { 
  19.       $TARGETS{$TARGET} = "$1 $2"; }
  20.     else {
  21.       $TARGETS{$TARGET} .= ": " . "$1 $2";
  22.       if (!grep(/$TARGET/,@REPEAT_TARGETS)) {
  23.         push(@REPEAT_TARGETS,$TARGET);
  24.       }
  25.     }
  26.     $_ = $SAVED_PATTERNSPACE;
  27.   }
  28. }
  29.  
  30. # print out number and content of repeated targets, using list from above
  31. if (@REPEAT_TARGETS eq "") {
  32.   print "\n Link targets appearing multiple times in book: none\n";
  33. }
  34. else {
  35.   print "\n Link targets appearing multiple times in book:\n";
  36.   print " ----------------------------------------------\n";
  37.   foreach $REPEAT_TARGET (@REPEAT_TARGETS) {
  38.     foreach $REPEAT (split(/:/,$TARGETS{$REPEAT_TARGET})) {
  39.       print " $REPEAT_TARGET : $REPEAT\n";
  40.     }
  41.   }
  42. }
  43.  
  44. # find xrefs and compare them to target array; print dangling pointers
  45. seek(F,0,0);
  46. while (<F>) {
  47.   while (s/<XREF IDREF=\"([^\"]+)\"[^<]+<\/XREF>/$1/) {
  48.     if (! $TARGETS{$1}) {
  49.       ($POINTER = $&) =~ s/<XREF IDREF=[^>]+>([^<]+)<\/XREF>/$1/;
  50.       if (!grep(/$POINTER/,keys(%POINTERS))) {
  51.         $POINTERS{$POINTER} = 1;
  52.       }
  53.       else { $POINTERS{$POINTER} += 1; }
  54.     }
  55.   }
  56. }
  57. if (%POINTERS == "") {
  58.   print "\n Unresolved References present in this book: none\n";
  59. }
  60. else {
  61.   print "\n Unresolved References present in this book:\n";
  62.   print " -------------------------------------------\n";
  63.   foreach $POINTER (keys(%POINTERS)) {
  64.     print " $POINTER appears $POINTERS{$POINTER} time(s)\n";
  65.   }
  66. }
  67.  
  68. # find and print any extrefs
  69. seek(F,0,0);
  70. while (<F>) {
  71.   while (s/<EXTREF IDREF=\"[^\"]+\" *BOOK=\"([^\"]+)\"[^>]+>/$1/) {
  72.     if (!grep(/$1/,keys(%EXTREFS))) {
  73.       $EXTREFS{$1} = 1; }
  74.     else { $EXTREFS{$1} += 1; }
  75.   }
  76. }
  77. if (%EXTREFS == "") {
  78.   print "\n External Book References present in this book: none \n";
  79. }
  80. else {
  81.   print "\n External Book References present in this book:\n";
  82.   print " ----------------------------------------------\n";
  83.   foreach $EXREF (keys(%EXTREFS)) {
  84.     print " $EXREF appears $EXTREFS{$EXREF} time(s)\n";
  85.   }
  86. }
  87.  
  88. close(F);
  89.