Be less verbose
[kai/samba.git] / source3 / script / find_missing_doc.pl
1 #!/usr/bin/perl
2
3 my $doc_file = "/docs/docbook/manpages/smb.conf.5.sgml";
4 my $source_file = "/source/param/loadparm.c";
5
6 my %link,%doc,%param;
7
8 # This one shouldn't be documented at all
9 $doc{-valid} = "FOUND";
10
11 $topdir = (shift @ARGV) or $topdir = ".";
12
13 ##################################################
14 # Reading links from manpage
15
16 open(IN,$topdir.$doc_file);
17
18 while(<IN>) {
19         if( /<listitem><para><link linkend="([^"]*)"><parameter>([^<]*)<\/parameter><\/link><\/para><\/listitem>/g ){
20                 $link{$2} = $1;
21                 $ref{$1} = $2;
22         }
23 }
24
25 close(IN);
26
27 ##################################################
28 # Reading documentation from manpage
29
30 open(IN,$topdir.$doc_file) || die("Can't open $topdir$doc_file");
31
32 while(<IN>) {
33         if( /<term><anchor id="([^"]*)">([^<]*?)([ ]*)\(.\)([ ]*)<\/term>/g ) {
34                 $key = $1;
35                 $value = $2;
36                 $doc{$value} = $key;
37
38                 # There is a reference to this entry
39                 if($ref{$key} eq $value){
40                         $ref{$key} = "FOUND";
41                 } else {
42                         if($ref{$key}) {
43                                 print "$key should refer to $value, but refers to " . $ref{$key} . "\n";
44                         } else {
45                                 print "$key should refer to $value, but has no reference!\n";
46                         }
47                         $ref{$key} = $value;
48                 }
49         }
50 }
51
52 close(IN);
53
54 #################################################
55 # Reading entries from source code
56
57 open(SOURCE,$topdir.$source_file) || die("Can't open $topdir$source_file");
58
59 while ($ln = <SOURCE>) {
60   last if $ln =~ m/^static\ struct\ parm_struct\ parm_table.*/;
61 } #burn through the preceding lines
62
63 while ($ln = <SOURCE>) {
64   last if $ln =~ m/^\s*\}\;\s*$/;
65   #pull in the param names only
66   next if $ln =~ m/.*P_SEPARATOR.*/;
67   next unless $ln =~ /.*\"(.*)\".*/;
68   
69   if($doc{lc($1)}) {
70         $doc{lc($1)} = "FOUND";
71   } else {
72         print "$1 is not documented!\n";
73   }
74 }
75 close SOURCE;
76
77 ##################################################
78 # Trying to find missing references
79
80 foreach (keys %ref) {
81         if($ref{$_} cmp "FOUND") {
82                 print "$_ references to " . $ref{$_} . ", but " . $ref{$_} . " isn't an anchor!\n";
83         }
84 }
85
86 foreach (keys %doc) {
87         if($doc{$_} cmp "FOUND") {
88                 print "$_ is documented but is not a configuration option!\n";
89         }
90 }