From 6d400b0656cdb3cd8ea2ff742fb18593fe871fbc Mon Sep 17 00:00:00 2001 From: jwz Date: Fri, 19 Jun 1998 23:06:50 +0000 Subject: [PATCH] from dawn: cleverly generate stuff for the "Description" column in LXR directory listings. git-svn-id: svn://10.0.0.236/trunk@4169 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/lxr/source | 67 ++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/mozilla/webtools/lxr/source b/mozilla/webtools/lxr/source index 2f63466c8b0..28173c50f09 100755 --- a/mozilla/webtools/lxr/source +++ b/mozilla/webtools/lxr/source @@ -1,5 +1,5 @@ #!/usr/bonsaitools/bin/perl -# $Id: source,v 1.6 1998-06-16 20:23:38 jwz Exp $ +# $Id: source,v 1.7 1998-06-19 23:06:50 jwz Exp $ # source -- Present sourcecode as html, complete with references # @@ -29,24 +29,56 @@ use LXR::Common; use LXR::Config; +# Search the beginning of a source file for a short description +# to be displayed in directory listings. Not all files have +# them and the ones that do use different formats so there are +# lots of ways to end up with junk. The basic format is: a file +# name possibly followed by a colon or dash(es) with whitespace +# strewn in followed by the description and maybe some stray comment +# characters. Don't be confused by #includes or rcs comments +# at the beginning of the file. +# -dme sub fdescexpand { + my $linecount=0; $desc= ""; -# if (open(FILE, $Path->{'real'}."/".$filename)) { -# while(){ -# if(/$filename\s*--*\s*/i){ -# ($null, $desc) = split(/ $filename\s*--*\s*/i); -# if ($desc) {last}; -# }elsif (/$filename\s*:\s*/i){ -# ($null, $desc) = split(/ $filename\s*:\s*/i); -# if ($desc) {last}; -# }elsif (/$filename\s*/i){ -# ($null, $desc) = split(/ $filename\s*/i); -# if ($desc) {last}; -# } -# } -# close(FILE); -# } + + #ignore files that aren't source code + if (!( + ($filename =~ /\.c$/) | + ($filename =~ /\.h$/) | + ($filename =~ /\.cc$/) | + ($filename =~ /\.cp$/) | + ($filename =~ /\.cpp$/) | + ($filename =~ /\.java$/) + )){ + return(""); + } + + if (open(FILE, $Path->{'real'}."/".$filename)) { + while(){ + if($linecount++ > 40) { + last; + }elsif (/\$Id: source,v 1.7 1998-06-19 23:06:50 jwz Exp $filename/){ + #ignore cvs headers + }elsif (/^#/){ + #ignore cpp directives + }elsif (/$filename\s*- ?-*\s*/i){ + ($null, $desc) = split(/ $filename\s*- ?-*\s*/i); + if ($desc) {last}; + }elsif (/$filename\s*:\s*/i){ + ($null, $desc) = split(/ $filename\s*:\s*/i); + if ($desc) {last}; + }elsif (/$filename\s\s*/i){ + ($null, $desc) = split(/ $filename\s\s*/i); + if ($desc) {last}; + } + } + close(FILE); + } + #strip trailing asterisks and "*/" + $desc =~ s#\*/?\s*$##; + return($desc); } @@ -323,6 +355,3 @@ if (!($Path->{'file'} =~ /\.(html)$/)) { &makefooter('sourcedir'); } } - -#$len = length($file); -#print ("length is: ", $len) ;