#!/bin/perl # C comment spell checker # For each given source file, print the filename, a colon, and the number # of misspelled words, then a list of misspelled words. # Words contained in the file stopwords.txt are not considered spelling errors. # Copyright 2003, Dan Kegel. Licensed under GPL. See the file ../COPYING for details. sub check_content($) { my $content = shift; $content =~ tr/*/ /; print POUT "$content\n"; } $TEMPFILE="/tmp/spell.tmp"; $STOPFILE=shift(@ARGV); open(STOPFILE, $STOPFILE) || die "can't open stopword file $STOPFILE"; while () { chomp; $stopped{$_}++; } close(STOPFILE); foreach $file (@ARGV) { open (FI, $file) || die $file; $content = join ("", ); close (FI); open(POUT, "> $TEMPFILE") || die; $content =~ s!//(.+)$!check_content($1)!egm; $content =~ s!/\*(.+?)\*/!check_content($1)!egs; close(POUT); open(PIN, "ispell -l < $TEMPFILE | sort -u |") || die; undef @badwords; while () { chomp; if ($stopped{$_} == 0) { push(@badwords, $_); } } close(PIN) || die; if (@badwords) { print "$file: ".scalar(@badwords)."\n\n"; print join(" ",@badwords)."\n\n"; } }