Created
September 3, 2015 19:18
-
-
Save fanf2/9b55be70da32a1eefcb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
use re 'eval'; | |
our $string_re = qr( " (?: [^"\\] | \\. )* " )x; | |
our $atom_re = qr( (?! zone \s+ | view \s+ ) | |
[0-9A-Za-z!:._/-]+ )x; | |
our $stuff_re = qr( $string_re | |
| $atom_re | |
| (??{$block_re}) | |
| \s+ | ; | |
)x; | |
our $block_re = qr( { (?: $stuff_re )+ } \s* ; )x; | |
our $type_re = qr( type \s+ ($atom_re) \s* ; )x; | |
my $conf = qx{named-checkconf -p @ARGV}; | |
sub zone { | |
my ($zone,$view,$class) = @_; | |
$conf =~ m(^ $type_re )x; | |
print "$zone $class $view $1\n"; | |
$conf =~ s(^ $stuff_re )()x | |
until $conf =~ s(^ } \s* ; )()x; | |
} | |
my $head_re = qr(\s+ ($string_re) \s+ (?: ($atom_re) \s+ )? { \s*)x; | |
while ($conf =~ s(^ $stuff_re )()x) { | |
next unless $conf =~ s(^ (zone|view) $head_re )()x; | |
my $name = $2; | |
my $class = $3 || "in"; | |
if ($1 eq 'zone') { | |
zone $name, '_default', $class; | |
} else { # view | |
my $view = substr $name, 1, -1; | |
for (;;) { | |
last if $conf =~ s(^ } \s* ; )()x; | |
if ($conf =~ s(^ zone $head_re )()x) { | |
zone $1, $view, $2 || "in"; | |
} | |
last unless $conf =~ s(^ $stuff_re )()x; | |
} | |
} | |
} | |
die "parser failure\n" if $conf !~ m(^$); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using named-listzones you can re-create an include file with a shell script like: