Skip to content

Instantly share code, notes, and snippets.

@fanf2
Created September 3, 2015 19:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanf2/9b55be70da32a1eefcb8 to your computer and use it in GitHub Desktop.
Save fanf2/9b55be70da32a1eefcb8 to your computer and use it in GitHub Desktop.
#!/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(^$);
@fanf2
Copy link
Author

fanf2 commented Sep 3, 2015

Using named-listzones you can re-create an include file with a shell script like:

: >named.in-view
named-listzones | sed '
    / in public slave$/bp
    d
    :p
    s// { in-view public; };/
    s/^/zone /
' >named.in-view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment