/*	XWP.C
**
**	The Executive Workplace
*/

#include "a:stdio.h"
#include "b:oxege.h"

#define	FLAGLOC	57

char FLmenu;		/* print menu? */
int *FLchain;		/* chain flag location */
extern char FLbclock, FLcalendar, FLerror, FLprint;
extern char stdate[];
extern int year;
extern char FLIclock, FLIcalendar, FLdial;
extern char Tcom[], Tlabel[], Thelp[];
extern char Ecom[], Elabel[], Ehelp[];
extern char Scom[], Slabel[], Shelp[], GLname[];

main()
	{
	int choice; 

	FLchain = FLAGLOC;

	setwindow( 0 );
	defcursor( 0 );

	setup();

	if ( *FLchain != 255 )			/* Initialize */
		{
		cls();
		ascrn();
		initmsg();
		signon( 1 );
		getdate();
		terminit();
		if ( year < 1986 )
			{
			reset();
			}
		if (FLIclock)
			{
			initclk();
			FLbclock = 1;
			}
		else	{
			FLbclock = NULL;
			}
		if (FLIcalendar)
			{
			FLcalendar = 1;
			calendar();
			}
		else	{
			FLcalendar = NULL;
			}
		exclock();
		}
	else
		{
		if( *( FLchain ) == 255 )	/* Reinitialize */
			{
			ascrn();
			}
		if  ( *(FLchain-1) == 255 )
			{
			initclk();
			FLbclock = 1;
			}
		else	{
			FLbclock = NULL;
			}
		if  ( *(FLchain-2) == 255 )
			{
			FLcalendar = 1;
			calendar();
			}
		else	{
			FLcalendar = NULL;
			}
		}
	FLdial = NULL;
	FLmenu = 1;
	*FLchain = 255;
	getstd();
	minit();
	message( 1, 0, "XWP 1.1" );
	message( 2, 0, greeting() );
	message( 3, 0, stoupper( stdate ) );

	while( 1 )
		{
		choice = mainmenu();
		switch( choice )
			{		
			case 1:
				signon( NULL );
				break;
			case 2:
				optmenu();
				break;
			case 3:
				filemenu();
				break;
			case 4:
				telmenu();
				break;
			case 5:
				break;
			case 6:
				user();
				break;
			case 7:
				shellmenu();
				break;
			case 8:
				if( FLprint == 1 )
					{
					error( "PRINT ACTIVE " );
					break;
					}
				defcursor( 3 );
				*FLchain = 0;
				exclock();
				cls();
				return;
			}
		}
	}

ascrn()
	{
	fill( 1, 1, 22, 78, FILL1, ATTDIM | ATTALT );
	fill( 0, 0, 0, 79, ' ' | ATTINV, ATTDIM | ATTUND );
	fill( 1, 0, 22, 0, OUTDIM, ATTDIM | ATTALT );
	fill( 1, 79, 22, 79, OUTDIM + 1, ATTDIM | ATTALT );
	}

/*	TASKS
**
**	Multi-tasking operations for XWP
*/
tasks()
	{
	bclock();
	print();
	}


execl( cmndstr )
	char *cmndstr;
	{
	char *dmaptr;
	if ( FLprint == 1 )
		{
		error( "PRINT ACTIVE" );
		FLerror = 0;
		return;
		}
	dmaptr = 128;
	defwindow( 1, 0, 0, 22, 79 );
	co( 26 );
	strcpy( dmaptr, cmndstr );
	if (FLbclock )
		{
		*(FLchain-1) = 255;
		}
	else	{
		*(FLchain-1) = NULL;
		}
	defcursor( 3 );
	Ubdos( 47, 0 );
	}

setup()
	{
	int sdatfile;
	if( (sdatfile = fopen( "XWP.CFG", "r" ) ) == NULL )
		{
		return;
		}
	fscanf( sdatfile, "%d %d %s %s",
		&FLIclock, &FLIcalendar,
		Tcom, Tlabel );
	fgets(  Thelp, 25, sdatfile );
	fscanf( sdatfile, "%s %s", Ecom, Elabel );
	fgets(  Ehelp, 25, sdatfile );
	fscanf( sdatfile, "%s %s", Scom, Slabel );
	fgets(  Shelp, 25, sdatfile );
	fgets(  GLname, 10, sdatfile );
	fclose( sdatfile );
	xcr( Thelp );
	xcr( Ehelp );
	xcr( Shelp );
	xcr( GLname );
	}

xcr( string )
	char string[];
	{
	char *pointer;
	pointer = string;
	pointer[ strlen( string ) - 1 ] = 0;
	}
 );
	}

xcr( string )
	char