]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Scripts for splitting and merging cf.data.pre files
authorhno <>
Wed, 8 Aug 2007 13:38:33 +0000 (13:38 +0000)
committerhno <>
Wed, 8 Aug 2007 13:38:33 +0000 (13:38 +0000)
scripts/merge-cf.data.pre.pl [new file with mode: 0755]
scripts/split-cf.data.pre.pl [new file with mode: 0755]

diff --git a/scripts/merge-cf.data.pre.pl b/scripts/merge-cf.data.pre.pl
new file mode 100755 (executable)
index 0000000..b3774ae
--- /dev/null
@@ -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 (executable)
index 0000000..1805dc3
--- /dev/null
@@ -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 <henrik@henriknordstrom.net½
+#
+# $Id: split-cf.data.pre.pl,v 1.1 2007/08/08 07:38:33 hno Exp $
+
+#
+# The template file is reasonably simple to parse. There's a number of
+# directives which delineate sections but there's no section delineation.
+# A section will "look" somewhat like this, most of the time:
+# NAME: <name>
+# IFDEF: <the ifdef bit>
+# TYPE: <the config type>
+# DEFAULT: <the default value>
+# LOC: <location in the Config struct>
+# 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;