home *** CD-ROM | disk | FTP | other *** search
- #!/usr/sbin/perl
-
- # test command line syntax
- $SGMLFILE=$ARGV[0];
- if ($SGMLFILE eq "") {
- print "Usage : xref <input-file-name>\n";
- exit;
- }
-
- # make an array of targets (with text as content of each entry);
- # push any repeated targets into a list for later use
- open(F,$SGMLFILE);
- while (<F>) {
- while (s/<XREFTARGET ID=\"([^\"]+)\">/$1/) {
- $SAVED_PATTERNSPACE = $_;
- $TARGET = $1;
- s/<[^>]+>([^>]*)$TARGET([^>]*)<[^>]+>/$1 $2/;
- if (! $TARGETS{$TARGET}) {
- $TARGETS{$TARGET} = "$1 $2"; }
- else {
- $TARGETS{$TARGET} .= ": " . "$1 $2";
- if (!grep(/$TARGET/,@REPEAT_TARGETS)) {
- push(@REPEAT_TARGETS,$TARGET);
- }
- }
- $_ = $SAVED_PATTERNSPACE;
- }
- }
-
- # print out number and content of repeated targets, using list from above
- if (@REPEAT_TARGETS eq "") {
- print "\n Link targets appearing multiple times in book: none\n";
- }
- else {
- print "\n Link targets appearing multiple times in book:\n";
- print " ----------------------------------------------\n";
- foreach $REPEAT_TARGET (@REPEAT_TARGETS) {
- foreach $REPEAT (split(/:/,$TARGETS{$REPEAT_TARGET})) {
- print " $REPEAT_TARGET : $REPEAT\n";
- }
- }
- }
-
- # find xrefs and compare them to target array; print dangling pointers
- seek(F,0,0);
- while (<F>) {
- while (s/<XREF IDREF=\"([^\"]+)\"[^<]+<\/XREF>/$1/) {
- if (! $TARGETS{$1}) {
- ($POINTER = $&) =~ s/<XREF IDREF=[^>]+>([^<]+)<\/XREF>/$1/;
- if (!grep(/$POINTER/,keys(%POINTERS))) {
- $POINTERS{$POINTER} = 1;
- }
- else { $POINTERS{$POINTER} += 1; }
- }
- }
- }
- if (%POINTERS == "") {
- print "\n Unresolved References present in this book: none\n";
- }
- else {
- print "\n Unresolved References present in this book:\n";
- print " -------------------------------------------\n";
- foreach $POINTER (keys(%POINTERS)) {
- print " $POINTER appears $POINTERS{$POINTER} time(s)\n";
- }
- }
-
- # find and print any extrefs
- seek(F,0,0);
- while (<F>) {
- while (s/<EXTREF IDREF=\"[^\"]+\" *BOOK=\"([^\"]+)\"[^>]+>/$1/) {
- if (!grep(/$1/,keys(%EXTREFS))) {
- $EXTREFS{$1} = 1; }
- else { $EXTREFS{$1} += 1; }
- }
- }
- if (%EXTREFS == "") {
- print "\n External Book References present in this book: none \n";
- }
- else {
- print "\n External Book References present in this book:\n";
- print " ----------------------------------------------\n";
- foreach $EXREF (keys(%EXTREFS)) {
- print " $EXREF appears $EXTREFS{$EXREF} time(s)\n";
- }
- }
-
- close(F);
-