Revision 1 (by moose, 2006/03/06 10:35:57) Initial Import
#!/usr/bin/perl

use strict;
use warnings;
use File::Spec::Functions qw/catdir/;
use IO::File;
use IO::Dir;

our $i = 1;
scandir(".");

sub scandir {
	my $dir = shift;
	my $dh = new IO::Dir($dir);
	return unless $dh;

	for($dh->read()) {
		next if /^\./;
		next if /^.*~$/;

		my $path = catdir($dir, $_);
		if(-d $path) {
#			print "Dir: $path\n";
			scandir($path);
			next;
		}

		scanfile($path) if -f _;
	}
}

sub bold { return "\e[1;3m" . shift() . "\e[m"; }

sub scanfile {
	my $fn = shift;
	my $fh = new IO::File($fn);
	my $ln = 0;
	my $lln = 0;
	my $ctx = 3;
	my $perl = ($fn =~ /\.p[lm]$/i);

	for(<$fh>) {
		chomp;
		++$ln;
		next if /^\s*$/;
		if(! m|^\s*//\s*([A-Z]+):\s*(.*)\s*$|) {
			#print "ln:$ln, lln:$lln\n" ;

#			s/^\s+(.*)\s*$/$1/;
#			s/^\t{3,}(.*)\s*$/\t$1/;
			if ($lln && $ln - $lln <= $ctx) {
				my $line = $_;
				my $f = new IO::File();
				$f->open(">.enscript");
				$f->print($line);
				$f->close();
				if($perl) {
					$line = `enscript --language=ansi --color --highlight=perl -o - .enscript -q`;
				} else {
					$line = `enscript --language=ansi --color --highlight=cpp -o - .enscript -q`;
				}
				unlink ".enscript";
				print "\t" . bold($ln) . ": $line" . "\n" ;
			}
				next;
		}

		print "\n" if $i > 1;
		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;
		$lln = $ln;
		++$i;
	}

#	my $text = join '', <$fh>;

#	print "File: $fn\n";
#	while($text =~ s|^//\s*FIXME:?\s*(.*)$||m) {
#		print $i . ": " . $1 . "\n";
#		$i++;
#	}
}