3 # Copyright (c) 2013-2022. 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.
18 die "Please install iamerican to use that script.\n"
19 unless (-r "/usr/lib/ispell/american.hash");
21 sub check_content($) {
24 print POUT "$content\n";
27 my $TEMPFILE="/tmp/spell.tmp";
28 my $DICTFILE="tools/internal/spell_dict.txt";
29 $DICTFILE="./spell_dict.txt" unless (-e $DICTFILE);
30 die "Call this script from its location or from the SimGrid root directory\n" unless (-e $DICTFILE);
32 die "Usage: ". ($DICTFILE eq "./spell_dict.txt"? "./":"tools/internal/")."spell_comments.pl "
33 ."`find ". ($DICTFILE eq "./spell_dict.txt"? "../../":".")." -name '*.[ch]' -o -name '*.hpp' -o -name '*.cpp' |grep -v smpi/mpich3-test|grep -v NAS | grep -v src/smpi/colls`\n"
34 unless scalar(@ARGV)>0;
37 foreach my $file (@ARGV) {
38 open (FI, $file) || die "Cannot open $file: $!\n";
39 my $content = join ("", <FI>);
42 open(POUT, "> $TEMPFILE") || die;
43 $content =~ s!//(.+)$!check_content($1)!egm;
44 $content =~ s!/\*(.+?)\*/!check_content($1)!egs;
47 open(PIN, "ispell -d american -p $DICTFILE -l < $TEMPFILE | sort -uf |") || die;
49 while (my $err = <PIN>) {
51 push(@badwords, $err) if ($err =~ /\w/ && length($err)>0);
56 print "$file: ".scalar(@badwords)." errors: '".join("','",@badwords)."'\n";
57 $total += scalar(@badwords);
61 print "Total: $total\n";