1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#!/usr/bin/env perl
use warnings;
use strict;
#
# libslack - https://libslack.org
#
# Copyright (C) 1999-2004, 2010, 2020-2023 raf <raf@raf.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <https://www.gnu.org/licenses/>.
#
# 20230824 raf <raf@raf.org>
#
# Compares the function prototypes in the pod manpage source against the
# actual function header itself. All differences are reported.
die("usage: $0 *.c\n") if $#ARGV == -1;
my $state = 0;
my $doc;
my $src;
my $jnk;
my $line = 0;
my $debug = 0;
while ($_ = <>)
{
++$line;
print("line $line state $state $_") if $debug;
if ($state == 0 && /^=item C[<](.*)[>]$/) # pod function prototype doco
{
next if $1 =~ /^E/ || $1 =~ / #def/;
$state = 1;
$doc = $1;
}
elsif ($state == 1 && /^=back$/) # bail out
{
$state = 0;
}
elsif ($state == 1 && /^=cut$/) # end of pod section
{
$state = 2;
}
elsif ($state == 2 && /^\*\/$/) # end of pod comment
{
do { $_ = <>; ++$line; } while /^$/; # skip blank lines
while (/^static / || /^#/) # skip static functions and macros
{
if (/^static.*;$/) # skip forward declaration
{
do { $_ = <>; ++$line; } while /^$/; # skip blank lines
}
elsif (/^static/) # static functions or forward declarations
{
do { $_ = <>; ++$line; } until /^}$/; # end of static helper function
do { $_ = <>; ++$line; } while /^$/; # blank lines between functions
}
elsif (/^#define/) # macros
{
while (/\\$/) { $_ = <>; ++$line; } # skip multi line macros
do { $_ = <>; ++$line; } while /^$/; # skip blank lines
}
else # other cpp directives
{
do { $_ = <>; ++$line; } while /^$/; # skip blank lines
}
}
chop();
$_ =~ s/\((\w+)\)([^;])/$1$2/; # handle special case of avoiding cpp expansion
if ($doc ne $_)
{
my ($doc_type, $doc_name, $doc_args) = $doc =~ /^(\w+ \*?)([a-zA-Z_0-9]+)\((.*)\)/;
my ($src_type, $src_name, $src_args) = $_ =~ /^(\w+ \*?)([()a-zA-Z_0-9]+)\((.*)\)/;
if ((!defined $doc_type || !defined $doc_name || !defined $doc_args || !defined $src_type || !defined $src_name || !defined $src_args))
{
print STDERR 'doc = ', $doc, "\n";
print STDERR 'src = ', $_, "\n";
print STDERR 'line = ', $line, "\n";
print STDERR 'doc_type = ', $doc_type, "\n";
print STDERR 'doc_name = ', $doc_name, "\n";
print STDERR 'doc_args = ', $doc_args, "\n";
print STDERR 'src_type = ', $src_type, "\n";
print STDERR 'src_name = ', $src_name, "\n";
print STDERR 'src_args = ', $src_args, "\n";
}
print("doc = '$doc'\nsrc = '$_'\n\n")
if $src_type ne $doc_type || $src_name ne "($doc_name)" || $src_args ne $doc_args;
}
else
{
print(" ok $doc\n") if $debug;
}
$state = 0;
$doc = undef;
}
}
# vi:set ts=4 sw=4:
|