From: hno <> Date: Wed, 8 Aug 2007 13:38:33 +0000 (+0000) Subject: Scripts for splitting and merging cf.data.pre files X-Git-Tag: SQUID_3_0_PRE7~102 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ffd3e51008b930c79bdea069f776c92f492957b9;p=thirdparty%2Fsquid.git Scripts for splitting and merging cf.data.pre files --- diff --git a/scripts/merge-cf.data.pre.pl b/scripts/merge-cf.data.pre.pl new file mode 100755 index 0000000000..b3774ae66e --- /dev/null +++ b/scripts/merge-cf.data.pre.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl +# +# This script reassembles a split configuration file back into a cf.data.pre +# file. + +use strict; +use IO::File; +use File::Basename; + +my ($path) = "."; + +if (defined $ARGV[0]) { + $path = dirname($ARGV[0]); +} + +sub filename($) +{ + my ($name) = @_; + return $path . "/" . $name . ".txt"; +} + +my ($in) = new IO::File; +while(<>) { + if (/^NAME: (.*)/) { + my (@aliases) = split(/ /, $1); + my ($name) = shift @aliases; + $in->open(filename($name), "r") || die "Couldn't open ".filename($name).":$!\n"; + while(<$in>) { + print $_; + } + $in->close(); + } else { + print $_; + } +} +undef $in; diff --git a/scripts/split-cf.data.pre.pl b/scripts/split-cf.data.pre.pl new file mode 100755 index 0000000000..1805dc3eee --- /dev/null +++ b/scripts/split-cf.data.pre.pl @@ -0,0 +1,82 @@ +#!/usr/bin/perl -w + +use strict; +use IO::File; +use Getopt::Long; +use File::Basename; + +# This mess is designed to parse the squid config template file +# cf.data.pre and split it into separare files, one per option +# +# Henrik Nordstrom +# IFDEF: +# TYPE: +# DEFAULT: +# LOC: +# DOC_START +# documentation goes here +# NOCOMMENT_START +# stuff which goes verbatim into the config file goes here +# NOCOMMENT_END +# DOC_END +# +# or alternatively instead of the DOC_START/DOC_END block just +# DOC_NONE if the option is documented by the next option +# +# Configuration sections are broken up by COMMENT_START/COMMENT_END +# bits, which we can use in the top-level index page. +# + +my $verbose = ''; +my $path = "."; + +my ($index) = new IO::File; +my ($out) = new IO::File; +my $name; + +my $top = dirname($0); + +GetOptions( + 'verbose' => \$verbose, 'v' => \$verbose, + 'out=s' => \$path, + ); + +sub filename($) +{ + my ($name) = @_; + return $path . "/" . $name . ".txt"; +} + +$index->open(filename("0-index"), "w") || die "Couldn't open ".filename("0-index").": $!\n"; + +while (<>) { + chomp; + print $index $_."\n" if !defined $name; + last if (/^EOF$/); + if ($_ =~ /^NAME: (.*)$/) { + print "DEBUG: new option: $name\n" if $verbose; + + my (@aliases) = split(/ /, $1); + $name = shift @aliases; + + $out->open(filename($name), "w") || die "Couldn't open ".filename($name).": $!\n"; + } + print $out $_."\n" if defined $name; + + if ($_ =~ /^DOC_END/ || + $_ =~ /^DOC_NONE/) { + $out->close(); + undef $name; + } +} +undef $out; +$index->close; +undef $index;