--------------------- PatchSet 11426 Date: 2007/05/13 17:01:45 Author: hno Branch: HEAD Tag: (none) Log: Get the ToC running, with raw section separators. Members: scripts/www/build-cfg-help.pl:1.10->1.11 scripts/www/template.html:1.3->1.4 Index: squid/scripts/www/build-cfg-help.pl =================================================================== RCS file: /cvsroot/squid/squid/scripts/www/build-cfg-help.pl,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- squid/scripts/www/build-cfg-help.pl 13 May 2007 14:58:40 -0000 1.10 +++ squid/scripts/www/build-cfg-help.pl 13 May 2007 17:01:45 -0000 1.11 @@ -10,7 +10,7 @@ # # Adrian Chadd # -# $Id: build-cfg-help.pl,v 1.10 2007/05/13 14:58:40 adrian Exp $ +# $Id: build-cfg-help.pl,v 1.11 2007/05/13 17:01:45 hno Exp $ # # The template file is reasonably simple to parse. There's a number of @@ -51,9 +51,19 @@ my ($state) = ""; -my ($name); -my (@names); -my (%data); +my (%option); +my (%all_names); +my ($comment); + +my $version = "2.HEAD"; +my $verbose = ''; +my $path = "/tmp"; + +GetOptions( + 'verbose' => \$verbose, 'v' => \$verbose, + 'out=s' => \$path, + 'version=s' => \$version + ); # XXX should implement this! sub uriescape($) @@ -62,16 +72,19 @@ return $line; } +sub filename($) +{ + my ($name) = @_; + return $path . "/" . $name . ".html"; +} + sub htmlescape($) { my ($line) = @_; + return "" if !defined $line; $line =~ s/([^\w\s])/sprintf ("&#%d;", ord ($1))/ge; return $line; } -my $verbose = ''; -my $path = "/tmp"; - -GetOptions('verbose' => \$verbose, 'v' => \$verbose, 'out=s' => \$path); # # Yes, we could just read the template file in once..! @@ -80,7 +93,7 @@ { my ($template, $data) = @_; # XXX should make sure the config option is a valid unix filename! - my ($fn) = $path . "/" . $name . ".html"; + my ($fn) = filename($data->{'name'}); my ($fh) = new IO::File; my ($th) = new IO::File; @@ -91,7 +104,7 @@ $data->{"title"} = $data->{"name"}; $data->{"ldoc"} = $data->{"doc"}; if (exists $data->{"aliases"}) { - $data->{"aliaslist"} = join(", ", $data->{"aliases"}); + $data->{"aliaslist"} = join(", ", @{$data->{"aliases"}}); } # XXX can't do this and then HTML escape.. # $data->{"ldoc"} =~ s/\n\n/<\/p>\n

\n/; @@ -107,90 +120,156 @@ undef $fh; } +my ($index) = new IO::File; + +$index->open(filename("index"), "w") || die "Couldn't open ".filename("index").": $!\n"; +print $index < + + Squid $version configuration file + + + +EOF +; + + +my ($name, $data); +my (@chained); + +my $in_options = 0; +sub start_option($) +{ + my ($name) = @_; + if (!$in_options) { + print $index "

\n"; + $in_options = 0; +} while (<>) { chomp; -# next if (/^$/); + last if (/^EOF$/); if ($_ =~ /^NAME: (.*)$/) { - # If we have a name already; shuffle the data off and blank - if (defined $name && $name ne "") { - generate_page("template.html", \%data); + my (@aliases) = split(/ /, $1); + $data = {}; + foreach (@aliases) { + $all_names{$_} = $data; } - undef %data; - $data{"doc"} = ""; - my ($r) = {}; - @{$r->{"aliases"}} = split(/ /, $1); - $name = $r->{"name"} = $data{"name"} = $r->{"aliases"}[0]; - # names should only have one entry! - shift @{$r->{"aliases"}}; - unshift @names, $r; - print "DEBUG: new section: $name\n"; + $name = shift @aliases; + + $option{$name} = $data; + $data->{'name'} = $name; + $data->{'aliases'} = \@aliases; + + start_option($name); + print "DEBUG: new option: $name\n" if $verbose; } elsif ($_ =~ /^COMMENT: (.*)$/) { - $data{"comment"} = $1; + $data->{"comment"} = $1; } elsif ($_ =~ /^TYPE: (.*)$/) { - $data{"type"} = $1; + $data->{"type"} = $1; } elsif ($_ =~ /^DEFAULT: (.*)$/) { - $data{"default"} = $1; + if ($1 eq "none") { + $data->{"default"} = "$1"; + } else { + $data->{"default"} = "$name $1"; + } } elsif ($_ =~ /^LOC:(.*)$/) { - $data{"loc"} = $1; - $data{"loc"} =~ s/^[\s\t]*//; + $data->{"loc"} = $1; + $data->{"loc"} =~ s/^[\s\t]*//; } elsif ($_ =~ /^DOC_START$/) { $state = "doc"; } elsif ($_ =~ /^DOC_END$/) { $state = ""; + my $othername; + foreach $othername (@chained) { + $option{$othername}{'doc'} = $data->{'doc'}; + } + undef @chained; } elsif ($_ =~ /^DOC_NONE$/) { - $state = ""; + push(@chained, $name); } elsif ($_ =~ /^NOCOMMENT_START$/) { $state = "nocomment"; } elsif ($_ =~ /^DEFAULT_IF_NONE: (.*)$/) { - $data{"default_if_none"} = $1; + $data->{"default_if_none"} = $1; } elsif ($_ =~ /^NOCOMMENT_END$/) { $state = ""; } elsif ($_ =~ /^IFDEF: (.*)$/) { - $data{"ifdef"} = $1; - } elsif ($state eq "doc") { - $data{"doc"} .= $_ . "\n"; + $data->{"ifdef"} = $1; + } elsif ($_ =~ /^#/ && $state eq "doc") { + $data->{"config"} .= $_ . "\n"; } elsif ($state eq "nocomment") { - $data{"nocomment"} .= $_ . "\n"; + $data->{"config"} .= $_ . "\n"; + } elsif ($state eq "doc") { + $data->{"doc"} .= $_ . "\n"; + } elsif ($_ =~ /^COMMENT_START$/) { + end_options; + $state = "comment"; + $comment = ""; + } elsif ($_ =~ /^COMMENT_END$/) { + print $index "
\n";
+		print $index $comment;
+		print $index "
\n"; + } elsif ($state eq "comment") { + $comment .= $_ . "\n"; + } elsif (/^#/) { + next; } elsif ($_ ne "") { - print "DEBUG: unknown line '$_'\n"; + print "NOTICE: unknown line '$_'\n"; } } +end_options; +print $index < +

Alphabetic index

+ + +EOF +; +$index->close; +undef $index; -# print last section -if ($name ne "") { - generate_page("template.html", \%data); +# and now, build the option pages +my (@names) = keys %option; +foreach $name (@names) { + generate_page("template.html", $option{$name}); } - -# and now, the index file! +# and now, the alpabetic index file! my ($fh) = new IO::File; -$fh->open($path . "/index.html", "w") || die "Couldn't open $path/index.html for writing: $!\n"; +my ($indexname) = filename("index_all"); +$fh->open($indexname, "w") || die "Couldn't open $indexname for writing: $!\n"; print $fh < - Squid configuration file + Squid $version configuration file index +

| Back up to the index |

+ +

Alphabetic index of all options

    EOF ; -foreach (@names) { - my ($n) = $_->{"name"}; - print $fh '
  • ' . htmlescape($n) . "
  • \n"; - # Uncomment these lines if you'd like the aliases to also be generated -# if (defined $_->{"aliases"}) { -# foreach (@{$_->{"aliases"}}) { -# print $fh '
  • (deprecated) ' . htmlescape($_) . "
  • \n"; -# } -# } + +foreach $name (sort keys %all_names) { + my ($data) = $all_names{$name}; + print $fh '
  • ' . htmlescape($name) . "
  • \n"; } print $fh < +

    | Back up to the index |

    EOF Index: squid/scripts/www/template.html =================================================================== RCS file: /cvsroot/squid/squid/scripts/www/template.html,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- squid/scripts/www/template.html 13 May 2007 14:58:40 -0000 1.3 +++ squid/scripts/www/template.html 13 May 2007 17:01:45 -0000 1.4 @@ -5,7 +5,7 @@ - | Back up to the index |
    + | Back up to the index |

    Option: %name%

    @@ -21,7 +21,7 @@

    Default Values

    -%name% %default% +%default%

    Compile-time option

    @@ -32,7 +32,7 @@

    Suggested Base Configuration

    -%nocomment%
    +%config%