/*  testchx.c -- test the Check Register Program under Concurrent DOS 8-16  */

#include    "a:bdscio.h"

main()
{
	test1();
	test2();
	type1();
	type2();
}

test1()
{
	char i, bufout[ BUFSIZ];

	puts( "\ntest1:\n");
	reset();
	if ( fcreat( "TEST.$$$", bufout) == ERROR)
		abort( "create");
	puts( "writing TEST.$$$: ");
	for ( i = 0; i < 20; ++i)
	{
		putc( '1', bufout);
		putchar( '1');
	}
	putc( CPMEOF, bufout);
	if ( fclose( bufout) == ERROR)
		abort( "close");
	unlink( "TEST1");
	puts( "\nrenaming TEST1=TEST.$$$\n");
	if ( rename( "TEST.$$$", "TEST1") == ERROR)
		abort( "rename");
}

test2()
{
	char i, bufout[ BUFSIZ];

	puts( "\ntest2:\n");
	reset();
	if ( fcreat( "TEST.$$$", bufout) == ERROR)
		abort( "create");
	puts( "writing TEST.$$$: ");
	for ( i = 0; i < 20; ++i)
	{
		putc( '2', bufout);
		putchar( '2');
	}
	putc( CPMEOF, bufout);
	if ( fclose( bufout) == ERROR)
		abort( "close");
	unlink( "TEST2");
	puts( "\nrenaming TEST2=TEST.$$$\n");
	if ( rename( "TEST.$$$", "TEST2") == ERROR)
		abort( "rename");
}

type1()
{
	char i, bufin[ BUFSIZ];

	puts( "\ntype1:\n");
	if ( fopen( "TEST1", bufin) == ERROR)
		abort( "open");
	puts( "reading TEST1: ");
	while (( i = getc( bufin)) != CPMEOF && i != ERROR)
		putchar( i);
	putchar( '\n');
	if ( fclose( bufin) == ERROR)
		abort( "close");
}

type2()
{
	char i, bufin[ BUFSIZ];

	puts( "\ntype2:\n");
	if ( fopen( "TEST2", bufin) == ERROR)
		abort( "open");
	puts( "reading TEST2: ");
	while (( i = getc( bufin)) != CPMEOF && i != ERROR)
		putchar( i);
	putchar( '\n');
	if ( fclose( bufin) == ERROR)
		abort( "close");
}

reset()
{
	int d;

	d = bdos( 25, 0) & 0x0f;	/*  currently selected drive  */
	bdos( 13, 0);			/*  reset  */
	bdos( 14, d);			/*  reselect  */
}

abort( s)
char *s;
{
	puts( "\nERROR: could not ");
	puts( s);
	puts( " file");
	exit();
}
);			/*  reselect  */
}

abort( s)
char *s;
{
	puts( "\nERROR: could not ");
	puts( s);
	puts( " file");
	