...and a big step for learning more Perl.
Hi!
This patch set started off as an experiment, but as I continued, I
realised that I should submit this and see if it's suitable for merging
into Linux.
To start off with, here's some patches for checkincludes.pl
This set was created for the following purposes:
1: Making it slightly easier to read
2: Making it easier to extend and add new arguments
3: Changing the usage output to look more "correct"
4: Introducing a 'quiet' mode like checkpatch.pl, and printing
messages for files without duplicated includes by default
Sorry if I did anything wrong - It's my first time really
experimenting with Perl.
Thanks in advance.
~Cruz
Cruz Julian Bishop (4):
scripts/checkincludes.pl: Print usage with heredoc
scripts/checkincludes.pl: Simplify and shorten argument logic
scripts/checkincludes.pl: Fix a bug introduced in the last commit
scripts/checkincludes.pl: Introduce 'quiet' mode
scripts/checkincludes.pl | 113 ++++++++++++++++++++++++++--------------------
1 file changed, 65 insertions(+), 48 deletions(-)
--
1.7.9.5
This is already used in checkpatch.pl, and is easier to
read, so I am changing it in checkincludes as well.
Additionally, this makes the usage output theoretically
easier to edit. In practise, there's almost no difference
Signed-off-by: Cruz Julian Bishop <[email protected]>
---
scripts/checkincludes.pl | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl
index 97b2c61..801ed5f 100755
--- a/scripts/checkincludes.pl
+++ b/scripts/checkincludes.pl
@@ -14,9 +14,13 @@
use strict;
sub usage {
- 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";
+ print <<EOM;
+Usage: checkincludes.pl [OPTIONS]... FILE...
+By default, we just warn of duplicates.
+
+Options:
+ -r Remove duplicated includes in place
+EOM
exit 1;
}
--
1.7.9.5
Since the previous commit, simply specifying -r without any files
caused no message to be displayed.
Before said commit, the usage() function was called.
This commit simply calls the usage() function if no files were
specified - This includes once other arguments are supported.
Signed-off-by: Cruz Julian Bishop <[email protected]>
---
scripts/checkincludes.pl | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl
index 7d713c2..cde7ce1 100755
--- a/scripts/checkincludes.pl
+++ b/scripts/checkincludes.pl
@@ -30,12 +30,16 @@ if ($#ARGV < 0) {
usage();
}
+my $argc = 0;
+
foreach my $arg (@ARGV) {
if ($arg eq "-r") {
$remove = 1;
} else {
open(my $f, '<', $arg)
or die "Cannot open $arg: $!.\n";
+
+ $argc++;
my %includedfiles = ();
my @file_lines = ();
@@ -84,3 +88,7 @@ foreach my $arg (@ARGV) {
close($f);
}
}
+
+if ($argc == 0) {
+ usage();
+}
--
1.7.9.5
This patch allows for much easier implementation of arguments
when modifying checkincludes.pl
The variable $file is also initially named $arg - I wasn't sure
if memory would be a problem (I know it would be in Java/C#) if
another $file variable was initialized with the value of $arg,
so I just left it.
Overall, this still works nicely. There are some more
potential simplifications, but I will cover those in another
patch if I decide to implement them tonight.
Signed-off-by: Cruz Julian Bishop <[email protected]>
---
scripts/checkincludes.pl | 85 +++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 46 deletions(-)
diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl
index 801ed5f..7d713c2 100755
--- a/scripts/checkincludes.pl
+++ b/scripts/checkincludes.pl
@@ -30,64 +30,57 @@ if ($#ARGV < 0) {
usage();
}
-if ($#ARGV >= 1) {
- if ($ARGV[0] =~ /^-/) {
- if ($ARGV[0] eq "-r") {
- $remove = 1;
- shift;
- } else {
- usage();
- }
- }
-}
+foreach my $arg (@ARGV) {
+ if ($arg eq "-r") {
+ $remove = 1;
+ } else {
+ open(my $f, '<', $arg)
+ or die "Cannot open $arg: $!.\n";
-foreach my $file (@ARGV) {
- open(my $f, '<', $file)
- or die "Cannot open $file: $!.\n";
+ my %includedfiles = ();
+ my @file_lines = ();
- my %includedfiles = ();
- my @file_lines = ();
-
- while (<$f>) {
- if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
- ++$includedfiles{$1};
+ while (<$f>) {
+ if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
+ ++$includedfiles{$1};
+ }
+ push(@file_lines, $_);
}
- push(@file_lines, $_);
- }
- close($f);
+ close($f);
- if (!$remove) {
- foreach my $filename (keys %includedfiles) {
- if ($includedfiles{$filename} > 1) {
- print "$file: $filename is included more than once.\n";
+ if (!$remove) {
+ foreach my $filename (keys %includedfiles) {
+ if ($includedfiles{$filename} > 1) {
+ print "$arg: $filename is included more than once.\n";
+ }
}
+ next;
}
- next;
- }
- open($f, '>', $file)
- or die("Cannot write to $file: $!");
+ open($f, '>', $arg)
+ or die("Cannot write to $arg: $!");
- my $dups = 0;
- foreach (@file_lines) {
- if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
- foreach my $filename (keys %includedfiles) {
- if ($1 eq $filename) {
- if ($includedfiles{$filename} > 1) {
- $includedfiles{$filename}--;
- $dups++;
- } else {
- print {$f} $_;
+ my $dups = 0;
+ foreach(@file_lines) {
+ if (m/^\s*#\s*include\s*[<"](\S*)[>"]/o) {
+ foreach my $filename (keys %includedfiles) {
+ if ($1 eq $filename) {
+ if ($includedfiles{$filename} > 1) {
+ $includedfiles{$filename}--;
+ $dups++;
+ } else {
+ print {$f} $_;
+ }
}
}
+ } else {
+ print {$f} $_;
}
- } else {
- print {$f} $_;
}
+ if ($dups > 0) {
+ print "$arg: removed $dups duplicate includes \n";
+ }
+ close($f);
}
- if ($dups > 0) {
- print "$file: removed $dups duplicate includes\n";
- }
- close($f);
}
--
1.7.9.5
In order to make checkincludes more like checkpatch in terms
of functionality, I have introduced a 'quiet' mode.
This mode can be turned on with the -q argument.
When not in quiet mode, each file that does not have duplicated
includes will have a message generated. Not having this is
sometimes annoying when performing checks on a single file
or directory without problems - "No output, does that mean it's
all good or I wrote the wrong command?"
Signed-off-by: Cruz Julian Bishop <[email protected]>
---
scripts/checkincludes.pl | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/scripts/checkincludes.pl b/scripts/checkincludes.pl
index cde7ce1..bff7316 100755
--- a/scripts/checkincludes.pl
+++ b/scripts/checkincludes.pl
@@ -20,11 +20,14 @@ By default, we just warn of duplicates.
Options:
-r Remove duplicated includes in place
+ -q Do not show messages for files that do not
+ have duplicated includes
EOM
exit 1;
}
my $remove = 0;
+my $quiet = 0;
if ($#ARGV < 0) {
usage();
@@ -35,6 +38,8 @@ my $argc = 0;
foreach my $arg (@ARGV) {
if ($arg eq "-r") {
$remove = 1;
+ } elsif($arg eq "-q") {
+ $quiet = 1;
} else {
open(my $f, '<', $arg)
or die "Cannot open $arg: $!.\n";
@@ -54,11 +59,16 @@ foreach my $arg (@ARGV) {
close($f);
if (!$remove) {
+ my $detected = 0;
foreach my $filename (keys %includedfiles) {
if ($includedfiles{$filename} > 1) {
+ $detected++;
print "$arg: $filename is included more than once.\n";
}
}
+ if (!$detected && !$quiet) {
+ print "$arg: No duplicated includes detected.\n";
+ }
next;
}
@@ -84,6 +94,8 @@ foreach my $arg (@ARGV) {
}
if ($dups > 0) {
print "$arg: removed $dups duplicate includes \n";
+ } elsif (!$quiet) {
+ print "$arg: no duplicated includes to remove \n";
}
close($f);
}
--
1.7.9.5
Ah, the wonders of having no coffee. I only just realized that
I wrote checkpatch instead of checkincludes!
Should I resubmit this patch series, or just leave it since it's
already on the mailing list?
On 31/08/12 23:18, Cruz Julian Bishop wrote:
> ...and a big step for learning more Perl.
>
> Hi!
>
> This patch set started off as an experiment, but as I continued, I
> realised that I should submit this and see if it's suitable for merging
> into Linux.
>
> To start off with, here's some patches for checkincludes.pl
>
> This set was created for the following purposes:
>
> 1: Making it slightly easier to read
> 2: Making it easier to extend and add new arguments
> 3: Changing the usage output to look more "correct"
> 4: Introducing a 'quiet' mode like checkpatch.pl, and printing
> messages for files without duplicated includes by default
>
> Sorry if I did anything wrong - It's my first time really
> experimenting with Perl.
>
> Thanks in advance.
>
> ~Cruz
>
> Cruz Julian Bishop (4):
> scripts/checkincludes.pl: Print usage with heredoc
> scripts/checkincludes.pl: Simplify and shorten argument logic
> scripts/checkincludes.pl: Fix a bug introduced in the last commit
> scripts/checkincludes.pl: Introduce 'quiet' mode
>
> scripts/checkincludes.pl | 113 ++++++++++++++++++++++++++--------------------
> 1 file changed, 65 insertions(+), 48 deletions(-)
>
On Fri, 2012-08-31 at 23:18 +1000, Cruz Julian Bishop wrote:
> This patch allows for much easier implementation of arguments
> when modifying checkincludes.pl
>
> The variable $file is also initially named $arg - I wasn't sure
> if memory would be a problem (I know it would be in Java/C#) if
> another $file variable was initialized with the value of $arg,
> so I just left it.
>
> Overall, this still works nicely. There are some more
> potential simplifications, but I will cover those in another
> patch if I decide to implement them tonight.
perl argument processing is normally done via Getopt::Long.
http://perldoc.perl.org/Getopt/Long.html
On Fri, 31 Aug 2012, Cruz Julian Bishop wrote:
> ...and a big step for learning more Perl.
>
> Hi!
>
> This patch set started off as an experiment, but as I continued, I
> realised that I should submit this and see if it's suitable for merging
> into Linux.
>
> To start off with, here's some patches for checkincludes.pl
>
> This set was created for the following purposes:
>
> 1: Making it slightly easier to read
> 2: Making it easier to extend and add new arguments
> 3: Changing the usage output to look more "correct"
> 4: Introducing a 'quiet' mode like checkpatch.pl, and printing
> messages for files without duplicated includes by default
>
> Sorry if I did anything wrong - It's my first time really
> experimenting with Perl.
>
> Thanks in advance.
>
> ~Cruz
>
> Cruz Julian Bishop (4):
> scripts/checkincludes.pl: Print usage with heredoc
> scripts/checkincludes.pl: Simplify and shorten argument logic
> scripts/checkincludes.pl: Fix a bug introduced in the last commit
> scripts/checkincludes.pl: Introduce 'quiet' mode
>
> scripts/checkincludes.pl | 113 ++++++++++++++++++++++++++--------------------
> 1 file changed, 65 insertions(+), 48 deletions(-)
>
>
Minor detail. Your patches are for "scripts/checkincludes.pl" but the
subject says "scripts/checkpatch.pl"... You may want to get it straight
what you are patching and let the subject reflect reality :-)
--
Jesper Juhl <[email protected]> http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.
On 01/09/12 01:42, Joe Perches wrote:
> On Fri, 2012-08-31 at 23:18 +1000, Cruz Julian Bishop wrote:
>> This patch allows for much easier implementation of arguments
>> when modifying checkincludes.pl
>>
>> The variable $file is also initially named $arg - I wasn't sure
>> if memory would be a problem (I know it would be in Java/C#) if
>> another $file variable was initialized with the value of $arg,
>> so I just left it.
>>
>> Overall, this still works nicely. There are some more
>> potential simplifications, but I will cover those in another
>> patch if I decide to implement them tonight.
> perl argument processing is normally done via Getopt::Long.
>
> http://perldoc.perl.org/Getopt/Long.html
>
Okay, thank you. I'll go look at that now
On 01/09/12 04:09, Jesper Juhl wrote:
> On Fri, 31 Aug 2012, Cruz Julian Bishop wrote:
>
>> ...and a big step for learning more Perl.
>>
>> Hi!
>>
>> This patch set started off as an experiment, but as I continued, I
>> realised that I should submit this and see if it's suitable for merging
>> into Linux.
>>
>> To start off with, here's some patches for checkincludes.pl
>>
>> This set was created for the following purposes:
>>
>> 1: Making it slightly easier to read
>> 2: Making it easier to extend and add new arguments
>> 3: Changing the usage output to look more "correct"
>> 4: Introducing a 'quiet' mode like checkpatch.pl, and printing
>> messages for files without duplicated includes by default
>>
>> Sorry if I did anything wrong - It's my first time really
>> experimenting with Perl.
>>
>> Thanks in advance.
>>
>> ~Cruz
>>
>> Cruz Julian Bishop (4):
>> scripts/checkincludes.pl: Print usage with heredoc
>> scripts/checkincludes.pl: Simplify and shorten argument logic
>> scripts/checkincludes.pl: Fix a bug introduced in the last commit
>> scripts/checkincludes.pl: Introduce 'quiet' mode
>>
>> scripts/checkincludes.pl | 113 ++++++++++++++++++++++++++--------------------
>> 1 file changed, 65 insertions(+), 48 deletions(-)
>>
>>
> Minor detail. Your patches are for "scripts/checkincludes.pl" but the
> subject says "scripts/checkpatch.pl"... You may want to get it straight
> what you are patching and let the subject reflect reality :-)
>
Yeah, I ended up writing the cover letter at 11:30 at night without any
coffee :-)
I'll look at a link that Joe Perches sent me then resubmit this
Thanks.
~Cruz