]> git.ipfire.org Git - thirdparty/squid.git/blame - scripts/split-cf.data.pre.pl
MinGW-w64: enable native file locking (#1358)
[thirdparty/squid.git] / scripts / split-cf.data.pre.pl
CommitLineData
ffd3e510 1#!/usr/bin/perl -w
a151895d 2#
b8ae064d 3## Copyright (C) 1996-2023 The Squid Software Foundation and contributors
a151895d
AJ
4##
5## Squid software is distributed under GPLv2+ license and includes
6## contributions from numerous individuals and organizations.
7## Please see the COPYING and CONTRIBUTORS files for details.
8##
ffd3e510 9
10use strict;
11use IO::File;
12use Getopt::Long;
13use File::Basename;
14
15# This mess is designed to parse the squid config template file
16# cf.data.pre and split it into separare files, one per option
17#
58fbbd9f 18# Henrik Nordstrom <henrik@henriknordstrom.net>
ffd3e510 19
20#
21# The template file is reasonably simple to parse. There's a number of
22# directives which delineate sections but there's no section delineation.
23# A section will "look" somewhat like this, most of the time:
24# NAME: <name>
25# IFDEF: <the ifdef bit>
26# TYPE: <the config type>
27# DEFAULT: <the default value>
28# LOC: <location in the Config struct>
29# DOC_START
30# documentation goes here
31# NOCOMMENT_START
32# stuff which goes verbatim into the config file goes here
33# NOCOMMENT_END
34# DOC_END
35#
36# or alternatively instead of the DOC_START/DOC_END block just
37# DOC_NONE if the option is documented by the next option
38#
39# Configuration sections are broken up by COMMENT_START/COMMENT_END
40# bits, which we can use in the top-level index page.
41#
42
43my $verbose = '';
44my $path = ".";
45
46my ($index) = new IO::File;
47my ($out) = new IO::File;
48my $name;
49
50my $top = dirname($0);
51
52GetOptions(
47f28373
FC
53 'verbose' => \$verbose, 'v' => \$verbose,
54 'out=s' => \$path,
55 );
ffd3e510 56
57sub filename($)
58{
47f28373
FC
59 my ($name) = @_;
60 return $path . "/" . $name . ".txt";
ffd3e510 61}
62
63$index->open(filename("0-index"), "w") || die "Couldn't open ".filename("0-index").": $!\n";
64
65while (<>) {
47f28373
FC
66 chomp;
67 print $index $_."\n" if !defined $name;
68 last if (/^EOF$/);
69 if ($_ =~ /^NAME: (.*)$/) {
70 print "DEBUG: new option: $name\n" if $verbose;
ffd3e510 71
47f28373
FC
72 my (@aliases) = split(/ /, $1);
73 $name = shift @aliases;
ffd3e510 74
47f28373
FC
75 $out->open(filename($name), "w") || die "Couldn't open ".filename($name).": $!\n";
76 }
77 print $out $_."\n" if defined $name;
ffd3e510 78
47f28373
FC
79 if ($_ =~ /^DOC_END/ ||
80 $_ =~ /^DOC_NONE/) {
81 $out->close();
82 undef $name;
83 }
ffd3e510 84}
85undef $out;
86$index->close;
87undef $index;