3 # Copyright (c) 2013-2015. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
9 # C comment spell checker
10 # For each given source file, print the filename, a colon, and the number
11 # of misspelled words, then a list of misspelled words.
12 # Words contained in the file stopwords.txt are not considered spelling errors.
13 # Copyright 2003, Dan Kegel. Licensed under GPL. See the file ../COPYING for details.
17 die "Please install iamerican to use that script."
18 unless (-r "/usr/lib/ispell/american.hash");
20 sub check_content($) {
23 print POUT "$content\n";
26 my $TEMPFILE="/tmp/spell.tmp";
27 my $DICTFILE="tools/spell_dict.txt";
28 $DICTFILE="spell_dict.txt" unless (-e $DICTFILE);
29 die "Call this script from its location or from the SimGrid root directory\n" unless (-e $DICTFILE);
31 die "Usage: ./spell_comments.pl `find ../ -name '*.[ch]' -name '*.hpp' -name '*.cpp'`\n"
32 unless length(@ARGV)>1;
33 foreach my $file (@ARGV) {
34 open (FI, $file) || die "Cannot open $file: $!\n";
35 my $content = join ("", <FI>);
38 open(POUT, "> $TEMPFILE") || die;
39 $content =~ s!//(.+)$!check_content($1)!egm;
40 $content =~ s!/\*(.+?)\*/!check_content($1)!egs;
43 open(PIN, "ispell -d american -p $DICTFILE -l < $TEMPFILE | sort -uf |") || die;
45 while (my $err = <PIN>) {
47 push(@badwords, $err) if ($err =~ /\w/ && length($err)>0);
52 print "$file: ".scalar(@badwords)." errors: '".join("','",@badwords)."'\n";