]>
Commit | Line | Data |
---|---|---|
ffd3e510 | 1 | #!/usr/bin/perl -w |
a151895d | 2 | # |
ef57eb7b | 3 | ## Copyright (C) 1996-2016 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 | |
10 | use strict; | |
11 | use IO::File; | |
12 | use Getopt::Long; | |
13 | use 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 | ||
43 | my $verbose = ''; | |
44 | my $path = "."; | |
45 | ||
46 | my ($index) = new IO::File; | |
47 | my ($out) = new IO::File; | |
48 | my $name; | |
49 | ||
50 | my $top = dirname($0); | |
51 | ||
52 | GetOptions( | |
53 | 'verbose' => \$verbose, 'v' => \$verbose, | |
54 | 'out=s' => \$path, | |
55 | ); | |
56 | ||
57 | sub filename($) | |
58 | { | |
59 | my ($name) = @_; | |
60 | return $path . "/" . $name . ".txt"; | |
61 | } | |
62 | ||
63 | $index->open(filename("0-index"), "w") || die "Couldn't open ".filename("0-index").": $!\n"; | |
64 | ||
65 | while (<>) { | |
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; | |
71 | ||
72 | my (@aliases) = split(/ /, $1); | |
73 | $name = shift @aliases; | |
74 | ||
75 | $out->open(filename($name), "w") || die "Couldn't open ".filename($name).": $!\n"; | |
76 | } | |
77 | print $out $_."\n" if defined $name; | |
78 | ||
79 | if ($_ =~ /^DOC_END/ || | |
80 | $_ =~ /^DOC_NONE/) { | |
81 | $out->close(); | |
82 | undef $name; | |
83 | } | |
84 | } | |
85 | undef $out; | |
86 | $index->close; | |
87 | undef $index; |