Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'smpi-topo'
[simgrid.git] / tools / spell / lspell.pl
1 #!/bin/perl
2
3 # Copyright (c) 2013-2014. The SimGrid Team.
4 # All rights reserved.
5
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.
8
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.
14
15 sub check_content($) {
16         my $content = shift;
17         $content =~ tr/*/ /;
18         print POUT "$content\n";
19 }
20
21 $TEMPFILE="/tmp/spell.tmp";
22 $STOPFILE=shift(@ARGV);
23
24 open(STOPFILE, $STOPFILE) || die "can't open stopword file $STOPFILE";
25 while (<STOPFILE>) {
26         chomp;
27         $stopped{$_}++;
28 }
29 close(STOPFILE);
30
31 foreach $file (@ARGV) {
32         open (FI, $file) || die $file;
33         $content = join ("", <FI>);
34         close (FI);
35
36         open(POUT, "> $TEMPFILE") || die;
37         $content =~ s!//(.+)$!check_content($1)!egm;
38         $content =~ s!/\*(.+?)\*/!check_content($1)!egs;
39         close(POUT);
40
41         open(PIN, "ispell -d american -l < $TEMPFILE | sort -uf |") || die;
42         undef @badwords;
43         while (<PIN>) {
44                 chomp;
45                 if ($stopped{$_} == 0) {
46                         push(@badwords, $_);
47                 }
48         }
49         close(PIN) || die;
50
51         if (@badwords) {
52                 print "$file: ".scalar(@badwords)."\n\n";
53                 print join(" ",@badwords)."\n\n";
54         }
55 }