/******************************************************************************
 systemg.cc

	This provides a way to test the JX library and provides sample source
	code for everyone to study.

	Copyright © 1997 by Glenn W. Bach. All rights reserved.

 ******************************************************************************/

#include <SyGApplication.h>
#include <SyGMDIServer.h>

#include <JXLibVersion.h>

#include <JCoreLibVersion.h>
#include <JString.h>

#include <iostream.h>
#include <stdlib.h>
#include <jAssert.h>

extern JCharacter* kFMSig;

const JCharacter* kSystemGVersionNumberStr = "1.0.1";

const JCharacter* kSystemGVersionStr =

	"SystemG 1.0.1\n"
	"\n"
	"A file manager for X.\n"
	"\n"
	"Copyright © 1999 by Glenn W. Bach.\n"
	"The binary version of this program may be\n"
	"freely distributed at no charge.\n"
	"\n"
	"http://www.its.caltech.edu/~glenn/systemg/\n"
	"glenn@its.caltech.edu";

void ParseTextOptions(const int argc, char* argv[]);

void PrintHelp();
void PrintVersion();

/******************************************************************************
 main

 ******************************************************************************/

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

	if (!SyGMDIServer::WillBeMDIServer(kFMSig, argc, argv))
		{
		return 0;
		}

	JBoolean displayAbout;
	JString prevVersStr;
	SyGApplication* app =
		new SyGApplication(&argc, argv, &displayAbout, &prevVersStr);
	assert( app != NULL );

	if (displayAbout)
		{
		app->DisplayAbout(prevVersStr);
		}

	
	app->Run();				// never actually returns
	return 0;
}

/******************************************************************************
 ParseTextOptions

	Handle the command line options that don't require opening an X display.

	Options that don't call exit() should use JXApplication::RemoveCmdLineOption()
	so ParseXOptions won't gag.

 ******************************************************************************/

void
ParseTextOptions
	(
	const int	argc,
	char*		argv[]
	)
{
	long index = 1;
	while (index < argc)
		{
		if (strcmp(argv[index], "-h") == 0)
			{
			PrintHelp();
			exit(0);
			}
		else if (strcmp(argv[index], "-v") == 0)
			{
			PrintVersion();
			exit(0);
			}
		index++;
		}
}

/******************************************************************************
 PrintHelp

	ruler:	 01234567890123456789012345678901234567890123456789012345678901234567890123456789

 ******************************************************************************/

void
PrintHelp()
{
	cout << endl;
	cout << "SystemG " << kSystemGVersionNumberStr << endl;
	cout << endl;
	cout << "This is a file manager for X." << endl;
	cout << endl;
	cout << "Because SystemG fully supports the Multiple Document concept," << endl;
	cout << "it can be safely invoked from the command line " << endl;
	cout << "as often as you like." << endl;
	cout << endl;
	cout << "Usage:" << endl;
	cout << "systemg dir dire ..." << endl;
	cout << endl;
	cout << "-h        prints this help" << endl;
	cout << "-v        prints version information" << endl;
	cout << endl;
	cout << "http://www.cco.caltech.edu/~glenn/systemg/" << endl;
	cout << "systemg@alice.wonderland.caltech.edu" << endl;
	cout << endl;
}

/******************************************************************************
 PrintVersion

 ******************************************************************************/

void
PrintVersion()
{
	cout << endl;
	cout << kSystemGVersionStr << endl;
	cout << endl;
}
