#!/import/perl/bin/perl

#  Copyright (c) 1991, 1992, 1993 Xerox Corporation.  All Rights Reserved.  
#  
#  Unlimited use, reproduction, and distribution of this software is
#  permitted.  Any copy of this software must include both the above
#  copyright notice of Xerox Corporation and this paragraph.  Any
#  distribution of this software must comply with all applicable United
#  States export control laws.  This software is made available AS IS,
#  and XEROX CORPORATION DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
#  INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF MERCHANTABILITY
#  AND FITNESS FOR A PARTICULAR PURPOSE, AND NOTWITHSTANDING ANY OTHER
#  PROVISION CONTAINED HEREIN, ANY LIABILITY FOR DAMAGES RESULTING FROM
#  THE SOFTWARE OR ITS USE IS EXPRESSLY DISCLAIMED, WHETHER ARISING IN
#  CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, EVEN IF
#  XEROX CORPORATION IS ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#  
#  $Id: texinfo2info.dist,v 1.3 1994/04/14 04:11:37 janssen Exp $

sub stderrcat {
  local($file) = $_[0];

  if (open ($file, $file)) {
    while (<$file>)
      { print STDERR; };
    close($file);
  }
}

sub stdoutcat {
  local($file) = $_[0];

  if (open ($file, $file)) {
    while (<$file>)
      { print; }
    close ($file);
  }
}

sub random_filename {
  join ('', time, int(rand(65536)), getpgrp);
}

if ( $#ARGV < 0 ) {
	print STDERR "Usage:  texinfo2info INPUTFILE.texinfo >OUTPUTFILE.info\n";
	exit 1;
};

$texinfoFile = $ARGV[0];
$errorFile = &random_filename;
$infoFile = &random_filename;

if ((system ("/import/gnu-2.0/sparc-sun-sunos4.1/gbin/makeinfo --no-split --output $infoFile --no-validate $texinfoFile >$errorFile 2>&1 </dev/null")/256) == 0) {
  unlink $errorFile;
}
else {
  print STDERR "/import/gnu-2.0/sparc-sun-sunos4.1/gbin/makeinfo:\n";
  &stderrcat ($errorFile);
  unlink $infoFile;
  unlink $errorFile;
  exit 1;
}
&stdoutcat ($infoFile);
unlink $infoFile;
exit 0;
