forked from squid-cache/squid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit-cf.data.pre.pl
executable file
·87 lines (74 loc) · 2.16 KB
/
split-cf.data.pre.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl -w
#
## Copyright (C) 1996-2023 The Squid Software Foundation and contributors
##
## Squid software is distributed under GPLv2+ license and includes
## contributions from numerous individuals and organizations.
## Please see the COPYING and CONTRIBUTORS files for details.
##
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>
#
# 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;