#! /local/bin/perl5.003 # (C) Copyright 1997 Rahul Dhesi, All rights reserved. # Permission for copying and creation of derivative works is granted, # provided this copyright notice is preserved, to anybody who # does not discriminate against the copyright owner. use strict; # $Source: /local/undoc/RCS/make.diablo,v $ # $Id: make.diablo,v 1.9 1997/10/04 02:15:02 rdroot Exp $ # Read dnewsfeeds, make diablo.hosts and dnntpspool.ctl # Diablo's dnewsfeeds file is parsed for lines beginning with one of # these strings: '## <>', '## <' and '## >'. These are extracted and # combined to create 'diablo.hosts' and 'dnntpspool.ctl' files. The # '<>' or '<' or '>' must be followed by whitespace and then more # fields, all separated by whitespace. # A line beginning with '## >' maps a label into a host name, for making # outgoing connections with dnewslink. The rest of the line should have # the same format as a line in dnntpspool.ctl. Example: # ## > jrqqm news.jrqqm.com 50 n2 # The above line in dnewsfeeds will cause the following output line to # be sent to dnntpspool.ctl: # jrqqm news.jrqqm.com 50 n2 # A line begining with '## <' maps one or more incoming host name or IP # addresses (which may include wildcards accepted by Diablo) into a label. # The rest of the line should be a label followed by one or more host # names or IP addresses (which may include wildcards accepted by # Diablo). Each host name or IP address will result in one output line # being written to diablo.hosts. Example: # ## < xyzz5 newsfeeds.xyzz5.com 172.16.1.* 10.3.3.4 # The above line in dnewsfeeds will cause the following lines to be # written to diablo.hosts: # xyzz5 newsfeeds.xyzz5.com # xyzz5 172.16.1.* 10.3.3.4 # A line beginning with '## <>' has the same format and effect as a line # beginning '## >', except that the corresponding entry is also # generated for diablo.hosts. Example: # ## <> plugh34 newsfeeds.plugh34.com 50 n2 realtime $::myname = $0; $::myname =~ s|.*/||; $::RCSHEADER = '$Source: /local/undoc/RCS/make.diablo,v $' . "\n" . '$Id: make.diablo,v 1.9 1997/10/04 02:15:02 rdroot Exp $'; # suppresss perl warnings $::debug = $::trace = $::verbose = $::opt_h = undef; $::opt_v = $::opt_t = $::opt_x = undef; $::usage = "usage: $::myname [-vtx] arg ... (or -h for help)"; if (@ARGV && $ARGV[0] =~ "^-.+" ) { require "getopts.pl"; &Getopts("vtxh"); } $::debug = $::opt_x; $::trace = $::opt_t; $::verbose = $::debug || $::trace || $::opt_v; if ($::opt_h) { &givehelp(); exit(0); } ## (@ARGV < 1) && &usage_error; # program goes here # output files $::t_nntp = "T.$$.dnntpspool.ctl"; $::t_hosts = "T.$$.diablo.hosts"; $::f_nntp = "dnntpspool.ctl"; $::f_hosts = "diablo.hosts"; open(DNEWSFEEDS, "dnewsfeeds") || die "$::myname: can't open 'dnewsfeeds' for output: $!\n"; open(NNTP, ">$::t_nntp") || die "$::myname: can't open $::t_nntp for output: $!\n"; open(HOSTS, ">$::t_hosts") || die "$::myname: can't open $::t_hosts for output: $!\n"; print NNTP <) { if (/^## <>\s+(\S+)\s+(\S+)\s+(.+)\s*$/) { ## <> jrqqm xyzzy.jrqqm.com 50 n2 ($label, $host, $options) = ($1, $2, $3); $::debug && print "## <> [$label] [$host] [$options]\n"; s/^## <>\s+//; print NNTP $_; print HOSTS "$host $label\n"; } elsif (/^## <\s+(\S+)\s+(.+)\s*$/) { ## < jrqqm xyzzy.jrqqm.com 192.198.7.31 ($label, $host) = ($1, $2); @hosts = split(' ', $host); for (@hosts) { print HOSTS "$_ $label\n"; } } elsif (/^## >\s+(\S+)\s+(\S+)\s+(.+)\s*$/) { ## > jrqqm xyzzy.jrqqm.com 50 n2 ($label, $host, $options) = ($1, $2, $3); $::debug && print "## <> [$label] [$host] [$options]\n"; s/^## >\s+//; print NNTP $_; } elsif (/^## [<>]/) { warn "$::myname: warning: oddly formatting line:\n $_"; } } my $error = 0; close(HOSTS) || do { $error = 1; warn "$::myname: error closing $::t_hosts: $!\n"; }; close(NNTP) || do { $error = 1; warn "$::myname: error closing $::t_nntp: $!\n"; }; if (! $::trace && ! $error) { rename($::t_hosts, $::f_hosts) || warn "$::myname: error renaming $::t_hosts to $::f_hosts: $!\n"; rename($::t_nntp, $::f_nntp) || warn "$::myname: error renaming $::t_nntp to $::f_nntp: $!\n"; } else { print "$::myname: output left in $::t_hosts and $::t_nntp\n"; } sub usage_error { my($msg) = @_; if ($msg) { die "$msg\n"; } else { die "$::usage\n"; } } sub givehelp { ## require 'local/page.pl'; ## &page(<