
#include "a:stdio.h"
#include "b:oxege.h"

extern char FLmenu, FLbclock, FLcalendar, FLerror;
extern char Ecom[], Elabel[], Ehelp[];
extern char Tcom[], Tlabel[], Thelp[];
extern char Scom[], Slabel[], Shelp[];
extern char filename[], scratch[];
extern int *FLchain;

mainmenu()
	{ 
	int choice;

	setmenu( 1, 10, " HELP " );
	setmenu( 2, 10, " OPTIONS " );
	setmenu( 3, 10, " FILES " );
	setmenu( 4, 10, " TELCOM " );
	setmenu( 5, 10, " " );
	setmenu( 6, 10, " USER " );
	setmenu( 7, 10, " SHELL " );
	setmenu( 8, 10, " EXIT " );

	choice = menu( 0, 0, 8, 1, 10, FLmenu );
	FLmenu = 0;
	setwindow( 0 );
	return choice;
	}

filemenu()
	{
	int choice;
	setmenu( 1, 10, " SWEEP " );
	setmenu( 2, 10, " EDIT " );
	setmenu( 3, 10, " PRINT " );
	setmenu( 4, 10, " RETURN " );

	choice = menu( 1, 20, 1, 4, 10, 1 );

	setwindow(0);
	fill( 1, 20, 4, 30, FILL1, ATTDIM | ATTALT );

	switch( choice )
		{
		case 1:
			check( Scom );
			if ( FLerror )
				{
				FLerror = NULL;
				return;
				}
			message( 1, 0, Slabel );
			message( 2, 0, Shelp );
			strcpy( scratch, Scom );
			strcat( scratch, "!xwp" );
			execl( scratch );
			break;
		case 2:
			edit();
			break;
		case 3:
			initprn();
			break;
		case 4:
			break;
		}
	}

edit()
	{
	check( Ecom );
	if (FLerror)
		{
		FLerror = NULL;
		return;
		}
	spoke( 1, 20, " FILE TO EDIT:   ", ATTDIM );
	spoke( 2, 20, "                 ", ATTBRT | INVATT);
	adr( 2, 21 );
	fflush( stdin );
	defcursor( 3 );
	gets( filename );
	defcursor( 0 );
	*(FLchain-3) = 255;
	defwindow( 1, 1, 0, 22, 79 );
	cls();
	strcpy( scratch, Ecom );
	strcat( scratch, " " );
	strcat( scratch, filename );
	strcat( scratch, " !xwp " );
	message( 1, 0, Elabel );
	message( 2, 0, Ehelp );
	execl( scratch );
	}

optmenu()
	{
	int choice;

	setmenu( 1, 12, " CLOCK " );
	setmenu( 2, 12, " CALENDAR " );
	setmenu( 3, 12, " RESET " );
	setmenu( 4, 12, " PRINTER " );
	setmenu( 5, 12, " RETURN " );

	choice = menu( 1, 10, 1, 5, 12, 1 );
	setwindow( 0 );

	fill( 1, 10, 5, 10+12, FILL1, ATTDIM | ATTALT );

	/* switch goes here */
	switch( choice )
		{
		case 1:
			if ( FLbclock == 1)
				{
				clrclk();
				}
			else	{
				initclk();
				}
			break;
		case 2:
			if ( FLcalendar )
				{
				clrcal();
				}
			else	{
				calendar();
				}
			FLcalendar = !FLcalendar;
			break;
		case 3:
			reset();
			break;
		case 4:
			printer();
			break;
		case 5:
			break;
		}
	}

telmenu()
	{
	int choice;
	setmenu( 1, 10, " DIAL " );
	setmenu( 2, 10, " TERM " );
	setmenu( 3, 10, " TELCOM " );
	setmenu( 4, 10, " RETURN " );
	choice = menu( 1, 30, 1, 4, 10, 1 );
	fill( 1, 30, 4, 40, FILL1, ATTDIM | ATTALT );
	switch( choice )
		{
		case 1:
			dial();
			break;
		case 2:
			term();
			break;
		case 3:
			check( Tcom );
			if ( FLerror )
				{
				FLerror = NULL;
				return;
				}
			message( 1, 0, Tlabel );
			message( 2, 0, Thelp );
			strcpy( scratch, Tcom );
			strcat( scratch, "!xwp" );
			execl( scratch );
			break;
		case 4:
			break;
		}
	}

shellmenu()
	{
	int choice;
	setmenu( 1, 10, " EXECUTE " );
	setmenu( 2, 10, " CP/M+ " );
	setmenu( 3, 10, " RETURN " );
	choice = menu( 1, 60, 1, 3, 10, 1 );
	fill( 1, 60, 3, 70, FILL1, ATTDIM | ATTALT );
	switch( choice )
		{
		case 1:
			fill( 4, 20, 7, 60, ' ', ATTBRT );
			outline( 4, 20, 7, 60, OUTBLK, ATTDIM | ATTALT );
			fill( 5, 21, 5, 59, ' ' | ATTINV, ATTDIM );
			spoke( 5, 28, " Enter CP/M command line: ", ATTDIM );
			setwindow( 0 );
			defcursor( 3 );
			defwindow( 1, 6, 21, 6, 59 );
			gets( scratch );
			strcat( scratch, "!xwp " );
			message( 1, 0, "XWP" );
			message( 2, 0, "EXECUTING COMMAND..." );
			execl( scratch );
			break;
		case 2:
			message( 1, 0, "CP/M+" );
			message( 2, 0, " " );
			defwindow( 1, 0, 0, 22, 79 );
			defcursor( 3 );
			co( 26 );
			abort( 1 );
			break;
		case 3:
			break;
		}
	}

		defwindow( 1, 0, 0, 22, 79 );
			defcursor( 3 );
			co( 26 );
			abo