#!/usr/local/bin/perl

	$VERSION		= "1.9";
	$MOD_DATE		= "15.Sep.94";
	$AUTHOR			= "Paul Hulford";

# 15.Sep.94 PDH - add command hggettext 
# 17.Jul.94 PDH - test length of ARGV[0] otherwise option 0 fails 
# 16.Jul.94 PDH - make it so harmony starts in the background 
# 14.Jul.94 PDH - hginsrht & hginstext available on all hosts 
# 13.Jul.94 PDH - Add comments
# 11.Jul.94 PDH - put quotes around arguments with white space 
# 30.Jun.94 PDH - hgcmd isnt actually a command -> man 
# 30.Jun.94 PDH - new command hgmvcp

# Command to offer a menu of Hyper-G commands available to a user.
# Any arguments are treated as commands which are executed with the
# exception that if the first arg is the number of a menu option then
# this argument is replaced by the name of the command before executing 

die "\nhg v$VERSION - $AUTHOR $MOD_DATE\n\n" if "@ARGV" eq "-v";
&help && exit if "@ARGV" eq "-h";

#
# Help options
#

sub help
{
	print "\n";
	print "Description:\n";
	print "         Menu or command line access to Hyper-G commands.\n";
	print "\n";
	print "Usage:\n";
	print "         hg -h\n";
	print "         hg -v\n";
	print "         hg [command_name [arguments]]\n";
	print "         hg [menu_number  [arguments]]\n";
	print "         hg man command_name\n";
	print "\n";
	print "Options:\n";
	print "        -h                -- help\n";
	print "        -v                -- version\n";	
	print "        command_name      -- hyperg command name\n";
	print "        menu_option       -- number of a menu option\n";
	print "        arguments         -- arguments to a command\n";
	print "\n";
	print "Help:\n";
	print "        For help with commands use the \"man\" menu option\n"; 
	print "        and the command name you require assistance with\n";
	print "        as the first argument.\n"; 
	print "\n";
	print "        Most commands support -h for help\n";
	print "\n";
}



@args = @ARGV;		# remeber args

while( length($ARGV[0]) )    # PDH 17-Jul-94
{
	$_ = shift;
	$cmd .= '"'.$_.'" ' if( /\s/ ); 
	$cmd .= $_.' ' if( ! /\s/ );
}

$input = $cmd;

$CHOICES = 9;

open( SIN, "<-" );

	if ( ! @args )
	{
		print "\n";
		print "  0.  help           (hg usage)\n";
		print "  1.  hgtv           (Text viewer)\n";
		print "  2.  harmony        (X Windows viewer)\n";
		print "  3.  hginsrht       (Inserting rtf, htf & text docs)\n";
		print "  4.  hginstext      (Direct text input)\n";
		print "  5.  hginfo         (Get Node Attributes)\n";
		print "  6.  man            (Hyper-G Manual)\n";
		print "  7.  hginscoll      (Create a Collection)\n";
		print "  8.  hgmvcp         (Move or Copy a Document)\n";
		print "  9.  hggettext      (Retrieve a text Document)\n";
		print "\n";

		print "Help: option [-h]\n";
		print "Manual: 6 [command_name]\n";
		print "Choose a Function (option [arguments]): ";
		$input = <SIN>;
		print "\n";
	}

	$input =~ /^([0-9]+)(.*)$/
		&& ($menu_select = 1) 
		&& ($sel = $1 + 0) 
		&& ($cmd_args = $2);

	exit if $sel > $CHOICES;
	exit if $input =~ /^$/;	

	$CPU = $ENV{'CPU'};

	$cmd = "" if $menu_select;
	
	&help && exit 		if $sel == 0 && $menu_select; 
	$cmd = "hgtv" 		if $sel == 1 && $CPU =~ /SUN4|PMAX/;
	$cmd = "harmony" 	if $sel == 2 && $CPU =~ /SUN4|PMAX|SGI/;
	$cmd = "hginsrht" 	if $sel == 3 && $CPU =~ /SUN4|PMAX|SGI/;
	$cmd = "hginstext" 	if $sel == 4 && $CPU =~ /SUN4|PMAX|SGI/;
	$cmd = "hginfo" 	if $sel == 5 && $CPU =~ /SUN4/;
	$cmd = "man"	 	if $sel == 6 && $CPU =~ /SUN4|PMAX|SGI/;
	$cmd = "hginscoll"	if $sel == 7 && $CPU =~ /SUN4/;
	$cmd = "hgmvcp"		if $sel == 8 && $CPU =~ /SUN4/;
	$cmd = "hggettext"	if $sel == 9 && $CPU =~ /SUN4/;

	die("ERROR host does not support command\n\n") if ! $cmd;

	exec( "$cmd"."$cmd_args" ) unless( $cmd =~ /^harmony/ );
	system( "$cmd"."$cmd_args &" ) if( $cmd =~ /^harmony/ );

exit;

