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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
|
#!/usr/bin/env perl
use strict;
my $outfile;
if ($ARGV[0] eq "-o") {
die "Missing filename after -o.\n" unless ($#ARGV >= 1);
shift;
$outfile = $ARGV[0];
shift;
}
die "Must specify product.\n" unless ($#ARGV >= 0);
my $product = $ARGV[0];
# Figure out the version name.
my $version;
open VERSION, "<version.txt" or die "No version.txt file.\n";
while (<VERSION>) {
chomp;
if (/^version="(.*)"/) { $version=$1 }
}
close VERSION;
# Sort out the product, and %approd.
my %approd;
$approd{'a'} = 1;
if ($product eq "x3270") {
$approd{'u'} = 1;
} elsif ($product eq "c3270") {
$approd{'C'} = 1;
$approd{'u'} = 1;
} elsif ($product eq "s3270") {
$approd{'S'} = 1;
$approd{'u'} = 1;
} elsif ($product eq "b3270") {
$approd{'B'} = 1;
$approd{'u'} = 1;
} elsif ($product eq "wc3270") {
$approd{'C'} = 1;
$approd{'w'} = 1;
} elsif ($product eq "ws3270") {
$approd{'S'} = 1;
$approd{'w'} = 1;
} elsif ($product eq "wb3270") {
$approd{'B'} = 1;
$approd{'w'} = 1;
} else {
die "Unknown product '$product'.\n";
}
my $prefix = $product;
$prefix =~ s/3270//;
$approd{$prefix} = 1;
# Dump out %approd.
#foreach my $k (keys %approd) {
# print STDERR "$k: $approd{$k}\n"
#}
my %types = (
i => 'Integer',
b => 'Boolean',
s => 'String'
);
# Set up output file.
my $out;
my $tmpfile;
if ($outfile) {
$tmpfile = "/tmp/mkr" . $$;
unlink $tmpfile;
open TMPFILE, ">", $tmpfile or die "Can't open $tmpfile.\n";
$out = *TMPFILE;
} else {
$out = *STDOUT;
}
# From here on out, unlink the tempfile if we bail.
END {
unlink $tmpfile if ($tmpfile);
}
# Unlink the tempfile if we get a termination signal.
sub sighandler
{
unlink $tmpfile if ($tmpfile);
exit(0);
}
$SIG{'INT'} = \&sighandler;
$SIG{'QUIT'} = \&sighandler;
$SIG{'HUP'} = \&sighandler;
$SIG{'TERM'} = \&sighandler;
# Remove HTML attributes from a resource name.
sub nix
{
my $txt = shift(@_);
$txt =~ s/<\/?[\w.]+>//g;
return $txt;
}
# The indices.
my @index; # overall index
my @c_index; # configuration index
my @a_index; # appearance index
my @n_index; # NVT-mode index
my @p_index; # protocol index
my @i_index; # interaction index
my @s_index; # security index
my @t_index; # tracing index
my @o_index; # other index
my @d_index; # deprecated index
my @indices = (
\@c_index,
\@a_index,
\@n_index,
\@p_index,
\@i_index,
\@s_index,
\@t_index,
\@o_index,
\@d_index
);
my @index_name = (
"Basic Configuration",
"Appearance",
"NVT-Mode",
"Protocol",
"Terminal Interaction",
"Security",
"Tracing",
"Other",
"Deprecated"
);
# The elements of an entry.
my $name;
my @names;
my $applies;
my $type;
my $default;
my @switch;
my @option;
my $description;
my $groups;
sub dump {
if ($name && $applies) {
# The minimum set of required attributes are type and description.
die "$name missing type\n" if (!$type);
die "$name missing description\n" if (!$description);
foreach my $n (@names) {
# Add this name to the general index.
push @index, $n;
# Add this name to the specified indices...
if (defined($groups)) {
foreach (split /\s+/, $groups) {
if ($_ eq "c") {
push @c_index, $n;
} elsif ($_ eq "a") {
push @a_index, $n;
} elsif ($_ eq "n") {
push @n_index, $n;
} elsif ($_ eq "p") {
push @p_index, $n;
} elsif ($_ eq "i") {
push @i_index, $n;
} elsif ($_ eq "s") {
push @s_index, $n;
} elsif ($_ eq "t") {
push @t_index, $n;
} elsif ($_ eq "d") {
push @d_index, $n;
} else {
die "Unknown group '$_'\n";
}
}
} else {
# ... or to the 'other' index.
push @o_index, $n;
}
my $tgt = nix($n);
print $out "<a name=\"$tgt\"></a>\n<b>Name:</b> $product.$n<br>\n";
}
print $out "<b>Type</b>: $type<br>\n";
if ($default) { print $out "<b>Default</b>: $default<br>\n"; }
if (@switch) {
my $comma;
print $out "<b>Command Line</b>:";
foreach my $s (@switch) {
print $out "$comma $s\n";
$comma = ",";
}
print $out "<br>\n";
}
if ($product eq "x3270") {
foreach my $o (@option) {
print $out "<b>Option</b>: $o<br>\n";
}
}
$description =~ s/%p%/$product/g;
while ($description =~ /%-([\w.<>\/*]+)%/) {
my $full = $1;
my $clean = nix($1);
$clean =~ s/<\/?i>//g;
$description =~ s/%-[\w.<>\/*]+%/<a href=#$clean>$product.$full<\/a>/;
}
#$description =~ s/%-([\w.]+)%/<a href=#\1><tt>$product.\1<\/tt><\/a>/g;
print $out "<b>Description</b>:<br>\n";
print $out "<p class=indented>$description</p>\n";
}
undef $name;
undef @names;
undef $applies;
undef $type;
undef $default;
undef @switch;
undef @option;
undef $description;
undef $groups;
}
print $out <<"EOS";
<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>$product Resources</title>
<link HREF="http://www.w3.org/StyleSheets/Core/Steely" TYPE="text/css" REL="stylesheet">
<style type="text/css">
<!--
.indented
{
padding-left: 50pt;
padding-right: 50pt;
}
-->
</style>
</head>
<body>
<h1>$product Resources</h1>
EOS
my $on = 1;
my $in_desc;
my $in_intro;
my @ifstack;
while (<STDIN>) {
chomp;
# Skip blank lines.
next if (/^\s*$/);
# Handle if/endif.
if (/^if\s+(.*)/) {
push @ifstack, $on;
my $desc_applies;
foreach (split /\s+/, $1) {
$desc_applies = 1 if ($approd{$_});
}
$on = $desc_applies if ($ifstack[$#ifstack]);
next;
} elsif (/^else/) {
die "dangling else\n" if ($#ifstack < 0);
$on = !$on if ($ifstack[$#ifstack]);
next;
} elsif (/^endif/) {
die "dangling endif\n" if ($#ifstack < 0);
$on = pop(@ifstack);
next;
}
next unless $on;
# Handle desc.
if ($in_desc) {
if (/^\./) {
undef $in_desc;
} else {
$description .= $_ . "\n";
}
next;
}
# Handle intro.
if (/^intro/) {
$in_intro = 1;
next;
} elsif ($in_intro) {
if (/^\./) {
undef $in_intro;
print $out "<h2>Alphabetical Resource List</h2>\n";
} else {
s/%p%/$product/g;
while (/%-([\w.<>\/*]+)%/) {
my $full = $1;
my $clean = nix($1);
$clean =~ s/<\/?i>//g;
$_ =~ s/%-[\w.<>\/*]+%/<a href=#$clean>$product.$full<\/a>/;
}
print $out "$_\n";
}
next;
}
# Handle normal keywords.
if (/name\s(.*)/) {
&dump;
@names = split /\s+/, $1;
$name = $names[0];
next;
}
if (/applies\s(.*)/) {
undef $applies;
foreach (split /\s+/, $1) {
$applies = 1 if ($approd{$_});
}
next;
}
if (/groups\s(.*)/) {
$groups = $1;
next;
}
if (/type\s([^\s]*)/) {
$type = $types{$1};
next;
}
if (/default\s(.*)/) {
$default = $1;
next;
}
if (/switch\s(.*)/) {
push @switch, $1;
next;
}
if (/option\s(.*)/) {
push @option, $1;
next;
}
if (/^desc/) {
$in_desc = 1;
next;
}
last if (/^EOF$/);
die "Unknown keyword '$_'.\n";
}
&dump;
print $out <<EOT;
<h2>Index of All Resources</h2>
<table border cols=4 width="75%">
EOT
my $ix = 0;
foreach my $i (@index) {
if (!($ix % 4)) {
if ($ix) { print $out " </tr>\n"; }
print $out "<tr>";
}
my $clean = nix($i);
print $out " <td><a href=\"#$clean\">$i</a></td>";
$ix++;
}
print $out " </tr>\n</table>\n";
my $q = 0;
foreach my $j (@indices) {
my @arr = @$j;
if ($#arr >= 0) {
print $out "<h2>$index_name[$q] Resources</h2>\n";
print $out "<table border cols=4 width=\"75%\">\n";
my $ix = 0;
foreach my $i (@arr) {
if (!($ix % 4)) {
if ($ix) { print $out " </tr>\n"; }
print $out "<tr>";
}
my $clean = nix($i);
print $out " <td><a href=\"#$clean\">$i</a></td>";
$ix++;
}
print $out " </tr>\n</table>\n";
}
$q = $q + 1;
}
print $out "<p><i>$product version $version ", `date`, "\n";
print $out "</body>\n";
# Wrap up the outfile.
if ($outfile) {
close TMPFILE;
system("mv $tmpfile $outfile") == 0
or die "Can't rename $tmpfile to $outfile.\n";
}
|