/*	TERM6.C		Subroutines for TERM.C - Part 6
			Binary file transfer

	Note:	These routines need to link GNF for
		treating ambiguous file names, and
		TX1, RX1 to transfer/receive 1 file.

	10 Mar 1988	A.Herrmann
*/

#include "stdio.h"
#include "term.h"
#include "term.e"


static char rx_call[4] = "RX\r";	/* call to RX on receiver	*/


void tx(finame,item)	/* transfers possibly ambiguous file(s) finame	*/
char *finame;		/* to be received by RX				*/
int item;		/* shows name of currently transferred file in item */
{
	char	name[16];		/* current file name		*/
	char	*fname;			/* pointer to current file name	*/
	FILE	*fp;			/* file pointer			*/

	char	ch;
	char	s_rs232();		/* sends char via RS232		*/
	char	*getffn(), *getnfn();	/* gets first, next file name	*/
	int	tx1();			/* transmits one file,		*/
					/* returns TRUE iff success	*/
	int	okay;			/* TRUE iff transfer successful	*/

	if (strlen(finame)==0) return;
	unintrpt();			/* turn off SIO interrupt mode	*/
	fname = rx_call;		/* call RX on receiver		*/
	while (ch=*fname++) {
		while (!s_rs232(ch)) ;	/* send one character...	*/
		while (!(ch=r_rs232()));/* ... and wait for echo	*/
	}
	fname = name;
	while (*fname++ = toupper(*finame++)) ;
	fname = getffn(fname=name);
	okay = FALSE;
	do {
		if ((fp = fopen(fname, "r")) != NULL) {
			fclose(fp);
			cpitem(fname,item);
			ptitem(item);
			okay = tx1(fname);
		}
	} while (okay && (fname=getnfn()));
	tx1("");			/* signal EOT			*/
	cpitem(par[item].alt[0],item);	/* clear item in status line	*/
	ptitem(item);
	intrpt();			/* turn on SIO interrupt mode	*/
}


void rx(finame,item)	/* receives file finame	to be sent by TX	*/
char *finame;
int item;		/* shows name of currently transferred file in item */
{
}
