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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
#
# check that all existing config directives, SphinxQL statements are documented
#
# load sphinx.xml as a single huge string
$sep = $/;
undef $/;
open FP, "<sphinx.xml" or die("failed to open sphinx.xml");
$doc = <FP>;
close FP;
$/ = $sep;
# load and parse sphinx.conf.in to %conf hash
$section = "";
open FP, "<../sphinx.conf.in" or die("failed to open ../sphinx.conf.in");
while (<FP>)
{
if (/^(source|index|searchd|indexer)\b/)
{
$section = $1;
next;
}
if (/^}/)
{
$section = "";
next;
}
next if $section eq "";
if (/^\s*(?:(?:\#\s+)*)(\w+)\s*=/)
{
$conf{$section}{$1} = "conf";
}
}
close FP;
# check config directives from sphinxutils.cpp vs sphinx.xml and sphinx.conf.in
$in_section = 0;
$num_sections = 0;
$num_keys = 0;
$num_missing = 0;
open FP, "<../src/sphinxutils.cpp" or die("failed to open ../src/sphinxutils.cpp");
while (<FP>)
{
# out of section? scan lines until a section declaration start
if ($in_section!=1)
{
if (/KeyDesc_t\s+g_dKeys(\w+)\s*\[\]/)
{
$section = lc $1;
$in_section = 1;
$num_sections++;
}
next;
}
# in a section, handle stuff
# opening bracket
next if (/^{$/);
# closing bracket
if (/^\s*};\s$/)
{
$in_section = 0;
next;
}
# closing entry
next if (/^\s*{\s*NULL,/);
# entry
if (/^\s*\{\s*\"(\w+)\",\s*(\w.*?),/)
{
$key = $1;
$flags = $2;
next if !$key;
next if ($flags =~ /KEY_DEPRECATED/);
next if ($flags =~ /KEY_HIDDEN/);
$num_keys++;
$miss = "";
if ($conf{$section}{"$key"} ne "conf")
{
$miss = "sphinx.conf.in";
}
# handle doc-level replacements
if (/check.pl/)
{
die("unknown replacement syntax: $_") if (!(/\/\/\s+check.pl\s+(\w+)$/));
$key = $1;
}
$dockey = $key;
$dockey =~ s/_/-/g;
if ($doc !~ /<sect2 id="conf-($section-)*$dockey">/)
{
$miss .= " and " if ($miss ne "");
$miss .= "sphinx.xml";
}
if ($miss ne "")
{
print "section $section, key $key missing from $miss\n";
$num_missing++;
}
next;
}
# whoops, unhandled in-section syntax
die("unhandled in-section syntax: $_");
}
close FP;
die("failed to find key sections in sphinxutils.cpp") if !$num_sections;
print "total $num_keys active config directives, $num_missing not documented\n";
# check SphinxQL statements from searchd.cpp vs sphinx.xml
$in_list = 0;
$num_statements = 0;
$num_missing = 0;
sub check_stmt
{
$num_statements++;
my $stmt = shift;
my $dockey = lc $stmt;
$dockey =~ s/_/-/g;
if ($doc !~ /<sect1 id="sphinxql-$dockey">/)
{
print "statement $stmt not documented\n";
$num_missing++;
}
}
open FP, "<../src/searchd.cpp" or die("failed to open ../src/searchd.cpp");
while (<FP>)
{
if (!$in_list)
{
$in_list = 1 if (/enum SqlStmt_e/);
next;
}
last if /};/; # closing bracket
next if !/STMT_(\w+)/; # empty line or something
$stmt = $1;
next if ($stmt eq "DUMMY") || ($stmt eq "PARSE_ERROR") || ($stmt eq "TOTAL"); # skip internal codes
# handle doc-level replacements
if (/check.pl/)
{
die("unknown replacement syntax: $_") if (!(/\/\/\s+check.pl\b(.*?)$/));
@sub = split(/\s+/, $1);
for $sub (@sub)
{
next if !$sub;
die("unknown replacement syntax: $sub") if (!($sub =~ /^STMT_(\w+)$/));
check_stmt($1);
}
} else
{
# no replacements, just check the line
check_stmt($stmt);
}
}
close FP;
die("failed to find SphinxQL statements list in searchd.cpp") if !$in_list;
print "total $num_statements SphinxQL statements, $num_missing not documented\n";
|