
/*% cc -DUNIX %  -o itest; size itest;
 ****************************************************************************
 *
 * sendline(c)  sends a character to host
 * mputs(s) sends null terminated string to host
 *
 * purgeline()	empty receive queue
 * int readline(tenths) read char from host, timeout in seconds/10
	return received byte 0 to 0377
	negative return values indicate error:
		return -1 on recoverable error
		return -2 on timeout
	trap fatal errors (loss of carrier, etc.)
 * checkline() return non 0 if readline has 1 or more bytes ready
 *
 *
 ****************************************************************************
 */



#include "izm.h"


#define PATHLEN 256
#define OK 0
#define FALSE 0
#define TRUE 1
#define ERROR (-1)
/* Ward Christensen / CP/M parameters - Don't change these! */
#define CAN ('X'&037)
#define XOFF ('s'&037)
#define XON ('q'&037)
#define NAK 025
#define TIMEOUT (-2)


#ifdef UNIX
#include <stdio.h>

#define LOGFILE "/tmp/szlog"
int Verbose=0;
int errcnt=0;		/* number of files unreadable */
int Exitcode;
//#define POSIX
#include "rbunix.c"	/* most of the system dependent stuff here */
jmp_buf tohere;		/* For the interrupt on RX timeout */
jmp_buf intrjmp;	/* For the interrupt on RX CAN */

/* called by signal interrupt or terminate to clean things up */
void
bibi(n)
{
	mode(0);
	fprintf(stderr, "sz: caught signal %d; exiting\n", n);
	if (n == SIGQUIT)
		abort();
	if (n == 99)
		fprintf(stderr, "mode(2) in rbsb.c not implemented!!\n");
	exit(128+n);
}
/* Called when ZMODEM gets an interrupt (^X) */
onintr()
{
	signal(SIGINT, SIG_IGN);
	longjmp(intrjmp, -1);
}



#endif

int checkline();
int readline();
void sendline();
void mputs();
void purgeline();




void test2(n)
{
	int c;

	printf("%d tenths of seconds\r\n", n);
        c = readline(n);
	printf("readline returned %d\r\n", c);
}

void
testit()
{
	int c, n;

	/* check checkline operation */
	printf("Hit a Character (or not)\r\n");
	sleep(5);
	c = checkline();
	printf("Checkline returned %d \r\n", c);
	/* OK if readline returns TIMEOUT here */
        c = readline(1);
	printf("readline returned %d\r\n\n", c);

	/* check purgeline operation */
	printf("Purgeline test: Hit some characters quickly\r\n");
	sleep(5);
	purgeline();
	printf("Purgeline called\r\n");
	c = checkline();
	printf("Checkline returned %d \r\n", c);
	if (c) {
		printf("Should have returned 0\r\n");
		return;
	}

	test2(1);
	test2(10);
	test2(100);
	test2(600);

}




main(argc, argv)
char *argv[];
{

	mode(1);

	signal(SIGKILL, bibi);
	signal(SIGINT, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGTERM, bibi);

	testit();

	mode(0);
	exit(0);
	/*NOTREACHED*/
}


/* End of itest.c */
