aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl52
1 files changed, 35 insertions, 17 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d2c074feaa7d..65bb50076632 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -55,6 +55,7 @@ my $spelling_file = "$D/spelling.txt";
55my $codespell = 0; 55my $codespell = 0;
56my $codespellfile = "/usr/share/codespell/dictionary.txt"; 56my $codespellfile = "/usr/share/codespell/dictionary.txt";
57my $conststructsfile = "$D/const_structs.checkpatch"; 57my $conststructsfile = "$D/const_structs.checkpatch";
58my $typedefsfile = "";
58my $color = 1; 59my $color = 1;
59my $allow_c99_comments = 1; 60my $allow_c99_comments = 1;
60 61
@@ -113,6 +114,7 @@ Options:
113 --codespell Use the codespell dictionary for spelling/typos 114 --codespell Use the codespell dictionary for spelling/typos
114 (default:/usr/share/codespell/dictionary.txt) 115 (default:/usr/share/codespell/dictionary.txt)
115 --codespellfile Use this codespell dictionary 116 --codespellfile Use this codespell dictionary
117 --typedefsfile Read additional types from this file
116 --color Use colors when output is STDOUT (default: on) 118 --color Use colors when output is STDOUT (default: on)
117 -h, --help, --version display this help and exit 119 -h, --help, --version display this help and exit
118 120
@@ -208,6 +210,7 @@ GetOptions(
208 'test-only=s' => \$tst_only, 210 'test-only=s' => \$tst_only,
209 'codespell!' => \$codespell, 211 'codespell!' => \$codespell,
210 'codespellfile=s' => \$codespellfile, 212 'codespellfile=s' => \$codespellfile,
213 'typedefsfile=s' => \$typedefsfile,
211 'color!' => \$color, 214 'color!' => \$color,
212 'h|help' => \$help, 215 'h|help' => \$help,
213 'version' => \$help 216 'version' => \$help
@@ -629,28 +632,43 @@ if ($codespell) {
629 632
630$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; 633$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
631 634
632my $const_structs = ""; 635sub read_words {
633if (open(my $conststructs, '<', $conststructsfile)) { 636 my ($wordsRef, $file) = @_;
634 while (<$conststructs>) {
635 my $line = $_;
636 637
637 $line =~ s/\s*\n?$//g; 638 if (open(my $words, '<', $file)) {
638 $line =~ s/^\s*//g; 639 while (<$words>) {
640 my $line = $_;
639 641
640 next if ($line =~ m/^\s*#/); 642 $line =~ s/\s*\n?$//g;
641 next if ($line =~ m/^\s*$/); 643 $line =~ s/^\s*//g;
642 if ($line =~ /\s/) {
643 print("$conststructsfile: '$line' invalid - ignored\n");
644 next;
645 }
646 644
647 $const_structs .= '|' if ($const_structs ne ""); 645 next if ($line =~ m/^\s*#/);
648 $const_structs .= $line; 646 next if ($line =~ m/^\s*$/);
647 if ($line =~ /\s/) {
648 print("$file: '$line' invalid - ignored\n");
649 next;
650 }
651
652 $$wordsRef .= '|' if ($$wordsRef ne "");
653 $$wordsRef .= $line;
654 }
655 close($file);
656 return 1;
649 } 657 }
650 close($conststructsfile); 658
651} else { 659 return 0;
652 warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; 660}
661
662my $const_structs = "";
663read_words(\$const_structs, $conststructsfile)
664 or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
665
666my $typeOtherTypedefs = "";
667if (length($typedefsfile)) {
668 read_words(\$typeOtherTypedefs, $typedefsfile)
669 or warn "No additional types will be considered - file '$typedefsfile': $!\n";
653} 670}
671$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne "");
654 672
655sub build_types { 673sub build_types {
656 my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; 674 my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";