Commit c17add56 authored by Jonathan Corbet's avatar Jonathan Corbet

docs: kernel-doc: Finish moving STATE_* code out of process_file()

Move STATE_INLINE and STATE_DOCBLOCK code out of process_file(), which now
actually fits on a single screen.  Delete an unused variable and add a
couple of comments while I'm at it.
Reviewed-by: default avatarJani Nikula <jani.nikula@intel.com>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent cc794812
...@@ -1990,37 +1990,39 @@ sub process_proto($$) { ...@@ -1990,37 +1990,39 @@ sub process_proto($$) {
} }
} }
#
# STATE_DOCBLOCK: within a DOC: block.
#
sub process_docblock($$) {
my $file = shift;
sub process_file($) { if (/$doc_end/) {
my $file; dump_doc_section($file, $section, $contents);
my $func; $section = $section_default;
my $initial_section_counter = $section_counter; $contents = "";
my ($orig_file) = @_; $function = "";
%parameterdescs = ();
$file = map_filename($orig_file); %parametertypes = ();
@parameterlist = ();
if (!open(IN,"<$file")) { %sections = ();
print STDERR "Error: Cannot open file $file\n"; @sectionlist = ();
++$errors; $prototype = "";
return; $state = STATE_NORMAL;
} elsif (/$doc_content/) {
if ( $1 eq "" ) {
$contents .= $blankline;
} else {
$contents .= $1 . "\n";
}
} }
}
$. = 1; #
# STATE_INLINE: docbook comments within a prototype.
#
sub process_inline($$) {
my $file = shift;
$section_counter = 0;
while (<IN>) {
while (s/\\\s*$//) {
$_ .= <IN>;
}
# Replace tabs by spaces
while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
if ($state == STATE_NORMAL) {
process_normal();
} elsif ($state == STATE_NAME) {
process_name($file, $_);
} elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) {
process_body($file, $_);
} elsif ($state == STATE_INLINE) { # scanning for inline parameters
# First line (state 1) needs to be a @parameter # First line (state 1) needs to be a @parameter
if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
$section = $1; $section = $1;
...@@ -2057,36 +2059,49 @@ sub process_file($) { ...@@ -2057,36 +2059,49 @@ sub process_file($) {
++$warnings; ++$warnings;
} }
} }
}
sub process_file($) {
my $file;
my $initial_section_counter = $section_counter;
my ($orig_file) = @_;
$file = map_filename($orig_file);
if (!open(IN,"<$file")) {
print STDERR "Error: Cannot open file $file\n";
++$errors;
return;
}
$. = 1;
$section_counter = 0;
while (<IN>) {
while (s/\\\s*$//) {
$_ .= <IN>;
}
# Replace tabs by spaces
while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
# Hand this line to the appropriate state handler
if ($state == STATE_NORMAL) {
process_normal();
} elsif ($state == STATE_NAME) {
process_name($file, $_);
} elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) {
process_body($file, $_);
} elsif ($state == STATE_INLINE) { # scanning for inline parameters
process_inline($file, $_);
} elsif ($state == STATE_PROTO) { } elsif ($state == STATE_PROTO) {
process_proto($file, $_); process_proto($file, $_);
} elsif ($state == STATE_DOCBLOCK) { } elsif ($state == STATE_DOCBLOCK) {
if (/$doc_end/) process_docblock($file, $_);
{
dump_doc_section($file, $section, $contents);
$section = $section_default;
$contents = "";
$function = "";
%parameterdescs = ();
%parametertypes = ();
@parameterlist = ();
%sections = ();
@sectionlist = ();
$prototype = "";
$state = STATE_NORMAL;
}
elsif (/$doc_content/)
{
if ( $1 eq "" )
{
$contents .= $blankline;
}
else
{
$contents .= $1 . "\n";
}
}
} }
} }
# Make sure we got something interesting.
if ($initial_section_counter == $section_counter) { if ($initial_section_counter == $section_counter) {
if ($output_mode ne "none") { if ($output_mode ne "none") {
print STDERR "${file}:1: warning: no structured comments found\n"; print STDERR "${file}:1: warning: no structured comments found\n";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment