#!/usr/bin/perl -w # Copyright (c) 2005 MichalDominik (AT) gmail (DOT) com ; MIT X11 license # Shell logic ported to perl and basically rewritten by muppet, 2005; # JS code is largely unchanged. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT # SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR # THE USE OR OTHER DEALINGS IN THE SOFTWARE. ######################### MODIFY HERE FOR YOUR NEEDS ######################## use strict; use Getopt::Long; use vars qw(@extensions $afterlines $beforelines $project $note $search_expression); #@extensions = qw(*.c *.h *.xs); # Files to parse $afterlines = 10; # Number of context lines after $beforelines = 3; # Number of context lines before $project="Project"; $note="This file was generated by fixme2html. You can customize this note"; $search_expression = '\\<\\(XXX\\|FIXME\\|TODO\\)\\>'; ################################## OPTIONS ################################## GetOptions ('project=s' => \$project, 'note=s' => \$note, 'extensions=s' => \@extensions, 'search=s' => \$search_expression); @extensions = qw(*.c *.h *.xs) unless @extensions; #warn "extensions: @extensions\n"; #warn "project: $project\n"; #__END__ die "Usage: $0 outputfile [grep search expression]\n" unless @ARGV; my $outfile = shift @ARGV; ############################# MAIN PROCESSING ################################# open OUTFILE, "> $outfile" or die "can't open $outfile for writing: $!\n"; header (); my @allfiles; # Find files for each extension foreach my $extension (@extensions) { my @these = grep { # filter out things in boilerplate directories !m{/(\.svn|blib)/} } `find ./ -iname "$extension" -print`; # special-case hack for C files generated from XS files. # something similar would be needed for .y => .c, but we'll # figure that out when we need it. if ($extension eq '*.c') { @these = map { (my $xsfile = $_) =~ s/\.c\s?$/.xs/; (-e $xsfile) ? () : ($_) } @these; } push @allfiles, @these; } chomp @allfiles; our $id=1; # For each file find fixmes foreach my $file (sort @allfiles) { next if -z $file; my @fixmes = `grep -n '$search_expression' $file`; #print "fixmes: ".scalar(@fixmes)."\n"; next unless @fixmes; print OUTFILE "

$file

\n"; foreach my $hit (@fixmes) { local $/ = undef; my ($lineno, $fixme) = $hit =~ m/^(\d+):(.*)$/; my $first = $lineno-$beforelines; $first = 1 if $first < 1; my $last = $lineno+$afterlines; # cat with line numbers; print only the lines of interest. #print "`cat -n '$file' | sed -n \"$first,$last\"p`\n"; my $context = `cat -n '$file' | sed -n "$first,$last"p`; # mark the line that has the actual hit on it. $context =~ s/^(\s*$lineno)/$1:/m; print OUTFILE "
\n"; print OUTFILE "

".escape_html_chars ($fixme)."

\n"; print OUTFILE "
\n"; print OUTFILE "
\n";
                print OUTFILE escape_html_chars ($context);
                print OUTFILE "
\n"; print OUTFILE "
\n"; print OUTFILE "
\n"; $id++; } } footer (); close OUTFILE; print "$project: $id\n"; ################################ HTML STUFF ################################### sub escape_html_chars { local $_ = shift; s/&/\&/g; s//\>/g; $_ } sub header { print OUTFILE < $project : FIXME watcher

$project

$note
EOH } sub footer { print OUTFILE ""; }