72
72
# Yea, though I walk through the valley of the shadow of pattern
73
73
# matching, I shall fear no regex.
75
# use global vars here because the expandtemplate subroutine makes
76
# passing parameters impossible. Use $filename from source and
77
# $Path from Common.pm
78
my $filename = $main::filename;
82
my $maxlines = 40; #only look at the beginning of the file
84
#ignore files that aren't source code
86
($filename =~ /\.c$/) |
87
($filename =~ /\.h$/) |
88
($filename =~ /\.cc$/) |
89
($filename =~ /\.cp$/) |
90
($filename =~ /\.cpp$/) |
91
($filename =~ /\.java$/)
96
if (open(FILE, $Path->{'real'}."/".$filename)) {
99
if($linecount++ > 60) {
106
# sanity check: if there's no description then stop
107
if (!($desc =~ /\w/)){
111
# save a copy for later
114
# Look for well behaved <filename><seperator> formatted
115
# descriptions before we go to the trouble of looking for
116
# one in the first comment. The whitespace between the
117
# delimeter and the description may include a newline.
118
if (($desc =~ s/(?:.*?$filename\s*?- ?-*\s*)([^\n]*)(?:.*)/$1/sgi) ||
119
($desc =~ s/(?:.*?$filename\s*?:\s*)([^\n]*)(?:.*)/$1/sgi) ||
120
($desc =~ s/(?:.*?Description:\s*)([^\n]*)(?:.*)/$1/sgi)
122
# if the description is non-empty then clean it up and return it
124
#strip trailing asterisks and "*/"
125
$desc =~ s#\*/?\s*$##;
126
$desc =~ s#^[^\S]*\**[^\S]*#\n#gs;
128
# Strip beginning and trailing whitespace
132
# Strip junk from the beginning
133
$desc =~ s#[^\w]*##ms;
135
#htmlify the comments making links to symbols and files
136
$desc = markupstring($desc, $Path->{'virt'});
141
# we didn't find any well behaved descriptions above so start over
142
# and look for one in the first comment
145
# Strip off code from the end, starting at the first cpp directive
148
# Strip off code from the end, starting at typedef
149
$desc =~ s/\ntypedef.*//s;
152
$desc =~ s#(?:/\*.*license.*?\*/)(.*)#$1#is;
154
# Strip off copyright notice
155
$desc =~ s#(?:/\*.*copyright.*?\*/)(.*)#$1#is;
157
# Strip off emacs line
158
$desc =~ s#(/\*.*tab-width.*?\*/)(.*)#$2#isg;
161
$desc =~ s#Id: $filename.*?Exp \$##g;
163
# Yuck, nuke these silly comments in js/jsj /* ** */
164
$desc =~ s#\n\s*/\*+[\s\*]+\*/\n#\n#sg;
166
# Don't bother to continue if there aren't any comments here
167
if(!($desc =~ m#/\*#)) {
171
# Remove lines generated by jmc
172
$desc =~ s#\n.*?Source date:.*\n#\n#;
173
$desc =~ s#\n.*?Generated by jmc.*\n#\n#;
175
# Extract the first comment
176
$desc =~ s#(?:.*?/\*+)(.*?)(?:(?:\*+/.*)|(?:$))#$1#s;
178
# Strip silly borders
179
$desc =~ s#\n\s*[\*\=\-\s]+#\n#sg;
181
# Strip beginning and trailing whitespace
185
# Strip out file name
186
$desc =~ s#$filename##i;
189
$desc =~ s#By [^\n]*##;
192
$desc =~ s#\d{1,2}/\d{1,2}/\d\d\d\d##;
193
$desc =~ s#\d{1,2}/\d{1,2}/\d\d##;
194
$desc =~ s#\d{1,2} \w\w\w \d\d\d\d##;
196
# Strip junk from the beginning
199
# Extract the first paragraph
200
$desc =~ s#(\n\s*?\n.*)##s;
202
# If the description is too long then just use the first sentence
203
# this will fail if no period was used.
204
if (length($desc) > 200 ) {
205
$desc =~ s#([^\.]+\.)\s.*#$1#s;
208
# If the description is still too long then assume it will look
209
# like gobbeldygook and give up
210
if (length($desc) > 200 ) {
214
# htmlify the comments, making links to symbols and files
215
$desc = markupstring($desc, $Path->{'virt'});
81
my $maxlines = 40; #only look at the beginning of the file
83
#ignore files that aren't source code
86
($filename =~ /\.c$/) | ($filename =~ /\.h$/) | ($filename =~ /\.cc$/) |
87
($filename =~ /\.cp$/) | ($filename =~ /\.cpp$/) | ($filename =~ /\.java$/)
94
if ($fh = $files->getfilehandle($dir . $filename, $release)) {
97
if ($linecount++ > 60) {
104
# sanity check: if there's no description then stop
105
if (!($desc =~ /\w/)) {
109
# if a java file, only consider class-level javadoc comments
110
if ($filename =~ /\.java$/) {
112
# last /** ... */ before 'public class' or 'public interface'
115
$desc =~ m/public\s((abstract|static|final|strictfp)\s)*(class|interface)/g;
116
$declPos = pos $desc;
117
return "\ \;" if !$declPos;
119
# last comment start before declaration
122
while ($desc =~ m#/\*\*#g) {
123
last if $declPos < pos $desc;
124
$commentStart = pos $desc;
126
return "\ \;" if $commentStart == -1;
128
# find comment end, and extract
129
pos $desc = $commentStart;
131
$commentEnd = pos $desc;
132
$desc = substr($desc, $commentStart + 3, $commentEnd - $commentStart - 5);
134
return "\ \;" if !$desc;
136
# strip off any leading * s
137
$desc =~ s/^\s*\*\s?//mg;
139
# Strip off @parameter lines
140
$desc =~ s/^\s*@\w+.*$//mg;
142
# strip html tags (probably a way to do this all in one, but it's beyond my skill)
143
$desc =~ s#<[/\w]+(\s*\w+="[\w\s]*"\s*)*>##g; # double quoted attributes
144
$desc =~ s#<[/\w]+(\s*\w+='[\w\s]*'\s*)*>##g; # single quoted attributes
145
$desc =~ s#<[/\w]+(\s*\w+=[\w]*\s*)*>##g; # no quotes on attributes
147
# strip off some CVS keyword lines
148
foreach $keyword ('Workfile', 'Revision', 'Modtime', 'Author', 'Id', 'Date', 'Source',
151
$desc =~ s/^\s*\$$keyword[\$:].*$//mg;
156
# save a copy for later
159
# Look for well behaved <filename><seperator> formatted
160
# descriptions before we go to the trouble of looking for
161
# one in the first comment. The whitespace between the
162
# delimeter and the description may include a newline.
163
if ( ($desc =~ s/(?:.*?$filename\s*?- ?-*\s*)([^\n]*)(?:.*)/$1/sgi)
164
|| ($desc =~ s/(?:.*?$filename\s*?:\s*)([^\n]*)(?:.*)/$1/sgi)
165
|| ($desc =~ s/(?:.*?Description:\s*)([^\n]*)(?:.*)/$1/sgi))
168
# if the description is non-empty then clean it up and return it
171
#strip trailing asterisks and "*/"
172
$desc =~ s#\*/?\s*$##;
173
$desc =~ s#^[^\S]*\**[^\S]*#\n#gs;
175
# Strip beginning and trailing whitespace
179
# Strip junk from the beginning
180
$desc =~ s#[^\w]*##ms;
182
#htmlify the comments making links to symbols and files
183
$desc = markupstring($desc, $Path->{'virt'});
188
# if java and the <filename><seperator> check above didn't work, just dump the whole javadoc
189
if ($filename =~ /\.java$/) {
193
# we didn't find any well behaved descriptions above so start over
194
# and look for one in the first comment
197
# Strip off code from the end, starting at the first cpp directive
200
# Strip off code from the end, starting at typedef
201
$desc =~ s/\ntypedef.*//s;
204
$desc =~ s#(?:/\*.*license.*?\*/)(.*)#$1#is;
206
# Strip off copyright notice
207
$desc =~ s#(?:/\*.*copyright.*?\*/)(.*)#$1#is;
209
# Strip off emacs line
210
$desc =~ s#(/\*.*tab-width.*?\*/)(.*)#$2#isg;
213
$desc =~ s#Id: $filename.*?Exp \$##g;
215
# Yuck, nuke these silly comments in js/jsj /* ** */
216
$desc =~ s#\n\s*/\*+[\s\*]+\*/\n#\n#sg;
218
# Don't bother to continue if there aren't any comments here
219
if (!($desc =~ m#/\*#)) {
223
# Remove lines generated by jmc
224
$desc =~ s#\n.*?Source date:.*\n#\n#;
225
$desc =~ s#\n.*?Generated by jmc.*\n#\n#;
227
# Extract the first comment
228
$desc =~ s#(?:.*?/\*+)(.*?)(?:(?:\*+/.*)|(?:$))#$1#s;
230
# Strip silly borders
231
$desc =~ s#\n\s*[\*\=\-\s]+#\n#sg;
233
# Strip beginning and trailing whitespace
237
# Strip out file name
238
$desc =~ s#$filename##i;
241
$desc =~ s#By [^\n]*##;
244
$desc =~ s#\d{1,2}/\d{1,2}/\d\d\d\d##;
245
$desc =~ s#\d{1,2}/\d{1,2}/\d\d##;
246
$desc =~ s#\d{1,2} \w\w\w \d\d\d\d##;
248
# Strip junk from the beginning
251
# Extract the first paragraph
252
$desc =~ s#(\n\s*?\n.*)##s;
254
# If the description is too long then just use the first sentence
255
# this will fail if no period was used.
256
if (length($desc) > 200) {
257
$desc =~ s#([^\.]+\.)\s.*#$1#s;
260
# If the description is still too long then assume it will look
261
# like gobbeldygook and give up
262
if (length($desc) > 200) {
266
# htmlify the comments, making links to symbols and files
267
$desc = markupstring($desc, $Path->{'virt'});
227
276
# dme: create a short description for a subdirectory in a directory listing
228
277
# If no description, return the string "\ \;" to keep the
229
278
# table looking pretty.
231
# In Mozilla, if the directory has a README file look in it for lines
280
# In Mozilla, if the directory has a README file look in it for lines
232
281
# like the ones used in source code: "directoryname --- A short description"
234
my ($templ, $node, $dir, $index) = @_;
236
if ($$index{$node}) {
237
return LXR::Common::expandtemplate($templ,
239
sub { return $$index{$node} }));
283
my ($templ, $node, $dir, $release) = @_;
284
if ($files->isdir($dir . $node, $release)) {
285
return LXR::Common::expandtemplate($templ,
286
('desctext' => sub { return dirdesc($dir . $node, $release); }));
288
return LXR::Common::expandtemplate($templ,
289
('desctext' => sub { return fdescexpand($node, $dir, $release); }));
246
# dme: Print a descriptive blurb in directory listings between
293
# dme: Print a descriptive blurb in directory listings between
247
294
# the document heading and the table containing the actual listing.
249
296
# For Mozilla, we extract this information from the README file if
250
297
# it exists. If the file is short then just print the whole thing.
251
# For longer files print the first paragraph or so. As much as
252
# possible make this work for randomly formatted files rather than
298
# For longer files print the first paragraph or so. As much as
299
# possible make this work for randomly formatted files rather than
253
300
# inventing strict rules which create gobbeldygook when they're broken.
257
if (-f $Path->{'real'}."/README") {
259
} elsif (-f $Path->{'real'}."/README.html") {
260
descreadmehtml($path);
302
my ($path, $release) = @_;
303
if ($files->isfile($path . "README.txt", $release)) {
304
descreadme($path . "README.txt", $release);
305
} elsif ($files->isfile($path . "README", $release)) {
306
descreadme($path . "README", $release);
307
} elsif ($files->isfile($path . "README.html", $release)) {
308
descreadmehtml($path . "README.html", $release);
265
312
sub descreadmehtml {
270
if (!(open(DESC, $Path->{'real'}."/README.html"))) {
278
# if the README is 0 length then give up
283
# check if there's a short desc nested inside the long desc. If not, do
284
# a non-greedy search for a long desc. assume there are no other stray
285
# spans within the description.
286
if ($string =~ /<span class=["']?lxrlongdesc['"]?>(.*?<span class=["']?lxrshortdesc['"]?>.*?<\/span>.*?)<\/span>/is) {
288
if (!($long =~ /<span.*?\<span/is)) {
289
print($long . "<p>\nSEE ALSO: <a href=\"README.html\">README</a></p>\n");
291
} elsif ($string =~ /<span class=["']?lxrlongdesc['"]?>(.*?)<\/span>/is) {
293
if (!($long =~ /\<span/is)) {
294
print($long . "<p>\nSEE ALSO: <a href=\"README.html\">README</a></p>\n");
313
my ($file, $release) = @_;
316
return if !($desc = $files->getfilehandle($file, $release));
324
# if the README is 0 length then give up
329
# check if there's a short desc nested inside the long desc. If not, do
330
# a non-greedy search for a long desc. assume there are no other stray
331
# spans within the description.
333
/<span class=["']?lxrlongdesc['"]?>(.*?<span class=["']?lxrshortdesc['"]?>.*?<\/span>.*?)<\/span>/is
337
if (!($long =~ /<span.*?\<span/is)) {
338
return ($long . "<p>\nSEE ALSO: <a href=\"README.html\">README</a></p>\n");
340
} elsif ($string =~ /<span class=["']?lxrlongdesc['"]?>(.*?)<\/span>/is) {
342
if (!($long =~ /\<span/is)) {
343
return ($long . "<p>\nSEE ALSO: <a href=\"README.html\">README</a></p>\n");
303
# $string =~ s#(</?([^>^\s]+[^>]*)>.*$)#($2~/B|A|IMG|FONT|BR|EM|I|TT/i)?$1:""#sg;
308
my $maxlines = 20; # If file is less than this then just print it all
309
my $minlines = 5; # Too small. Go back and add another paragraph.
310
my $chopto = 10; # Truncate long READMEs to this length
312
if (!(open(DESC, $Path->{'real'}."/README"))) {
321
# if the README is 0 length then give up
325
# strip the emacs tab line
326
$string =~ s/.*tab-width:[ \t]*([0-9]+).*\n//;
329
$string =~ s/.*The contents of this .* All Rights.*Reserved\.//s;
331
# strip the short description from the beginning
332
$path =~ s#/(.+)/#$1#;
333
$string =~ s/.*$path\/*\s+--- .*//;
336
$string =~ s/#+\s*\n/\n/;
337
$string =~ s/---+\s*\n/\n/g;
338
$string =~ s/===+\s*\n/\n/g;
340
# strip blank lines at beginning and end of file.
341
$string =~ s/^\s*\n//gs;
342
$string =~ s/\s*\n$//gs;
347
# If the file is small there's not much use splitting it up.
349
if ($count <= $maxlines) {
350
$string = markupstring($string, $Path->{'virt'});
351
$string = convertwhitespace($string);
354
# grab the first n paragraphs, with n decreasing until the
355
# string is 10 lines or shorter or until we're down to
359
while ( ($count > $chopto) && ($n-- > 1) ) {
360
$string =~ s/^((?:(?:[\S\t ]*?\n)+?[\t ]*\n){$n}?)(.*)/$1/s;
362
$string =~ s/\s*\n$//gs;
349
my ($file, $release) = @_;
353
# $string =~ s#(</?([^>^\s]+[^>]*)>.*$)#($2~/B|A|IMG|FONT|BR|EM|I|TT/i)?$1:""#sg;
358
my $maxlines = 20; # If file is less than this then just print it all
359
my $minlines = 5; # Too small. Go back and add another paragraph.
360
my $chopto = 10; # Truncate long READMEs to this length
362
return if !($desc = $files->getfilehandle($file, $release));
370
# if the README is 0 length then give up
366
# if we have too few lines then back up and grab another paragraph
375
# strip the emacs tab line
376
$string =~ s/.*tab-width:[ \t]*([0-9]+).*\n//;
379
$string =~ s/.*The contents of this .* All Rights.*Reserved\.//s;
381
# strip the short description from the beginning
382
$path =~ s#/(.+)/#$1#;
383
$string =~ s/.*$path\/*\s+--- .*//;
386
$string =~ s/#+\s*\n/\n/;
387
$string =~ s/---+\s*\n/\n/g;
388
$string =~ s/===+\s*\n/\n/g;
390
# strip blank lines at beginning and end of file.
391
$string =~ s/^\s*\n//gs;
392
$string =~ s/\s*\n$//gs;
368
395
$count = tr/\n//;
369
if ($count < $minlines) {
371
$temp =~ s/^((?:(?:[\S\t ]*?\n)+?[\t ]*\n){$n}?)(.*)/$1/s;
397
# If the file is small there's not much use splitting it up.
399
if ($count <= $maxlines) {
400
$string = markupstring($string, $Path->{'virt'});
401
$string = convertwhitespace($string);
405
# grab the first n paragraphs, with n decreasing until the
406
# string is 10 lines or shorter or until we're down to
410
while (($count > $chopto) && ($n-- > 1)) {
411
$string =~ s/^((?:(?:[\S\t ]*?\n)+?[\t ]*\n){$n}?)(.*)/$1/s;
413
$string =~ s/\s*\n$//gs;
417
# if we have too few lines then back up and grab another paragraph
420
if ($count < $minlines) {
422
$temp =~ s/^((?:(?:[\S\t ]*?\n)+?[\t ]*\n){$n}?)(.*)/$1/s;
426
# if we have more than $maxlines then truncate to $chopto
427
# and add an elipsis.
428
if ($count > $maxlines) {
429
$string =~ s/^((?:[\S \t]*\n){$chopto}?)(.*)/$1/s;
431
$string = $string . "\n...";
434
# since not all of the README is displayed here,
437
if ($string =~ /SEE ALSO/) {
438
$string = $string . ", README";
440
$string = $string . "\n\nSEE ALSO: README";
443
$string = markupstring($string, $Path->{'virt'});
444
$string = convertwhitespace($string);
446
# strip blank lines at beginning and end of file again
447
$string =~ s/^\s*\n//gs;
448
$string =~ s/\s*\n$//gs;
375
# if we have more than $maxlines then truncate to $chopto
376
# and add an elipsis.
377
if ($count > $maxlines) {
378
$string =~ s/^((?:[\S \t]*\n){$chopto}?)(.*)/$1/s;
380
$string = $string . "\n...";
383
# since not all of the README is displayed here,
386
if ($string =~ /SEE ALSO/) {
387
$string = $string . ", README";
389
$string = $string . "\n\nSEE ALSO: README";
392
$string = markupstring($string, $Path->{'virt'});
393
$string = convertwhitespace($string);
395
# strip blank lines at beginning and end of file again
396
$string =~ s/^\s*\n//gs;
397
$string =~ s/\s*\n$//gs;
400
print($string . "<p>\n");
404
455
# dme: substitute carraige returns and spaces in original text
405
456
# for html equivalent so we don't need to use <pre> and can
406
457
# use variable width fonts but preserve the formatting
407
458
sub convertwhitespace {
410
# handle ascii bulleted lists
411
$string =~ s/<p>\n\s+o\s/<p>\n\ \;\ \;o /sg;
412
$string =~ s/\n\s+o\s/ \;\n<br>\ \;\ \;o /sg;
414
#find paragraph breaks and replace with <p>
415
$string =~ s/\n\s*\n/<p>\n/sg;
461
# handle ascii bulleted lists
462
$string =~ s/<p>\n\s+o\s/<p>\n\ \;\ \;o /sg;
463
$string =~ s/\n\s+o\s/ \;\n<br>\ \;\ \;o /sg;
465
#find paragraph breaks and replace with <p>
466
$string =~ s/\n\s*\n/<p>\n/sg;