From: Markus Armbruster Date: Sat, 11 May 2013 14:44:40 +0000 (+0200) Subject: Don't put broken links in HTML info pages X-Git-Tag: v4.3.31~2 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=59a199c69dba177dccf9035b84b823fad3a3614c Don't put broken links in HTML info pages Pass the valid info page names to emp2html.pl, and convert only valid references to links there. --- diff --git a/Make.mk b/Make.mk index 87968b6ba..3cfad4dfe 100644 --- a/Make.mk +++ b/Make.mk @@ -293,7 +293,7 @@ info.nr/%: info/%.t # Pipes in make are a pain. The "test -s" catches obvious errors. info.html/%.html: info/%.t - perl $(srcdir)/info/emp2html.pl $< >$@ + $(call quiet-command,perl $(srcdir)/info/emp2html.pl $(info) <$< >$@,GEN $@) ### Explicit rules diff --git a/info/emp2html.pl b/info/emp2html.pl index 7b7d82e78..13069f933 100644 --- a/info/emp2html.pl +++ b/info/emp2html.pl @@ -31,9 +31,10 @@ # Drake Diedrich, 1996 # Markus Armbruster, 2004-2013 # -# Usage: emp2html.pl [INFO-FILE] +# Usage: emp2html.pl INFO... # -# Convert INFO-FILE (or else standard input) to HTML on standard output. +# Convert info source on standard input to HTML on standard output. +# INFO... are the info page names. use strict; use warnings; @@ -43,13 +44,18 @@ my $esc = "\\"; my $ignore = 0; my $is_subj; my @a; +my %topic; + +for (@ARGV) { + $topic{$_} = 1; +} print "\n"; print "\n"; print "\n"; -line: while (<>) { +line: while () { chomp; # strip record separator s/((^|[^\\])(\\\\)*)\\\".*/$1/g; # strip comments @@ -162,8 +168,7 @@ sub checkarg { sub anchor { local ($_) = @_; - # FIXME don't create dangling links here - return "$_"; + return $topic{$_} ? "$_" : $_; } # Translate HTML special characters into escape sequences @@ -182,13 +187,18 @@ sub htmlify { s/\\e/&\#92;/g; # escape character # turn quoted strings that look like info names into links # tacky... + my $pfx = ""; while (/\\\*Q([A-Za-z0-9\-\.]+)\\\*U|\"info ([A-Za-z0-9\-\.]+)\"/) { - if (defined $1) { - $_ = $` . anchor($1) . "$'"; + if (defined $1 && $topic{$1}) { + $pfx = $` . anchor($1); + } elsif (defined $2 && $topic{$2}) { + $pfx = "$`\"info " . anchor($2) . "\""; } else { - $_ = "$`\"info " . anchor($2) . "\"$'"; + $pfx .= $` . $&; } + $_ = "$'"; } + $_ = "$pfx$_"; # tranlate more troff escapes and strings s/\\\*Q//g; s/\\\*U/<\/em>/g;