From 8eca461731feb25b94ccf181e76ec2723e27769a Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Mon, 20 Jul 2020 17:10:44 +0200 Subject: [PATCH] util/find-doc-nits: Relax check of function declarations in name_synopsis() The relaxation allows spaces between function name and argument list, to allow line breaks like this when there are very long names: int (fantastically_long_name_breaks_80char_limit) (fantastically_long_name_breaks_80char_limit *something); This revealed some other intricaties, such as documented internal structures with function pointers inside, so a check of open structures was also added, and they are now simply skipped over. Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/12494) --- util/find-doc-nits | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/util/find-doc-nits b/util/find-doc-nits index c82e647bf5..3558180603 100755 --- a/util/find-doc-nits +++ b/util/find-doc-nits @@ -311,6 +311,7 @@ sub name_synopsis { # Find all functions in SYNOPSIS return unless $contents =~ /=head1 SYNOPSIS(.*)=head1 DESCRIPTION/ms; my $syn = $1; + my $ignore_until = undef; # If defined, this is a regexp # Remove all non-code lines $syn =~ s/^(?:\s*?|\S.*?)$//msg; # Remove all comments @@ -327,6 +328,19 @@ sub name_synopsis { my $line = $1; $syn = $'; + print STDERR "DEBUG[name_synopsis] \$line = '$line'\n" if $debug; + + # Special code to skip over documented structures + if ( defined $ignore_until) { + next if $line !~ /$ignore_until/; + $ignore_until = undef; + next; + } + if ( $line =~ /^\s*(?:typedef\s+)?struct(?:\s+\S+)\s*\{/ ) { + $ignore_until = qr/\}.*?;/; + next; + } + my $sym; my $is_prototype = 1; $line =~ s/STACK_OF\([^)]+\)/int/g; @@ -353,7 +367,7 @@ sub name_synopsis { # a callback function pointer: typedef ... (*NAME)(... # a callback function signature: typedef ... (NAME)(... $sym = $1; - } elsif ( $line =~ /typedef.* (\S+)\(/ ) { + } elsif ( $line =~ /typedef.* (\S+)\s*\(/ ) { # a callback function signature: typedef ... NAME(... $sym = $1; } elsif ( $line =~ /typedef.* (\S+);/ ) { @@ -366,12 +380,19 @@ sub name_synopsis { } elsif ( $line =~ /#\s*(?:define|undef) ([A-Za-z0-9_]+)/ ) { $is_prototype = 0; $sym = $1; - } elsif ( $line =~ /([A-Za-z0-9_]+)\(/ ) { + } elsif ( $line =~ /^[^\(]*?\(\*([A-Za-z0-9_]+)\s*\(/ ) { + # a function returning a function pointer: TYPE (*NAME(args))(args) + $sym = $1; + } elsif ( $line =~ /^[^\(]*?([A-Za-z0-9_]+)\s*\(/ ) { + # a simple function declaration $sym = $1; } else { next; } + + print STDERR "DEBUG[name_synopsis] \$sym = '$sym'\n" if $debug; + err($id, "$sym missing from NAME section") unless defined $names{$sym}; $names{$sym} = 2; -- 2.34.1