X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=utils%2Fprepare-configfile.pl;h=dc68632b82c2006033cc10bd767f16afa69b96c8;hp=e3b2b55e20b0ff676abdeba051bf5010ae759a40;hb=34a6a841e529579e2be4457ea0d4cb1befbc840a;hpb=dfec72c085a85320534be2d5b7db84bd8b69c832 diff --git a/utils/prepare-configfile.pl b/utils/prepare-configfile.pl index e3b2b55e..dc68632b 100755 --- a/utils/prepare-configfile.pl +++ b/utils/prepare-configfile.pl @@ -1,5 +1,10 @@ #!/usr/local/bin/perl +# This script is used by the config-file target in GNUMakefile. +# +# It removes garbage in the w3m output and separates comments +# and active directives. + use strict; use warnings; @@ -7,11 +12,29 @@ sub main() { my $hit_header = 0; my $hit_option = 0; my $header_len; + my $unfold_mode = 0; + my $unfolding_enabled = 0; + my $windows_section_reached = 0; while (<>) { + + if (!$unfolding_enabled and m/=========/) { + # We passed the table of contents + # and can try to unfold unintentional + # line breaks; + $unfolding_enabled = 1; + } + if (m/specific to the Windows GUI/) { + # The Windows section is formatted differently. + $windows_section_reached = 1; + } + s/^1\. \@\@TITLE\@\@/ /i; - if (m/^(\d\.)(\d\.)(\d\.)?\s/) { + if ($hit_header) { + $header_len += length($_); + $_ = " " . $_; + } elsif (m/^(\d*\.){1,3}\s/) { # Remove the first digit as it's the # config file section in the User Manual. s/^(\d\.)//; @@ -24,26 +47,47 @@ sub main() { $header_len = length($_); } - s/^/# /; + if ($unfold_mode) { + s/^\s+/ /; + $unfold_mode = 0; + } else { + if ( $hit_option ) { + # processing a continuation of a @@ line + if ( /^\s*$/ ) { # blank line + $hit_option = 0; + next; + } + } + s/^/# /; + } + if ($unfolding_enabled and + (m/(\s+#)\s*$/ or m/forward-socks5 and$/)) { + $unfold_mode = 1; + chomp; + } # XXX: someone should figure out what this stuff # is supposed to do (and if it really does that). s/^# #/####/ if /^# #{12,}/; - s/^.*$// if $hit_option; - $hit_option = 0; s/^\n//; s/^#\s*-{20,}//; s/ *$//; $hit_option = 1 if s/^#\s+@@//; - - print; - if ($hit_header) { + if ($windows_section_reached) { + # Do not drop empty lines in the Windows section + s/^\s*$/#\n/; + } + + print unless (/^\s*$/); + + if ($hit_header and !$unfold_mode) { # The previous line was a section # header so we better underline it. die "Invalid header length" unless defined $header_len; print "# " . "=" x $header_len . "\n"; $hit_header = 0; + $header_len = 0; }; } }