#! /usr/bin/perl
## This file is part of Babble. All files in the distribution of Babble
## are Copyright 2000 by
##
## Alva L. Couch,
## Associate Professor of Computer Science,
## Tufts University, Medford MA 02155
## email: couch@eecs.tufts.edu
## phone: 617-627-3674
##
## All rights reserved.
##
## Redistribution and use are permitted provided that this entire
## copyright notice is duplicated in all such copies, and that any
## documentation, announcements, and other materials related to such
## distribution and use acknowledge that the software was developed by
## Alva L. Couch at Tufts University in Medford, Massachusetts, USA.
## No charge, other than an "at-cost" distribution fee, may be charged
## for copies, derivations, or distributions of this material without
## the express written consent of the copyright holder. Neither the
## name of the University nor the names of the authors may be used to
## endorse or promote products derived from this material without
## specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS
## IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
## WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
## FITNESS FOR ANY PARTICULAR PURPOSE.
use Data::Dumper;
use Getopt::Long;
use strict;
no strict "refs";
# require "babble.pl";
$main::debug=0;
$main::trace=0;
$main::inform=1;
$main::xmlout=undef;
$main::rawout=undef;
$main::debugfile = 'STDERR';
$main::tracefile = 'STDERR';
$main::informfile = 'STDERR';
$main::xmloutfile = 'STDERR';
$main::rawoutfile = 'STDERR';
$main::xmloutfilename = 'xml.out';
$main::rawoutfilename = 'raw.out';
# open(DEBUG,">debug.out") or die "can't write debug.out";
# schedule signal handlers that will close open streams
$main::SIG{'INT'} = \&main::shut;
$main::SIG{'QUIT'} = \&main::shut;
$main::SIG{'__DIE__'} = \&main::shut;
# get options
$main::result = GetOptions(
"help" => \$main::help,
"debug=i" => \$main::debug,
"debugfile=s" => \$main::tracefilename,
"trace=i" => \$main::trace,
"tracefile=s" => \$main::tracefilename,
"errorfile=s" => \$main::informfilename,
"xmlout=i" => \$main::xmlout,
"xmloutfile=s" => \$main::xmloutfilename,
"rawout=i" => \$main::rawout,
"rawoutfile=s" => \$main::rawoutfilename,
"invoke=s" => \$main::invoke,
"bind=s" => \$main::bind,
"spawn=s" => \$main::spawn,
"converse=s" => \$main::converse,
"conversefile=s" => \$main::conversefile,
);
if ($main::help || ! $main::result) {
&help;
exit 1;
}
if (defined $main::converse) {
print STDERR "Entering a conversation with command '$main::converse'\n";
print STDERR "Type EOF (control-D) to exit\n";
$main::cmd=new Spawn($main::converse);
exit 1 if ! defined $main::cmd;
$main::ret = $main::cmd->converse();
$main::com = $main::converse;
$main::com =~ s/'/\\'/g;
$main::ret = "\n\n\n"
. $main::ret . "\n\n\n";
$main::cmd->close();
$main::conversefile = "./converse.out" if ! defined $main::conversefile;
print STDERR "Writing XML output to '$main::conversefile'\n";
open(OUT,">$main::conversefile") or die "can't write $main::conversefile: $!";
print OUT $main::ret;
close OUT;
print STDERR "Done!\n";
exit 0;
}
$main::file = shift @ARGV;
if ($main::file eq '') {
print STDERR "no file specified!\n";
&help;
exit 1;
}
if ($main::debug>0 && $main::debugfilename ne '') {
open(DEBUG,">$main::debugfilename")
or die "can't open $main::debugfilename: $!";
$main::debugfile = 'DEBUG';
&debug("Babble started " . localtime(time) . "\n");
}
if ($main::trace>0 && $main::tracefilename ne '') {
open(TRACE,">$main::tracefilename")
or die "can't open $main::tracefilename: $!";
$main::tracefile = 'TRACE';
&trace("Babble started " . localtime(time) . "\n");
}
if ($main::inform>0 && $main::informfilename ne '') {
open(INFORM,">$main::informfilename")
or die "can't open $main::informfilename: $!";
$main::informfile = 'INFORM';
&inform("Babble started " . localtime(time) . "\n");
}
if ($main::xmlout>0 && $main::xmloutfilename ne '') {
open(XMLOUT,">$main::xmloutfilename")
or die "can't open $main::xmloutfilename: $!";
$main::xmloutfile = 'XMLOUT';
&main::xmlout("