#!/usr/bin/perl # flatdns.pl: flatten zone files that # have $INCLUDE directives in them; # This is a basic Unix filter: the source file # is read until a $INCLUDE is met, the file # is read & placed where the $INCLUDE was and # the program continues on. Can do nested includes # and doesn't touch the original files. $|++; use strict; use Getopt::Std; use Cwd; my (%args,@files,$debug,$zoneinp,$zoneout,$line); $debug = 0; getopts('vi:o:h',\%args); if(!defined $args{'i'} || !defined $args{'o'} || defined $args{'h'}) { print <',"$zoneout/$_") or die "Cannot create \"$_\":$!\n"; while($line = ) { if($line =~ /^\$INCLUDE/) { procfile(*ZNEOUT,$line); } else { print ZNEOUT $line; } } close(ZNEINP); close(ZNEOUT); } sub procfile { my ($fh,$incline) = @_; my ($tmp,@inc); chomp($incline); print "INC: $incline\n" if $debug; @inc = split(/ /,$incline); print "FILE: $inc[1]\n" if $debug; print "CWD : ",getcwd,"\n" if $debug; open(INCINP,'<',$zoneinp . "/" . $inc[1]) or die "Cannot open file $inc[1]:$!\n"; while($tmp = ) { if($tmp =~ /^\$INCLUDE/) { procfile($fh,$tmp); } else { print $fh $tmp; } } close(INCINP); }