Commit 3cac2bc4 authored by Jonathan Corbet's avatar Jonathan Corbet
Browse files

docs: kernel-doc: Move STATE_NAME processing into its own function



Move this code out of process_file() in the name of readability and
maintainability.

Reviewed-by: default avatarJani Nikula <jani.nikula@intel.com>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent 07048d13
Loading
Loading
Loading
Loading
+72 −65
Original line number Diff line number Diff line
@@ -1793,37 +1793,14 @@ sub process_normal() {
    }
}



sub process_file($) {
    my $file;
#
# STATE_NAME: Looking for the "name - description" line
#
sub process_name($$) {
    my $file = shift;
    my $identifier;
    my $func;
    my $descr;
    my $initial_section_counter = $section_counter;
    my ($orig_file) = @_;
    my $leading_space;

    $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) {};
	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 = "";
@@ -1886,6 +1863,36 @@ sub process_file($) {
	++$warnings;
	$state = STATE_NORMAL;
    }
}

sub process_file($) {
    my $file;
    my $func;
    my $initial_section_counter = $section_counter;
    my ($orig_file) = @_;
    my $leading_space;

    $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) {};
	if ($state == STATE_NORMAL) {
	    process_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;