#!/usr/local/bin/perl

#######################################
# User Configuration
#######################################

  @smtp_hosts = qw(mailhost.tiuk.ti.com);
  @nntp_hosts = qw(news.ti.com);
$ftp_firewall = qq(gate.ti.com);
    @ph_hosts = qw(dles9.itg.ti.com);
  @pop3_hosts = qw(mailhost.tiuk.ti.com);
  @snpp_hosts = qw();
 $inet_domain = qq(tiuk.ti.com);

#######################################
# End of User Configuration
#######################################

use IO::File;

my $config = "Net/Config.pm";

# Use %INC and IO::File to determine hoe this machine
# maps package names to path names

foreach (keys %INC) {
 last if ($config = $_) =~ s/^IO(.)File/Net$1Config/;
}

my $fh = IO::File->new($config, "w") or
		die "Cannot create `$file': $!";

print "Creating $config ...\n";

$fh->print("# This file was autogenerated by $0\n");
$fh->print("# Any modifications made here will be lost\n");
$fh->print("# ",`date`);

$fh->print(<<'ESQ');

package Net::Config;

require Exporter;
use vars qw(@ISA @EXPORT %NetConfig);
use strict;

@EXPORT = qw(%NetConfig);
@ISA = qw(Exporter);

%NetConfig = (
ESQ

my %var = (
	   SMTP_Hosts   => \@smtp_hosts,
	   NNTP_Hosts   => \@nntp_hosts,
	   FTP_FireWall => $ftp_firewall,
	   PH_Hosts     => \@ph_hosts,
	   POP3_Hosts   => \@pop3_hosts,
	   SNPP_Hosts   => \@snpp_hosts,
	   INET_Domain  => $inet_domain,
	  );

my($k,$v);
while(($k,$v) = each %var)
 {
  my($r,$rv);

  next unless defined $v;

  if(ref($v))
   {
    my @r = grep { length } map { (/(\S+)/)[0] } @$v;
    next unless @r;
    $rv = join(" ", @{$v});
    $r = '[qw(' . $rv . ')]'
   }
  else
   {
    $rv = ($v =~ /(\S+)/)[0];
    next unless length $rv;
    $r = '"' . $rv . '"';
   }

  print STDERR sprintf(" %-16s => %s\n",$k,$rv);

  $fh->printf(" %-16s => %s,\n",$k,$r);
 }

$fh->print( ");\n\n1;\n" );
$fh->close;
