Re: [Linux-kernel-mentees] [PATCH v2 1/3] checkpatch: add verbose mode
From: Joe Perches <joe@perches.com>
Date: 2021-01-28 20:31:42
Also in:
lkml
On Thu, 2021-01-28 at 20:08 +0530, Dwaipayan Ray wrote:
Add a new verbose mode to checkpatch.pl to emit additional verbose test descriptions. The verbose mode is optional and can be enabled by the flag -v or --verbose.
[]
quoted hunk ↗ jump to hunk
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
+sub load_docs {
+ open(my $docs, '<', "$docsfile")
+ or warn "$P: Can't read the documentation file $docsfile $!\n";
+
+ my @lines = ();
+ while (<$docs>) {
+ my $line = $_;
+
+ $line =~ s/\s*\n?$//g;chomp
+ push (@lines, $line);
+ }
+ close($docs);
+
+ my $linenr = 0;
+ my $cnt = scalar @lines;
+ while ($linenr < $cnt) {
+ while ($linenr < $cnt &&
+ $lines[$linenr++] !~ /^\:(.+)\:$/)
+ {
+ }
+
+ last if ($linenr >= $cnt);
+
+ my $type = $lines[$linenr - 1];
+ $type =~ s/^\:(.+)\:$/$1/;
+ my $message = '';
+
+ while ($linenr < $cnt &&
+ $lines[$linenr] =~ /^(?:\s+(.+)$|$)/) {
+ $message .= $1 if (defined $1);
+ $message .= "\n";
+ $linenr++;
+ }
+
+ $message = trim($message);
+ $verbose_messages{$type} = $message;
+ }
+}I think this is overly complicated. There's no need to read and store the entire file and then parse it. Just parse it line by line as its read. _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees