Move previously inline'd Perl code for the config-file target
authorFabian Keil <fk@fabiankeil.de>
Fri, 13 Jun 2008 15:25:03 +0000 (15:25 +0000)
committerFabian Keil <fk@fabiankeil.de>
Fri, 13 Jun 2008 15:25:03 +0000 (15:25 +0000)
into a separate file, have it work with older perl releases,
clean it up a bit and fix the "underlining" code.

GNUmakefile.in
utils/prepare-configfile.pl [new file with mode: 0755]

index fe0d472..5d3001c 100644 (file)
@@ -1,6 +1,6 @@
 # Note:  Makefile is built automatically from Makefile.in
 #
 # Note:  Makefile is built automatically from Makefile.in
 #
-# $Id: GNUmakefile.in,v 1.169 2008/06/09 17:28:31 fabiankeil Exp $
+# $Id: GNUmakefile.in,v 1.170 2008/06/12 16:38:50 fabiankeil Exp $
 #
 # Written by and Copyright (C) 2001 - 2007 the SourceForge
 # Privoxy team. http://www.privoxy.org/
 #
 # Written by and Copyright (C) 2001 - 2007 the SourceForge
 # Privoxy team. http://www.privoxy.org/
@@ -854,27 +854,7 @@ dok-pdf: dok-shtml
 config-file: dok-release
        cd doc/source && $(DB)-notoc -iconfig-file -V nochunks config.sgml > __tmp.html &&\
        env -u LANG w3m -dump __tmp.html | fmt -w 70 > ../../config.new && $(RM) -r __tmp.*
 config-file: dok-release
        cd doc/source && $(DB)-notoc -iconfig-file -V nochunks config.sgml > __tmp.html &&\
        env -u LANG w3m -dump __tmp.html | fmt -w 70 > ../../config.new && $(RM) -r __tmp.*
-       $(PERL) -pi.bak \
-               -e 's/^1\. \@\@TITLE\@\@/     /i;'              \
-               -e '/^\d\.\d\.\s+/ && tr/[a-z]/[A-Z]/;'         \
-               -e 'my $$hit_header;'                           \
-               -e '$$header_len=0 unless $$hit_header;'        \
-               -e 'if ($$hit_header) {'                        \
-               -e '    print "#  ";'                           \
-               -e '    for ($$i=1; $$i < $$header_len; $$i++)' \
-               -e '            {print "=";}'                   \
-               -e '    print "\n";'                            \
-               -e '};'                                         \
-               -e '$$hit_header=0;'                            \
-               -e '$$hit_header=1 if m/^(\d\.)(\d\.)(\d\.)?\s/ && s/^(\d\.)//;'\
-               -e '$$header_len = length($$_);'                \
-               -e 's/^/#  /;  /^#  #{12,}/ && s/^#  #/####/;'  \
-               -e 's/^.*$$// if $$hit_option;'                 \
-               -e '$$hit_option=0;'                            \
-               -e 's/^\n//;'                                   \
-               -e 's/^#\s*-{20,}//;'                           \
-               -e 's/ *$$//;'                                  \
-               -e '$$hit_option=1 if s/^#\s+@@//;' config.new
+       $(PERL) -i.bak utils/prepare-configfile.pl config.new
 
        $(RM) *.bak
        @$(ECHO)  "****************************************************"
 
        $(RM) *.bak
        @$(ECHO)  "****************************************************"
@@ -1372,6 +1352,9 @@ coffee:
 ## end:
 
 # $Log: GNUmakefile.in,v $
 ## end:
 
 # $Log: GNUmakefile.in,v $
+# Revision 1.170  2008/06/12 16:38:50  fabiankeil
+# Add third-level domain to URL in dok-get target.
+#
 # Revision 1.169  2008/06/09 17:28:31  fabiankeil
 # - Recommend https for releasing files.
 # - Fix a warning about datarootdir being ignored.
 # Revision 1.169  2008/06/09 17:28:31  fabiankeil
 # - Recommend https for releasing files.
 # - Fix a warning about datarootdir being ignored.
diff --git a/utils/prepare-configfile.pl b/utils/prepare-configfile.pl
new file mode 100755 (executable)
index 0000000..e3b2b55
--- /dev/null
@@ -0,0 +1,50 @@
+#!/usr/local/bin/perl
+
+use strict;
+use warnings;
+
+sub main() {
+    my $hit_header = 0;
+    my $hit_option = 0;
+    my $header_len;
+
+    while (<>) {
+        s/^1\. \@\@TITLE\@\@/     /i;
+
+        if (m/^(\d\.)(\d\.)(\d\.)?\s/) {
+            # Remove the first digit as it's the
+            # config file section in the User Manual.
+            s/^(\d\.)//;
+
+            # If it's a section header, uppercase it.
+            $_ = uc() if (/^\d\.\s+/);
+
+            # Remember to underline it.
+            $hit_header = 1;
+            $header_len = length($_);
+        }
+
+        s/^/#  /;
+
+        # 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) {
+            # 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;
+        };
+    }
+}
+main();