* [PATCH 0/3] checkincludes.pl: add removal option
@ 2009-08-06 0:51 Luis R. Rodriguez
2009-08-06 0:51 ` [PATCH 1/3] checkincludes.pl: close file as soon as we're done with it Luis R. Rodriguez
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Luis R. Rodriguez @ 2009-08-06 0:51 UTC (permalink / raw)
To: akpm, joe, torvalds; +Cc: linux-kernel, mcgrof, Luis R. Rodriguez
This lets you remove duplicate includes headers in place with
checkincludes.pl, that is, the same file is overwritten with -r.
This actually makes this useful for me for porting crap drivers
where I have to do this a lot.
I don't know who these go through so sending to a few of you.
Luis R. Rodriguez (3):
checkincludes.pl: close file as soon as we're done with it
checkincludes.pl: provide usage helper
checkincludes.pl: add option to remove duplicates in place
scripts/checkincludes.pl | 62 +++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 58 insertions(+), 4 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/3] checkincludes.pl: close file as soon as we're done with it 2009-08-06 0:51 [PATCH 0/3] checkincludes.pl: add removal option Luis R. Rodriguez @ 2009-08-06 0:51 ` Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 2/3] checkincludes.pl: provide usage helper Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 3/3] checkincludes.pl: add option to remove duplicates in place Luis R. Rodriguez 2 siblings, 0 replies; 7+ messages in thread From: Luis R. Rodriguez @ 2009-08-06 0:51 UTC (permalink / raw) To: akpm, joe, torvalds; +Cc: linux-kernel, mcgrof, Luis R. Rodriguez Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> --- scripts/checkincludes.pl | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl index 8e6b716..32ebff6 100755 --- a/scripts/checkincludes.pl +++ b/scripts/checkincludes.pl @@ -13,12 +13,12 @@ foreach $file (@ARGV) { ++$includedfiles{$1}; } } + + close(FILE); foreach $filename (keys %includedfiles) { if ($includedfiles{$filename} > 1) { print "$file: $filename is included more than once.\n"; } } - - close(FILE); } -- 1.6.3.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] checkincludes.pl: provide usage helper 2009-08-06 0:51 [PATCH 0/3] checkincludes.pl: add removal option Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 1/3] checkincludes.pl: close file as soon as we're done with it Luis R. Rodriguez @ 2009-08-06 0:51 ` Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 3/3] checkincludes.pl: add option to remove duplicates in place Luis R. Rodriguez 2 siblings, 0 replies; 7+ messages in thread From: Luis R. Rodriguez @ 2009-08-06 0:51 UTC (permalink / raw) To: akpm, joe, torvalds; +Cc: linux-kernel, mcgrof, Luis R. Rodriguez Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> --- scripts/checkincludes.pl | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl index 32ebff6..4bff139 100755 --- a/scripts/checkincludes.pl +++ b/scripts/checkincludes.pl @@ -3,6 +3,15 @@ # checkincludes: Find files included more than once in (other) files. # Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>. +sub usage { + print "Usage: checkincludes.pl <file list>\n"; + exit 1; +} + +if ($#ARGV < 0) { + usage(); +} + foreach $file (@ARGV) { open(FILE, $file) or die "Cannot open $file: $!.\n"; -- 1.6.3.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] checkincludes.pl: add option to remove duplicates in place 2009-08-06 0:51 [PATCH 0/3] checkincludes.pl: add removal option Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 1/3] checkincludes.pl: close file as soon as we're done with it Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 2/3] checkincludes.pl: provide usage helper Luis R. Rodriguez @ 2009-08-06 0:51 ` Luis R. Rodriguez 2009-08-06 1:59 ` Andrew Morton 2 siblings, 1 reply; 7+ messages in thread From: Luis R. Rodriguez @ 2009-08-06 0:51 UTC (permalink / raw) To: akpm, joe, torvalds; +Cc: linux-kernel, mcgrof, Luis R. Rodriguez checkincludes.pl is more useful if it actually removed the lines. This adds support for that with -r. Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> --- scripts/checkincludes.pl | 57 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 51 insertions(+), 6 deletions(-) diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl index 4bff139..5a53407 100755 --- a/scripts/checkincludes.pl +++ b/scripts/checkincludes.pl @@ -2,32 +2,77 @@ # # checkincludes: Find files included more than once in (other) files. # Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>. +# Copyright abandoned, 2009, Luis R. Rodriguez <mcgrof@gmail.com> sub usage { - print "Usage: checkincludes.pl <file list>\n"; + print "Usage: checkincludes.pl [-r]\n"; + print "By default we just warn of duplicates\n"; + print "To remove files in place use -r\n"; exit 1; } +my $remove = 0; + if ($#ARGV < 0) { - usage(); + usage(); +} + +if ($#ARGV >= 1) { + if ($ARGV[0] =~ /^-/) { + if ($ARGV[0] eq "-r") { + $remove = 1; + shift; + } else { + usage(); + } + } } foreach $file (@ARGV) { open(FILE, $file) or die "Cannot open $file: $!.\n"; my %includedfiles = (); + my @file_lines = (); while (<FILE>) { if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { ++$includedfiles{$1}; } + push(@file_lines, $_); } close(FILE); - - foreach $filename (keys %includedfiles) { - if ($includedfiles{$filename} > 1) { - print "$file: $filename is included more than once.\n"; + + if (!$remove) { + foreach $filename (keys %includedfiles) { + if ($includedfiles{$filename} > 1) { + print "$file: $filename is included more than once.\n"; + } } + next; } + + open(FILE,">$file") || die("Cannot write to $file: $!"); + + my $dups = 0; + foreach (@file_lines) { + if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { + foreach $filename (keys %includedfiles) { + if ($1 eq $filename) { + if ($includedfiles{$filename} > 1) { + $includedfiles{$filename}--; + $dups++; + } else { + print FILE $_; + } + } + } + } else { + print FILE $_; + } + } + if ($dups > 0) { + print "$file: removed $dups duplicate includes\n"; + } + close(FILE); } -- 1.6.3.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] checkincludes.pl: add option to remove duplicates in place 2009-08-06 0:51 ` [PATCH 3/3] checkincludes.pl: add option to remove duplicates in place Luis R. Rodriguez @ 2009-08-06 1:59 ` Andrew Morton 2009-08-06 2:10 ` Luis R. Rodriguez 2009-08-06 19:17 ` Daniel K. 0 siblings, 2 replies; 7+ messages in thread From: Andrew Morton @ 2009-08-06 1:59 UTC (permalink / raw) To: Luis R. Rodriguez; +Cc: joe, torvalds, linux-kernel, mcgrof On Wed, 5 Aug 2009 17:51:12 -0700 "Luis R. Rodriguez" <lrodriguez@Atheros.com> wrote: > checkincludes.pl is more useful if it actually removed > the lines. This adds support for that with -r. > hm, spose so. It can't do any harm. Plus it's about time we edited that file - it hasn't been changed since we started the bk tree. > --- > scripts/checkincludes.pl | 57 +++++++++++++++++++++++++++++++++++++++++----- > 1 files changed, 51 insertions(+), 6 deletions(-) > > diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl > index 4bff139..5a53407 100755 > --- a/scripts/checkincludes.pl > +++ b/scripts/checkincludes.pl > @@ -2,32 +2,77 @@ > # > # checkincludes: Find files included more than once in (other) files. > # Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>. > +# Copyright abandoned, 2009, Luis R. Rodriguez <mcgrof@gmail.com> > > sub usage { > - print "Usage: checkincludes.pl <file list>\n"; > + print "Usage: checkincludes.pl [-r]\n"; > + print "By default we just warn of duplicates\n"; > + print "To remove files in place use -r\n"; I'm not sure I like the wording here - I don't _want_ my files removed! This? --- a/scripts/checkincludes.pl~checkincludespl-add-option-to-remove-duplicates-in-place-fix +++ a/scripts/checkincludes.pl @@ -7,7 +7,7 @@ sub usage { print "Usage: checkincludes.pl [-r]\n"; print "By default we just warn of duplicates\n"; - print "To remove files in place use -r\n"; + print "To remove duplicated includes in place use -r\n"; exit 1; } _ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] checkincludes.pl: add option to remove duplicates in place 2009-08-06 1:59 ` Andrew Morton @ 2009-08-06 2:10 ` Luis R. Rodriguez 2009-08-06 19:17 ` Daniel K. 1 sibling, 0 replies; 7+ messages in thread From: Luis R. Rodriguez @ 2009-08-06 2:10 UTC (permalink / raw) To: Andrew Morton Cc: Luis Rodriguez, joe@perches.com, torvalds@linux-foundation.org, linux-kernel@vger.kernel.org, mcgrof@gmail.com On Wed, Aug 05, 2009 at 06:59:45PM -0700, Andrew Morton wrote: > On Wed, 5 Aug 2009 17:51:12 -0700 "Luis R. Rodriguez" <lrodriguez@Atheros.com> wrote: > > > checkincludes.pl is more useful if it actually removed > > the lines. This adds support for that with -r. > > > > hm, spose so. It can't do any harm. > > Plus it's about time we edited that file - it hasn't been changed since > we started the bk tree. Hehe yeah.. Anno Domini > > --- > > scripts/checkincludes.pl | 57 +++++++++++++++++++++++++++++++++++++++++----- > > 1 files changed, 51 insertions(+), 6 deletions(-) > > > > diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl > > index 4bff139..5a53407 100755 > > --- a/scripts/checkincludes.pl > > +++ b/scripts/checkincludes.pl > > @@ -2,32 +2,77 @@ > > # > > # checkincludes: Find files included more than once in (other) files. > > # Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>. > > +# Copyright abandoned, 2009, Luis R. Rodriguez <mcgrof@gmail.com> > > > > sub usage { > > - print "Usage: checkincludes.pl <file list>\n"; > > + print "Usage: checkincludes.pl [-r]\n"; > > + print "By default we just warn of duplicates\n"; > > + print "To remove files in place use -r\n"; > > I'm not sure I like the wording here - I don't _want_ my files removed! > > This? > > --- a/scripts/checkincludes.pl~checkincludespl-add-option-to-remove-duplicates-in-place-fix > +++ a/scripts/checkincludes.pl > @@ -7,7 +7,7 @@ > sub usage { > print "Usage: checkincludes.pl [-r]\n"; > print "By default we just warn of duplicates\n"; > - print "To remove files in place use -r\n"; > + print "To remove duplicated includes in place use -r\n"; > exit 1; > } Sure, attached new v2 From: Luis R. Rodriguez <lrodriguez@atheros.com> Subject: [PATCH v2] checkincludes.pl: add option to remove duplicates in place checkincludes.pl is more useful if it actually removed the lines. This adds support for that with -r. Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com> --- Now with Andrew's change in place and some sort of documentation added. scripts/checkincludes.pl | 66 +++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 59 insertions(+), 7 deletions(-) diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl index 4bff139..676ddc0 100755 --- a/scripts/checkincludes.pl +++ b/scripts/checkincludes.pl @@ -1,33 +1,85 @@ #!/usr/bin/perl # -# checkincludes: Find files included more than once in (other) files. +# checkincludes: find/remove files included more than once +# # Copyright abandoned, 2000, Niels Kristian Bech Jensen <nkbj@image.dk>. +# Copyright 2009 Luis R. Rodriguez <mcgrof@gmail.com> +# +# This script checks for duplicate includes. It also has support +# to remove them in place. Note that this will not take into +# consideration macros so you should run this only if you know +# you do have real dups and do not have them under #ifdef's. You +# could also just review the results. sub usage { - print "Usage: checkincludes.pl <file list>\n"; + print "Usage: checkincludes.pl [-r]\n"; + print "By default we just warn of duplicates\n"; + print "To remove duplicated includes in place use -r\n"; exit 1; } +my $remove = 0; + if ($#ARGV < 0) { - usage(); + usage(); +} + +if ($#ARGV >= 1) { + if ($ARGV[0] =~ /^-/) { + if ($ARGV[0] eq "-r") { + $remove = 1; + shift; + } else { + usage(); + } + } } foreach $file (@ARGV) { open(FILE, $file) or die "Cannot open $file: $!.\n"; my %includedfiles = (); + my @file_lines = (); while (<FILE>) { if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { ++$includedfiles{$1}; } + push(@file_lines, $_); } close(FILE); - - foreach $filename (keys %includedfiles) { - if ($includedfiles{$filename} > 1) { - print "$file: $filename is included more than once.\n"; + + if (!$remove) { + foreach $filename (keys %includedfiles) { + if ($includedfiles{$filename} > 1) { + print "$file: $filename is included more than once.\n"; + } } + next; } + + open(FILE,">$file") || die("Cannot write to $file: $!"); + + my $dups = 0; + foreach (@file_lines) { + if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) { + foreach $filename (keys %includedfiles) { + if ($1 eq $filename) { + if ($includedfiles{$filename} > 1) { + $includedfiles{$filename}--; + $dups++; + } else { + print FILE $_; + } + } + } + } else { + print FILE $_; + } + } + if ($dups > 0) { + print "$file: removed $dups duplicate includes\n"; + } + close(FILE); } -- 1.6.3.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] checkincludes.pl: add option to remove duplicates in place 2009-08-06 1:59 ` Andrew Morton 2009-08-06 2:10 ` Luis R. Rodriguez @ 2009-08-06 19:17 ` Daniel K. 1 sibling, 0 replies; 7+ messages in thread From: Daniel K. @ 2009-08-06 19:17 UTC (permalink / raw) To: Andrew Morton; +Cc: Luis R. Rodriguez, joe, torvalds, linux-kernel, mcgrof Andrew Morton wrote: > On Wed, 5 Aug 2009 17:51:12 -0700 "Luis R. Rodriguez" <lrodriguez@Atheros.com> wrote: >> - print "Usage: checkincludes.pl <file list>\n"; >> + print "Usage: checkincludes.pl [-r]\n"; >> + print "By default we just warn of duplicates\n"; >> + print "To remove files in place use -r\n"; > > I'm not sure I like the wording here - I don't _want_ my files removed! > > This? > > --- a/scripts/checkincludes.pl~checkincludespl-add-option-to-remove-duplicates-in-place-fix > +++ a/scripts/checkincludes.pl > @@ -7,7 +7,7 @@ > sub usage { > print "Usage: checkincludes.pl [-r]\n"; > print "By default we just warn of duplicates\n"; > - print "To remove files in place use -r\n"; > + print "To remove duplicated includes in place use -r\n"; > exit 1; > } > And perhaps the '<file list>' should be kept as well, for documentation? --- a/scripts/checkincludes.pl +++ a/scripts/checkincludes.pl @@ -5,7 +5,7 @@ # Copyright abandoned, 2009, Luis R. Rodriguez <mcgrof@gmail.com> sub usage { - print "Usage: checkincludes.pl [-r]\n"; + print "Usage: checkincludes.pl [-r] <file list>\n"; print "By default we just warn of duplicates\n"; print "To remove duplicated includes in place use -r\n"; exit 1; Daniel K. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2009-08-06 19:28 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2009-08-06 0:51 [PATCH 0/3] checkincludes.pl: add removal option Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 1/3] checkincludes.pl: close file as soon as we're done with it Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 2/3] checkincludes.pl: provide usage helper Luis R. Rodriguez 2009-08-06 0:51 ` [PATCH 3/3] checkincludes.pl: add option to remove duplicates in place Luis R. Rodriguez 2009-08-06 1:59 ` Andrew Morton 2009-08-06 2:10 ` Luis R. Rodriguez 2009-08-06 19:17 ` Daniel K.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox