From: guido Date: Tue, 14 Sep 2004 17:02:20 +0000 (+0000) Subject: validate xrefs again X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97e5c1f847b8074efe18fb0bd33357ecdae25e51;p=dealii-svn.git validate xrefs again git-svn-id: https://svn.dealii.org/trunk@9615 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/common/scripts/validate-xrefs.pl b/deal.II/common/scripts/validate-xrefs.pl new file mode 100644 index 0000000000..b0111f0638 --- /dev/null +++ b/deal.II/common/scripts/validate-xrefs.pl @@ -0,0 +1,116 @@ +# $Id$ +# Check whether references in HTML files are valid or +# point to non-existing files/links/etc +# +# Author: Wolfgang Bangerth, Guido Kanschat 2000, 2004 + +#TODO: Th + +# set this to 1 if you want verbose output +$debug = 0; + +$startdir = `pwd`; +chop $startdir; + +foreach $filename (@ARGV) +{ + chdir $startdir || die "Could not change dir to $startdir\n"; + open IN, $filename + or die "---Can't open file `$filename'\n"; + + print "File: $filename\n" if $debug; + if ($filename =~ m!(.+)/([^/]+)!) + { + chdir $1; + $filename = $2; + } + + while () { + # first find all hrefs + while ( /<\s*a\s+href=\"?(.*?)[\s\"]/gi ) { + # then decide whether they are relevant for + # our purpose + $link = $1; + + if ( $link =~ /^mailto|http:\/\//i ) { + # link is external. don't check it + print "external link: $link\n" if $debug; + next; + } + elsif ( $link =~ m/^#(.*)/ ) + { + # this is a reference within this file. try to + # find its anchor + $internal_ref = $1; + print "internal reference: $link\n" if $debug; + + open IN2, $filename; + $found = 0; + while ( ) { + while ( /]* name=\"?(.*?)[\s\"]/gi ) { + if ( $1 eq $internal_ref) { + print " found.\n" if $debug; + $found = 1; + last; + } + } + } + + die "---Internal reference `$internal_ref' not found in file $filename\n" + unless $found; + next; + } + elsif ( $link =~ /^(.*?)#(.*)/ ) + { + # this is a reference within another file. try to + # find its anchor + $external_file = $1; + $external_ref = $2; + + # if the file name was prepended with http: (but is a local file, + # so no double-slash), then split off http: + $external_file =~ s/^http://g; + + print "external reference: $link\n" if $debug; + + open IN2, $external_file; + $found = 0; + while ( ) { + while ( /]* name=\"?(.*?)[\s\"]/gi ) { + if ( $1 eq $external_ref) { + print " found.\n" if $debug; + $found = 1; + last; + } + } + } + + die "---External reference `$external_file#$external_ref' not found in file $filename\n" + unless $found; + next; + } + else { + # this must now be a regular file which is + # referenced. the file must be local + + # if the file name was prepended with http: (but is a local file, + # so no double-slash), then split off http: + $link =~ s/^http://g; + + die "---Local file `$link' not found in file `$filename'\n" + unless ((-r $link) && (-f $link)); + } + } + + # check whether references to images are valid + while ( /img\s+src=\"?(.*?)[\s\"]/gi ) { + # check whether the file for the image is present + $link = $1; + + die "---Local image `$link' not found in file `$filename'\n" + unless ((-r $link) && (-f $link)); + } + } +} + +print "---- All local links found to be ok.\n"; diff --git a/deal.II/doc/Makefile.in b/deal.II/doc/Makefile.in index 815ec9e849..fafc8a5806 100644 --- a/deal.II/doc/Makefile.in +++ b/deal.II/doc/Makefile.in @@ -10,7 +10,7 @@ include $D/common/Make.global_options # generic targets -default: doxygen tutorial development glossary # validate-xrefs +default: doxygen tutorial development validate-xrefs all: default @@ -31,10 +31,9 @@ glossary: validate-xrefs: @echo "Validating cross-references in HTML files." -# $(PERL) $D/doc/auto/scripts/validate-xrefs.pl *html + $(PERL) $D/common/scripts/validate-xrefs.pl *html doxygen/*/*.html cd tutorial ; $(MAKE) validate-xrefs cd development ; $(MAKE) validate-xrefs - cd glossary ; $(MAKE) validate-xrefs cd publications ; $(MAKE) validate-xrefs cd news ; $(MAKE) validate-xrefs cd reports ; $(MAKE) validate-xrefs diff --git a/deal.II/doc/development/Makefile b/deal.II/doc/development/Makefile index 55a39865ab..e1a914837b 100644 --- a/deal.II/doc/development/Makefile +++ b/deal.II/doc/development/Makefile @@ -82,7 +82,7 @@ makefile.rules.html: $D/common/Makefile.template @$(PERL) makefile2html < $< > $@ validate-xrefs: - $(PERL) $D/doc/auto/scripts/validate-xrefs.pl \ + @$(PERL) $D/common/scripts/validate-xrefs.pl \ $(filter-out makefiles.1.html makefiles.2.html, \ $(shell echo *.html)) diff --git a/deal.II/doc/news/Makefile b/deal.II/doc/news/Makefile index d67a473fec..8b93429d80 100644 --- a/deal.II/doc/news/Makefile +++ b/deal.II/doc/news/Makefile @@ -6,8 +6,8 @@ include $D/common/Make.global_options validate-xrefs: - $(PERL) $D/doc/auto/scripts/validate-xrefs.pl *.html - for dir in 200* ; do cd $$dir ; $(MAKE) validate-xrefs ; cd .. ; done + @$(PERL) $D/common/scripts/validate-xrefs.pl *.html */*.html + .PHONY: validate-xrefs diff --git a/deal.II/doc/publications/Makefile b/deal.II/doc/publications/Makefile index 20ae806b1d..19b3b7b342 100644 --- a/deal.II/doc/publications/Makefile +++ b/deal.II/doc/publications/Makefile @@ -9,7 +9,7 @@ default: validate-xrefs: - $(PERL) $D/doc/auto/scripts/validate-xrefs.pl *.html + $(PERL) $D/common/scripts/validate-xrefs.pl *.html .PHONY: default validate-xrefs \ No newline at end of file diff --git a/deal.II/doc/reports/Makefile b/deal.II/doc/reports/Makefile index a5d067ce31..70c5da1795 100644 --- a/deal.II/doc/reports/Makefile +++ b/deal.II/doc/reports/Makefile @@ -9,7 +9,7 @@ validate-xrefs: if test -d $$dir -a ! $$dir = CVS ; then \ cd $$dir ; \ echo "Checking `pwd`" ; \ - $(PERL) $D/doc/auto/scripts/validate-xrefs.pl *html ; \ + $(PERL) $D/common/scripts/validate-xrefs.pl *html ; \ cd .. ; \ fi ; \ done diff --git a/deal.II/doc/tutorial/chapter-2.step-by-step/Makefile b/deal.II/doc/tutorial/chapter-2.step-by-step/Makefile index 96aa7bbca3..1d7bebe9fd 100644 --- a/deal.II/doc/tutorial/chapter-2.step-by-step/Makefile +++ b/deal.II/doc/tutorial/chapter-2.step-by-step/Makefile @@ -78,7 +78,7 @@ step-by-step.sgml: $(example-sgmls) validate-xrefs: - $(PERL) $D/doc/auto/scripts/validate-xrefs.pl \ + @$(PERL) $D/common/scripts/validate-xrefs.pl \ $(filter-out head.html foot.html, \ $(shell echo *.html))