From 2d3b8bb1f0953e2f4e2ef5d7f9f6a540933b0860 Mon Sep 17 00:00:00 2001 From: jwz Date: Tue, 23 Jun 1998 01:01:39 +0000 Subject: [PATCH] dawn@cannibal.mi.org: htmlify descriptions in directory listings remove some more style file stuff git-svn-id: svn://10.0.0.236/trunk@4255 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/lxr/lib/LXR/Common.pm | 59 ++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/mozilla/webtools/lxr/lib/LXR/Common.pm b/mozilla/webtools/lxr/lib/LXR/Common.pm index 3e7bdaa0af4..6d5fd7c62e6 100755 --- a/mozilla/webtools/lxr/lib/LXR/Common.pm +++ b/mozilla/webtools/lxr/lib/LXR/Common.pm @@ -1,4 +1,4 @@ -# $Id: Common.pm,v 1.9 1998-06-16 20:23:42 jwz Exp $ +# $Id: Common.pm,v 1.10 1998-06-23 01:01:39 jwz Exp $ package LXR::Common; @@ -8,6 +8,7 @@ require Exporter; @ISA = qw(Exporter); @EXPORT = qw(&warning &fatal &abortall &fflush &urlargs &fileref &idref &htmlquote &freetextmarkup &markupfile + &markspecials &htmlquote &freetextmarkup &markupstring &init &makeheader &makefooter &expandtemplate); @@ -151,11 +152,63 @@ sub linetag { $tag .= ' ' if $_[1] < 10; $tag .= ' ' if $_[1] < 100; $tag .= &fileref($_[1], $_[0], $_[1]).' '; - $tag =~ s/])/\0$1/g; + + # Look for identifiers and create links with identifier search query. + tie (%xref, "DB_File", $Conf->dbdir."/xref", O_RDONLY, 0664, $DB_HASH) + || &warning("Cannot open xref database."); + $string =~ s#(^|[^a-zA-Z_\#0-9\.])([a-zA-Z_~][a-zA-Z0-9_]*)\b# + $1.(is_linkworthy($2) ? &idref($2,$2) : $2)#ge; + untie(%xref); + + # HTMLify the special characters we marked earlier, + # but not the ones in the recently added xref html links. + $string=~ s/\0&/&/g; + $string=~ s/\0/>/g; + + # HTMLify email addresses and urls. + $string=~ s#((ftp|http)://\S*[^\s.])#$1#g; + $string=~ s/(<(.*@.*)>)/$1<\/a>/g; + + # HTMLify file names (assume file is in the current directory). + $string =~ s#([\w-_\/]+\.(c|h|cc|cp|cpp))# + {virtroot}/source$virtp$1\">$1#g; + + return($string); +} + +# dme: Return true if string is in the identifier db and it seems like its +# use in the sentence is as an identifier and its not just some word that +# happens to have been used as a variable name somewhere. We don't want +# words like "of", "to" and "a" to get links. The string must be long +# enough, and either contain "_" or if some letter besides the first +# is capitalized +sub is_linkworthy{ + my ($string) = @_; + + if ( ($string =~ /....../) && + ( ($string =~ /_/) || + ($string =~ /.[A-Z]/) + ) && + (defined($xref{$string})) + ){ + return (1); + }else{ + return (0); + } +} sub markupfile { my ($INFILE, $virtp, $fname, $outfun) = @_; @@ -171,7 +224,7 @@ sub markupfile { || &warning("Cannot open xref database."); &$outfun(# "
\n".
-		 #"');
+		 #"');
 		 &linetag($virtp.$fname, $line++));
 
 	($btype, $frag) = &SimpleParse::nextfrag;