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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#!/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 each module's header file against the
# function prototypes in the pod manpage source. All differences are reported.
die("usage: $0 *.c\n") if $#ARGV == -1;
my @src;
my @hdr;
for my $src (@ARGV)
{
next unless $src =~ /\.c$/;
next if $src eq 'getopt.c';
next if $src eq 'hsort.c';
next if $src eq 'vsscanf.c';
my $hdr = $src;
$hdr =~ s/\.c$/.h/;
my $src_state = '';
my $hdr_state = '';
@src = ();
@hdr = ();
my $done_rwlock_skip = 0;
open(SRC, $src) or die("failed to open $src\n");
while (<SRC>)
{
next if $_ =~ /^$/;
next if $_ =~ /^\s+#/;
$src_state = $1, next if $_ =~ /^=head1 (.*)$/;
if ($src_state eq 'DESCRIPTION' && $_ =~ /^=item [CI]<(.*)>$/)
{
my $proto = $1 . ';';
next if $proto =~ /^ #define/;
next unless $proto =~ /^extern/ || $proto =~ /\);$/;
push(@src, $proto);
}
}
close(SRC);
open(HDR, $hdr) or die("failed to open $hdr\n");
while (<HDR>)
{
if ($_ =~ /^#ifndef HAVE_PTHREAD_RWLOCK/ && $done_rwlock_skip == 0)
{
my $jnk;
do { $jnk = <HDR>; } while $jnk !~ /^#endif$/;
$done_rwlock_skip = 1;
}
next if $_ =~ /^$/;
next if $_ =~ /^#/;
next if $_ =~ /^\//;
next if $_ =~ /^\*/;
$hdr_state = 'decls', next if $_ =~ /^_begin_decls$/;
last if $_ =~ /^_end_decls$/;
if ($hdr_state eq 'decls')
{
my $proto = $_;
#warn "$hdr: _args missing: $proto\n" if $proto =~ /\);\s*$/ && $proto !~ / _args /;
#$proto =~ s/ _args \(//;
#$proto =~ s/\)\);/);/;
chop($proto);
push(@hdr, $proto);
}
}
close(HDR);
show("$src != $hdr (line number mismatch)"), next if $#src != $#hdr;
my $i;
my $first = 1;
for ($i = 0; $i <= $#src; ++$i)
{
if ($src[$i] ne $hdr[$i])
{
print("$src != $hdr\n") if $first;
print("doc = $src[$i]\n");
print("hdr = $hdr[$i]\n");
$first = 0;
}
}
print("\n") unless $first;
}
sub show
{
my ($msg) = @_;
print("$msg\n");
print("-- doc ---\n");
my $i;
for ($i = 0; $i <= $#src; ++$i)
{
print("$src[$i]\n");
}
print("-- hdr ---\n");
for ($i = 0; $i <= $#hdr; ++$i)
{
print("$hdr[$i]\n");
}
print("----------\n\n");
}
# vi:set ts=4 sw=4:
|