--------------------- PatchSet 11420 Date: 2007/05/13 14:04:40 Author: adrian Branch: HEAD Tag: (none) Log: Prepare for the actual page generating code. Remove global variable and replace with hash; add HTML escape function. Members: scripts/www/build-cfg-help.pl:1.4->1.5 Index: squid/scripts/www/build-cfg-help.pl =================================================================== RCS file: /cvsroot/squid/squid/scripts/www/build-cfg-help.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- squid/scripts/www/build-cfg-help.pl 13 May 2007 14:02:40 -0000 1.4 +++ squid/scripts/www/build-cfg-help.pl 13 May 2007 14:04:40 -0000 1.5 @@ -10,7 +10,7 @@ # # Adrian Chadd # -# $Id: build-cfg-help.pl,v 1.4 2007/05/13 14:02:40 hno Exp $ +# $Id: build-cfg-help.pl,v 1.5 2007/05/13 14:04:40 adrian Exp $ # # The template file is reasonably simple to parse. There's a number of @@ -51,28 +51,35 @@ my ($state) = ""; -my ($path) = "/tmp"; -my ($name, $doc, $nin, @nocomment, $type, $default, $ifdef, $comment, $loc); -my ($default_if_none); +my ($name); my (@names); +my (%data); + +sub htmlescape($) +{ + my ($line) = @_; + return $line =~ s/([^\w\s])/sprintf ("&#%d;", ord ($1))/ge; +} my $verbose = ''; +my $path = "/tmp"; GetOptions('verbose' => \$verbose, 'v' => \$verbose, 'out=s' => \$path); # # Yes yes global variables suck. Rewrite it if you must. # -sub generate_page() +sub generate_page($) { + my ($data) = @_; # XXX should make sure the config option is a valid unix filename! my ($fn) = $path . "/" . $name . ".html"; my ($fh) = new IO::File; $fh->open($fn, "w") || die "Couldn't open $fn: $!\n"; - print $fh "name: $name\n"; - print $fh "default value: $default\n"; - print $fh "default if none: $default_if_none\n"; + my ($ldoc) = $data->{"doc"}; + + print $ldoc; close $fh; undef $fh; @@ -84,35 +91,29 @@ if ($_ =~ /^NAME: (.*)$/) { # If we have a name already; shuffle the data off and blank if (defined $name && $name ne "") { - generate_page(); + generate_page(\%data); } - $name = $1; - $doc = ""; - $nin = ""; - undef @nocomment; - $nin = 0; - $type = ""; - $default = ""; - $ifdef = ""; - $loc = ""; - $comment = ""; - $default_if_none = ""; + + undef %data; + $data{"nin"} = 0; + $data{"nocomment"} = []; + my ($r) = {}; @{$r->{"aliases"}} = split(/ /, $1); - $r->{"name"} = $name = $r->{"aliases"}[0]; + $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"; } elsif ($_ =~ /^COMMENT: (.*)$/) { - $comment = $1; + $data{"comment"} = $1; } elsif ($_ =~ /^TYPE: (.*)$/) { - $type = $1; + $data{"type"} = $1; } elsif ($_ =~ /^DEFAULT: (.*)$/) { - $default = $1; + $data{"default"} = $1; } elsif ($_ =~ /^LOC:(.*)$/) { - $loc = $1; - $loc =~ s/^[\s\t]*//; + $data{"loc"} = $1; + $data{"loc"} =~ s/^[\s\t]*//; } elsif ($_ =~ /^DOC_START$/) { $state = "doc"; } elsif ($_ =~ /^DOC_END$/) { @@ -122,16 +123,16 @@ } elsif ($_ =~ /^NOCOMMENT_START$/) { $state = "nocomment"; } elsif ($_ =~ /^DEFAULT_IF_NONE: (.*)$/) { - $default_if_none = $1; + $data{"default_if_none"} = $1; } elsif ($_ =~ /^NOCOMMENT_END$/) { - $nin++; + $data{"nin"} ++; $state = ""; } elsif ($_ =~ /^IFDEF: (.*)$/) { - $ifdef = $1; + $data{"ifdef"} = $1; } elsif ($state eq "doc") { - $doc .= $_ . "\n"; + $data{"doc"} .= $_ . "\n"; } elsif ($state eq "nocomment") { - $nocomment[$nin] .= $_ . "\n"; + $data{"nocomment"}->[$data{"nin"}] .= $_ . "\n"; } else { print "DEBUG: unknown line '$_'\n"; } @@ -139,7 +140,7 @@ # print last section if ($name ne "") { - generate_page(); + generate_page(\%data); } # and now, the index file!