#! /usr/local/bin/perl
#
#  expand - expands the name of the RR owner with the current origin,
#           if not terminated with a dot, and prints the entire
#	    RR with the expanded name in the first column
#
#  Copyright (C) 1992, 1993 PUUG - Grupo Portugues de Utilizadores
#                                  do Sistema UNIX
#                1992, 1993 FCCN - Fundacao para o Desenvolvimento dos Meios 
#                                  Nacionais de Calculo Cientifico 
#
#  Authors: Jorge Frazao de Oliveira <frazao@puug.pt>
#           Artur Romao <artur@dns.pt>
#
#  This file is part of the DDT package, Version 2.0.
#
#  Permission to use, copy, modify, and distribute this software and its 
#  documentation for any purpose and without any fee is hereby granted, 
#  provided that the above copyright notice appear in all copies.  Neither 
#  PUUG nor FCCN make any representations about the suitability of this
#  software for any purpose.  It is provided "as is" without express or 
#  implied warranty.


# =()<push(@INC, "@<LIBDIR>@");>()=
push(@INC, "/usr/local/lib/ddt/cmd");

require "ddt.pl";


while (<STDIN>) {
	next if /^;/;

    	chop;	# strip record separator
    	@Field = split(/\s+/, $_);

        if (/^\$ORIGIN/) {
                $Origin = $Field[2];

                next;
        }

        if (/^[\.\-0-9A-Za-z]+)/ {
                $Name = &make_name($Field[1], $Origin);

		shift(@Field);
        }

	if (/\tSOA\t/ && /\(\s*$/) {	# SOA lines continued by a '('
		chop($_ = <STDIN>);	# read the timers line

		s/\t//;
			
		push(@Field, $_);
	}

	unshift(@Field, $Name);	# insert the name in front of the RR

	while (@Field) {
		printf "%s\t", shift(@Field);
	}

	print "";
}
