| 1 |
1 |
moose |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
use strict; |
| 4 |
|
|
use warnings; |
| 5 |
|
|
use File::Spec::Functions qw/catdir/; |
| 6 |
|
|
use IO::File; |
| 7 |
|
|
use IO::Dir; |
| 8 |
|
|
|
| 9 |
|
|
our $i = 1; |
| 10 |
|
|
scandir("."); |
| 11 |
|
|
|
| 12 |
|
|
sub scandir { |
| 13 |
|
|
my $dir = shift; |
| 14 |
|
|
my $dh = new IO::Dir($dir); |
| 15 |
|
|
return unless $dh; |
| 16 |
|
|
|
| 17 |
|
|
for($dh->read()) { |
| 18 |
|
|
next if /^\./; |
| 19 |
|
|
next if /^.*~$/; |
| 20 |
|
|
|
| 21 |
|
|
my $path = catdir($dir, $_); |
| 22 |
|
|
if(-d $path) { |
| 23 |
|
|
# print "Dir: $path\n"; |
| 24 |
|
|
scandir($path); |
| 25 |
|
|
next; |
| 26 |
|
|
} |
| 27 |
|
|
|
| 28 |
|
|
scanfile($path) if -f _; |
| 29 |
|
|
} |
| 30 |
|
|
} |
| 31 |
|
|
|
| 32 |
|
|
sub bold { return "\e[1;3m" . shift() . "\e[m"; } |
| 33 |
|
|
|
| 34 |
|
|
sub scanfile { |
| 35 |
|
|
my $fn = shift; |
| 36 |
|
|
my $fh = new IO::File($fn); |
| 37 |
|
|
my $ln = 0; |
| 38 |
|
|
my $lln = 0; |
| 39 |
|
|
my $ctx = 3; |
| 40 |
|
|
my $perl = ($fn =~ /\.p[lm]$/i); |
| 41 |
|
|
|
| 42 |
|
|
for(<$fh>) { |
| 43 |
|
|
chomp; |
| 44 |
|
|
++$ln; |
| 45 |
|
|
next if /^\s*$/; |
| 46 |
|
|
if(! m|^\s*//\s*([A-Z]+):\s*(.*)\s*$|) { |
| 47 |
|
|
#print "ln:$ln, lln:$lln\n" ; |
| 48 |
|
|
|
| 49 |
|
|
# s/^\s+(.*)\s*$/$1/; |
| 50 |
|
|
# s/^\t{3,}(.*)\s*$/\t$1/; |
| 51 |
|
|
if ($lln && $ln - $lln <= $ctx) { |
| 52 |
|
|
my $line = $_; |
| 53 |
|
|
my $f = new IO::File(); |
| 54 |
|
|
$f->open(">.enscript"); |
| 55 |
|
|
$f->print($line); |
| 56 |
|
|
$f->close(); |
| 57 |
|
|
if($perl) { |
| 58 |
|
|
$line = `enscript --language=ansi --color --highlight=perl -o - .enscript -q`; |
| 59 |
|
|
} else { |
| 60 |
|
|
$line = `enscript --language=ansi --color --highlight=cpp -o - .enscript -q`; |
| 61 |
|
|
} |
| 62 |
|
|
unlink ".enscript"; |
| 63 |
|
|
print "\t" . bold($ln) . ": $line" . "\n" ; |
| 64 |
|
|
} |
| 65 |
|
|
next; |
| 66 |
|
|
} |
| 67 |
|
|
|
| 68 |
|
|
print "\n" if $i > 1; |
| 69 |
|
|
printf "\e[1;3m%2i\e[m. %-25s - \e[1;3m%4i\e[m - \e[1;3m%-5s\e[m: %s\n", $i, $fn, $ln, $1, $2; |
| 70 |
|
|
$lln = $ln; |
| 71 |
|
|
++$i; |
| 72 |
|
|
} |
| 73 |
|
|
|
| 74 |
|
|
# my $text = join '', <$fh>; |
| 75 |
|
|
|
| 76 |
|
|
# print "File: $fn\n"; |
| 77 |
|
|
# while($text =~ s|^//\s*FIXME:?\s*(.*)$||m) { |
| 78 |
|
|
# print $i . ": " . $1 . "\n"; |
| 79 |
|
|
# $i++; |
| 80 |
|
|
# } |
| 81 |
|
|
} |