[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <37535426fad04587289023e3dcc705a438c59ef6.camel@perches.com>
Date: Thu, 28 Jan 2021 11:11:05 -0800
From: Joe Perches <joe@...ches.com>
To: Dwaipayan Ray <dwaipayanray1@...il.com>
Cc: linux-kernel-mentees@...ts.linuxfoundation.org,
lukas.bulwahn@...il.com, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v2 1/3] checkpatch: add verbose mode
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.
[]
> 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.
Powered by blists - more mailing lists