~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/scripts/checkincludes.pl

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /scripts/checkincludes.pl (Version linux-6.12-rc7) and /scripts/checkincludes.pl (Version linux-4.4.302)


  1 #!/usr/bin/env perl                            !!   1 #!/usr/bin/perl
  2 # SPDX-License-Identifier: GPL-2.0             << 
  3 #                                                   2 #
  4 # checkincludes: find/remove files included mo      3 # checkincludes: find/remove files included more than once
  5 #                                                   4 #
  6 # Copyright abandoned, 2000, Niels Kristian Be<      5 # Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>.
  7 # Copyright 2009 Luis R. Rodriguez <mcgrof@gmai      6 # Copyright 2009 Luis R. Rodriguez <mcgrof@gmail.com>
  8 #                                                   7 #
  9 # This script checks for duplicate includes. I      8 # This script checks for duplicate includes. It also has support
 10 # to remove them in place. Note that this will      9 # to remove them in place. Note that this will not take into
 11 # consideration macros so you should run this      10 # consideration macros so you should run this only if you know
 12 # you do have real dups and do not have them u     11 # you do have real dups and do not have them under #ifdef's. You
 13 # could also just review the results.              12 # could also just review the results.
 14                                                    13 
 15 use strict;                                        14 use strict;
 16                                                    15 
 17 sub usage {                                        16 sub usage {
 18         print "Usage: checkincludes.pl [-r]\n"     17         print "Usage: checkincludes.pl [-r]\n";
 19         print "By default we just warn of dupl     18         print "By default we just warn of duplicates\n";
 20         print "To remove duplicated includes i     19         print "To remove duplicated includes in place use -r\n";
 21         exit 1;                                    20         exit 1;
 22 }                                                  21 }
 23                                                    22 
 24 my $remove = 0;                                    23 my $remove = 0;
 25                                                    24 
 26 if ($#ARGV < 0) {                                  25 if ($#ARGV < 0) {
 27         usage();                                   26         usage();
 28 }                                                  27 }
 29                                                    28 
 30 if ($#ARGV >= 1) {                                 29 if ($#ARGV >= 1) {
 31         if ($ARGV[0] =~ /^-/) {                    30         if ($ARGV[0] =~ /^-/) {
 32                 if ($ARGV[0] eq "-r") {            31                 if ($ARGV[0] eq "-r") {
 33                         $remove = 1;               32                         $remove = 1;
 34                         shift;                     33                         shift;
 35                 } else {                           34                 } else {
 36                         usage();                   35                         usage();
 37                 }                                  36                 }
 38         }                                          37         }
 39 }                                                  38 }
 40                                                    39 
 41 my $dup_counter = 0;                           << 
 42                                                << 
 43 foreach my $file (@ARGV) {                         40 foreach my $file (@ARGV) {
 44         open(my $f, '<', $file)                    41         open(my $f, '<', $file)
 45             or die "Cannot open $file: $!.\n";     42             or die "Cannot open $file: $!.\n";
 46                                                    43 
 47         my %includedfiles = ();                    44         my %includedfiles = ();
 48         my @file_lines = ();                       45         my @file_lines = ();
 49                                                    46 
 50         while (<$f>) {                             47         while (<$f>) {
 51                 if (m/^\s*#\s*include\s*[<"](\     48                 if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
 52                         ++$includedfiles{$1};      49                         ++$includedfiles{$1};
 53                 }                                  50                 }
 54                 push(@file_lines, $_);             51                 push(@file_lines, $_);
 55         }                                          52         }
 56                                                    53 
 57         close($f);                                 54         close($f);
 58                                                    55 
 59         if (!$remove) {                            56         if (!$remove) {
 60                 foreach my $filename (keys %in     57                 foreach my $filename (keys %includedfiles) {
 61                         if ($includedfiles{$fi     58                         if ($includedfiles{$filename} > 1) {
 62                                 print "$file:      59                                 print "$file: $filename is included more than once.\n";
 63                                 ++$dup_counter << 
 64                         }                          60                         }
 65                 }                                  61                 }
 66                 next;                              62                 next;
 67         }                                          63         }
 68                                                    64 
 69         open($f, '>', $file)                       65         open($f, '>', $file)
 70             or die("Cannot write to $file: $!"     66             or die("Cannot write to $file: $!");
 71                                                    67 
 72         my $dups = 0;                              68         my $dups = 0;
 73         foreach (@file_lines) {                    69         foreach (@file_lines) {
 74                 if (m/^\s*#\s*include\s*[<"](\     70                 if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
 75                         foreach my $filename (     71                         foreach my $filename (keys %includedfiles) {
 76                                 if ($1 eq $fil     72                                 if ($1 eq $filename) {
 77                                         if ($i     73                                         if ($includedfiles{$filename} > 1) {
 78                                                    74                                                 $includedfiles{$filename}--;
 79                                                    75                                                 $dups++;
 80                                                << 
 81                                         } else     76                                         } else {
 82                                                    77                                                 print {$f} $_;
 83                                         }          78                                         }
 84                                 }                  79                                 }
 85                         }                          80                         }
 86                 } else {                           81                 } else {
 87                         print {$f} $_;             82                         print {$f} $_;
 88                 }                                  83                 }
 89         }                                          84         }
 90         if ($dups > 0) {                           85         if ($dups > 0) {
 91                 print "$file: removed $dups du     86                 print "$file: removed $dups duplicate includes\n";
 92         }                                          87         }
 93         close($f);                                 88         close($f);
 94 }                                              << 
 95                                                << 
 96 if ($dup_counter == 0) {                       << 
 97         print "No duplicate includes found.\n" << 
 98 }                                                  89 }
                                                      

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php