File: check-pod-prototypes

package info (click to toggle)
daemon 0.6.4-1
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, squeeze, stretch, wheezy
  • size: 2,600 kB
  • ctags: 2,389
  • sloc: ansic: 28,824; sh: 3,036; perl: 594; makefile: 304
file content (95 lines) | stat: -rwxr-xr-x 2,541 bytes parent folder | download
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
#!/usr/bin/env perl
use warnings;
use strict;

# 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