
/*
 *	Program 	SpoolWatch
 *	Programmer	N.d'Alterio
 *	Date		09/09/95
 *
 *  Synopsis:	Displays information on the contents of the news and
 *		mail spool directories. With or without GUI.
 *
 *  Arguments:	MAILDIR\K			Location of mail spool dir (CLI)
 *		NEWSDIR\K			Location of news spool dir (CLI)
 *		NOGUI\S				Don't open GUI (CLI)
 *		FULL\S				Prints full info (CLI)
 *		LEFT\N				Left edge of window (CLI)
 *		TOP\N				Top edge of window (CLI)
 *
 *		NEWSDIR				Location of news spool dir (WB)
 *		MAILDIR				Location of mail spool dir (WB)
 *		TOP				Top edge of window (WB)
 *		LEFT				Left edge of window (WB)
 *
 *  Inputs:					None.
 *
 *  Outputs:					None.
 *
 *  Variables:	exit_code			Program return code.
 *		exit_flag			Flag to show if early exit is needed.
 *		nfi				News FullInfo struct.
 *		mfi				Mail FullInfo struct.
 *		swa				Program args struct.
 *
 *  Functions:	OpenLibrary			Opens a library (EXEC)
 *		CloseLibrary			Closes a library (EXEC)
 *		ProgArgsWB			Gets arguments from WB (SW)
 *		ProgArgsCLI			Gets aruments for CLI (SW)
 *		FullSpoolInfo			Reads full information on spooldir (SW)
 *		SpoolWindow			Opens the SpoolWatch GUI (SW)
 *		SpoolCLI			Prints simple spool info to stdout (SW)
 *		PrintFullInfo			Prints full spool info to stdout (SW)
 *		FreeProgArgs			Frees prog args struct (SW)
 *		SWError				Displays error message (SW)
 *		fprintf				Prints to stream (ANSI)
 *		exit				Ends program (ANSI)
 *
 * $Id: SpoolWatch.c 2.6 1995/09/28 00:20:52 daltern Exp $
 *
 */

#include "SpoolWatch.h"

extern struct Library *DOSBase;

char *version = "$VER: SpoolWatch 2.8 (02.10.95) Nick d'Alterio";
 
int main( int argc, char *argv[] )

{

  int exit_code = 0;
  int exit_flag = FALSE;

  struct SWArgs   *swa;

  struct FullInfo *nfi;
  struct FullInfo *mfi;

  if ( DOSBase = OpenLibrary( "dos.library", 37 ) ) {
      

/*
 *  Get args corresponding to the program start method.
 */

	if ( argc == 0 ) {

/*
 *   Started via workbench.
 */
		if ( !( swa = ProgArgsWB( argv ) ) ) {
			exit_code = 0;
			exit_flag = TRUE;
		}   /* end if ProgArgsWB */
	
	} else {

/*
 *   Started from shell.
 */

		if ( !( swa = ProgArgsCLI() ) ) {
			exit_code = 0;
			exit_flag = TRUE;
		}   /* end if ProgArgsCli */

	}   /* end if argc */

/*
 *   Build up the full info structures.
 */

	if ( !exit_flag ) {

		nfi = FullSpoolInfo( swa, NEWS_TYPE );
        	mfi = FullSpoolInfo( swa, MAIL_TYPE );

	}   /* end if !exit_flag */

/*	
 *   Use the GUI
 */

	if ( !swa->nogui && !exit_flag ) {

		exit_code = SpoolWindow( swa, nfi, mfi );
 
	}   /* end if !nogui */

/*
 *   Shell Output case.
 */

	if (  swa->nogui && !exit_flag ) {

		switch ( swa->full ) { 

/*
 *   Give the full information.
 */
			
			case TRUE:
	
				if ( !nfi ) {
	
					fprintf( stdout, "\n News spool is empty\n\n" );

				} else {

					fprintf( stdout, "\nNews Spool .....\n\n" );
					PrintFullInfo( nfi );
				}   /* end if files in spool */

				fprintf( stdout, "\n Press return to continue...\n\n" );
				getchar();

				if ( !mfi ) {
	
					fprintf( stdout, "\n Mail spool is empty\n\n" );

				} else {

					fprintf( stdout, "\nMail Spool .....\n\n" );
					PrintFullInfo( mfi );
				}   /* end if files in spool */

				break;

/*
 *   Just give number of files in each spool.
 */

			case FALSE:

				SpoolCLI( nfi, mfi );
				break;
			
		}   /* end switch full */
		
	}   /* end if nogui */

/*
 *   Free up resources.
 */
 	
	FreeProgArgs( swa );

	CloseLibrary( DOSBase );

  }   /* end if DOSBase */

  exit( exit_code );

}   /* end program SpoolWatch */

/*========================================================================*
			END PROGRAM SpoolWatch
 *========================================================================*/



  