From 9e7aae58c2787ac637bb010affbe6f2db0d0611e 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. --- webtools/lxr/source | 67 ++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/webtools/lxr/source b/webtools/lxr/source index 58d22f2b0127..599440a26c08 100755 --- a/webtools/lxr/source +++ b/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) ;