From: Jani Nikula <jani.nikula@linux.intel.com>
To: Jonathan Corbet <corbet@lwn.net>, linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, mchehab@kernel.org, me@tobin.cc,
Jonathan Corbet <corbet@lwn.net>
Subject: Re: [PATCH 4/8] docs: kernel-doc: Move STATE_NAME processing into its own function
Date: Fri, 09 Feb 2018 11:27:20 +0200 [thread overview]
Message-ID: <87a7wia4xz.fsf@intel.com> (raw)
In-Reply-To: <20180207172624.24555-5-corbet@lwn.net>
On Wed, 07 Feb 2018, Jonathan Corbet <corbet@lwn.net> wrote:
> Move this code out of process_file() in the name of readability and
> maintainability.
>
> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
I admit I don't fully understand the semantics of perl parameter
passing, but looks okay.
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
> ---
> scripts/kernel-doc | 137 ++++++++++++++++++++++++++++-------------------------
> 1 file changed, 72 insertions(+), 65 deletions(-)
>
> diff --git a/scripts/kernel-doc b/scripts/kernel-doc
> index 65150b7c8472..a27c7016f72d 100755
> --- a/scripts/kernel-doc
> +++ b/scripts/kernel-doc
> @@ -1793,13 +1793,81 @@ sub process_normal() {
> }
> }
>
> +#
> +# STATE_NAME: Looking for the "name - description" line
> +#
> +sub process_name($$) {
> + my $file = shift;
> + my $identifier;
> + my $descr;
> +
> + if (/$doc_block/o) {
> + $state = STATE_DOCBLOCK;
> + $contents = "";
> + $new_start_line = $. + 1;
> +
> + if ( $1 eq "" ) {
> + $section = $section_intro;
> + } else {
> + $section = $1;
> + }
> + }
> + elsif (/$doc_decl/o) {
> + $identifier = $1;
> + if (/\s*([\w\s]+?)\s*-/) {
> + $identifier = $1;
> + }
>
> + $state = STATE_BODY;
> + # if there's no @param blocks need to set up default section
> + # here
> + $contents = "";
> + $section = $section_default;
> + $new_start_line = $. + 1;
> + if (/-(.*)/) {
> + # strip leading/trailing/multiple spaces
> + $descr= $1;
> + $descr =~ s/^\s*//;
> + $descr =~ s/\s*$//;
> + $descr =~ s/\s+/ /g;
> + $declaration_purpose = $descr;
> + $state = STATE_BODY_MAYBE;
> + } else {
> + $declaration_purpose = "";
> + }
> +
> + if (($declaration_purpose eq "") && $verbose) {
> + print STDERR "${file}:$.: warning: missing initial short description on line:\n";
> + print STDERR $_;
> + ++$warnings;
> + }
> +
> + if ($identifier =~ m/^struct/) {
> + $decl_type = 'struct';
> + } elsif ($identifier =~ m/^union/) {
> + $decl_type = 'union';
> + } elsif ($identifier =~ m/^enum/) {
> + $decl_type = 'enum';
> + } elsif ($identifier =~ m/^typedef/) {
> + $decl_type = 'typedef';
> + } else {
> + $decl_type = 'function';
> + }
> +
> + if ($verbose) {
> + print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
> + }
> + } else {
> + print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
> + " - I thought it was a doc line\n";
> + ++$warnings;
> + $state = STATE_NORMAL;
> + }
> +}
>
> sub process_file($) {
> my $file;
> - my $identifier;
> my $func;
> - my $descr;
> my $initial_section_counter = $section_counter;
> my ($orig_file) = @_;
> my $leading_space;
> @@ -1823,69 +1891,8 @@ sub process_file($) {
> while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
> if ($state == STATE_NORMAL) {
> process_normal();
> - } elsif ($state == STATE_NAME) {# this line is the function name (always)
> - if (/$doc_block/o) {
> - $state = STATE_DOCBLOCK;
> - $contents = "";
> - $new_start_line = $. + 1;
> -
> - if ( $1 eq "" ) {
> - $section = $section_intro;
> - } else {
> - $section = $1;
> - }
> - }
> - elsif (/$doc_decl/o) {
> - $identifier = $1;
> - if (/\s*([\w\s]+?)\s*-/) {
> - $identifier = $1;
> - }
> -
> - $state = STATE_BODY;
> - # if there's no @param blocks need to set up default section
> - # here
> - $contents = "";
> - $section = $section_default;
> - $new_start_line = $. + 1;
> - if (/-(.*)/) {
> - # strip leading/trailing/multiple spaces
> - $descr= $1;
> - $descr =~ s/^\s*//;
> - $descr =~ s/\s*$//;
> - $descr =~ s/\s+/ /g;
> - $declaration_purpose = $descr;
> - $state = STATE_BODY_MAYBE;
> - } else {
> - $declaration_purpose = "";
> - }
> -
> - if (($declaration_purpose eq "") && $verbose) {
> - print STDERR "${file}:$.: warning: missing initial short description on line:\n";
> - print STDERR $_;
> - ++$warnings;
> - }
> -
> - if ($identifier =~ m/^struct/) {
> - $decl_type = 'struct';
> - } elsif ($identifier =~ m/^union/) {
> - $decl_type = 'union';
> - } elsif ($identifier =~ m/^enum/) {
> - $decl_type = 'enum';
> - } elsif ($identifier =~ m/^typedef/) {
> - $decl_type = 'typedef';
> - } else {
> - $decl_type = 'function';
> - }
> -
> - if ($verbose) {
> - print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
> - }
> - } else {
> - print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
> - " - I thought it was a doc line\n";
> - ++$warnings;
> - $state = STATE_NORMAL;
> - }
> + } elsif ($state == STATE_NAME) {
> + process_name($file, $_);
> } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) {
> if (/$doc_sect/i) { # case insensitive for supported section names
> $newsection = $1;
--
Jani Nikula, Intel Open Source Technology Center
next prev parent reply other threads:[~2018-02-09 9:27 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-07 17:26 [PATCH 0/8] Clean up kernel-doc and fix literal-block handling Jonathan Corbet
2018-02-07 17:26 ` [PATCH 1/8] docs: kernel-doc: Get rid of xml_escape() and friends Jonathan Corbet
2018-02-09 9:09 ` Jani Nikula
2018-02-09 13:32 ` Jonathan Corbet
2018-02-07 17:26 ` [PATCH 2/8] docs: kernel-doc: Rename and split STATE_FIELD Jonathan Corbet
2018-02-09 9:20 ` Jani Nikula
2018-02-07 17:26 ` [PATCH 3/8] docs: kernel-doc: Move STATE_NORMAL processing into its own function Jonathan Corbet
2018-02-09 9:23 ` Jani Nikula
2018-02-07 17:26 ` [PATCH 4/8] docs: kernel-doc: Move STATE_NAME " Jonathan Corbet
2018-02-09 9:27 ` Jani Nikula [this message]
2018-02-07 17:26 ` [PATCH 5/8] docs: kernel-doc: Move STATE_BODY processing to a separate function Jonathan Corbet
2018-02-09 9:32 ` Jani Nikula
2018-02-09 17:30 ` Linus Torvalds
2018-02-13 10:01 ` Jani Nikula
2018-02-07 17:26 ` [PATCH 6/8] docs: kernel-doc: Move STATE_PROTO processing into its own function Jonathan Corbet
2018-02-09 9:33 ` Jani Nikula
2018-02-07 17:26 ` [PATCH 7/8] docs: kernel-doc: Finish moving STATE_* code out of process_file() Jonathan Corbet
2018-02-08 2:29 ` Tobin C. Harding
2018-02-08 19:58 ` Jonathan Corbet
2018-02-09 9:36 ` Jani Nikula
2018-02-07 17:26 ` [PATCH 8/8] docs: kernel-doc: Don't mangle literal code blocks in comments Jonathan Corbet
2018-02-08 2:30 ` Tobin C. Harding
2018-02-09 9:47 ` Jani Nikula
2018-02-14 16:53 ` Markus Heiser
2018-02-08 2:26 ` [PATCH 0/8] Clean up kernel-doc and fix literal-block handling Tobin C. Harding
-- strict thread matches above, loose matches on Subject: below --
2018-02-14 18:40 [PATCH v2 0/8] docs: Cleanup kernel-doc and fix literal block handling Jonathan Corbet
2018-02-14 18:40 ` [PATCH 4/8] docs: kernel-doc: Move STATE_NAME processing into its own function Jonathan Corbet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a7wia4xz.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=corbet@lwn.net \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=me@tobin.cc \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).