#!/usr/bin/perl -w
# 

print <<EOF
========================================================
Programma di comunicazione HP-LINUX, tramite KERMIT
Attivare su HP il comando SERVER.
				by M. Andreoli (C)1997
=======================================================
Commandi:

	s <file> or s		send
	r <file> or r		receive 
	v <file> or v		vi <file>
	c <file> or c		compilazione g48  + precompilazione gcc 
	q			quit 
	!<unix command>		comandi UNIX 	
	<hp command>		comandi HP (in maiuscolo!)	

EOF
;

# Eliminazione processi che occupano la porta

print `fuser -k /dev/ttyS1`;

#Settaggi della seriale

system("stty 2500:5:80000cbd:8a3b:3:1c:7f:15:4:0:1:0:11:13:1a:0:12:f:17:16:0:0:73 < /dev/ttyS1");
system("stty echo < /dev/ttyS1");

$SIG{'INT'}='Exit';

sub Exit
{
print "Ok.\n";
system("stty sane < /dev/ttyS1");
exit;
}

sub SendCmd
{
$_=shift;
#tr/[a-z]/[A-Z]/;
$cmd="kermit -C \"remote host $_, quit\"";
print "Attendere ...\n";	
eval print `$cmd`; 
}

undef $current;

while ( 1 )
{
print "\aHP> ";
$_=<>;
# Editing
/^vi (.+)/ | /^v$/			&& do { 
					if ($1) { $current=$1; };	
					system "vi $current";
					next};
# Compilazione  
/^c (.*)/ | /^c$/			&& do { 
					if ($1) { $current=$1; };	
					$obj=`basename $current .c`;
					chomp $obj;
					print "Compiling ... $current->$obj\n";
					system "cc -E $current |g48  1> $obj";
					next};
# Spedizione 
/^s (.*)/ | /^s$/			&& do { 
					if ($1) { $current=$1; };	
					$obj=`basename $current .c`;
					print "Sending ... $obj\n";
					print `kermit -s $obj`;	
					next};
# Ricezione
/^[gr] (.*)/ 				&& do { 
					print "Receiving ... $1\n";
					print `kermit -g $1`; 	
					next;};
# Comandi shell
/^\!(.*)/ 				&& do { system $1; next;};
# Quit
/^q$/					&& do { Exit; };
# Quando pigio RETURN 
/^$/					&& do { next;};
# Comandi KERMIT remoti
/(.*)/					&& do { SendCmd $1; next;};
}
