void
GetOptions
	(
	const JSize			argc,
	char*				argv[],
	JPtrArray<JString>*	inputFileList,
	JString*			dataVarName,
	JString*			outputFileName,
	JString*			databaseFileName,
	JBoolean*			debug
	)
{
	inputFileList->CleanOut();
	dataVarName->Clear();
	outputFileName->Clear();
	databaseFileName->Clear();
	*debug = kJFalse;

	JIndex index = 1;
	while (index < argc)
		{
		if (JIsVersionRequest(argv[index]))
			{
			PrintVersion();
			exit(0);
			}
		else if (JIsHelpRequest(argv[index]))
			{
			PrintHelp();
			exit(0);
			}

		else if (strcmp(argv[index], "--code") == 0)
			{
			JCheckForValues(2, &index, argc, argv);
			*dataVarName    = argv[index];
			*outputFileName = argv[index+1];
			index++;
			}

		else if (strcmp(argv[index], "--db") == 0)
			{
			JCheckForValues(1, &index, argc, argv);
			*databaseFileName = argv[index];
			}

		else if (strcmp(argv[index], "--debug") == 0)
			{
			*debug = kJTrue;
			}

		else if (argv[index][0] == '-')
			{
			cerr << argv[0] << ": unknown command line option: " << argv[index] << endl;
			}

		else
			{
			JString* inputFileName = new JString(argv[index]);
			assert( inputFileName != NULL );

			if (inputFileName->EndsWith("~") ||
				inputFileName->BeginsWith("#"))
				{
				delete inputFileName;
				}
			else
				{
				inputFileList->Append(inputFileName);
				}
			}

		index++;
		}

	if (inputFileList->IsEmpty())
		{
		cerr << argv[0] << ": no input files" << endl;
		exit(1);
		}
}
void
ParseOptions
	(
	const JSize	argc,
	char*		argv[],
	JString*	fileName,
	JBoolean*	printInfo,
	int*		transparentColor,
	LaceOption*	interlace,
	JBoolean*	padColormap,
	JBoolean*	blend,
	JFloat*		alpha,
	JRGB*		alphaColor,
	JString*	blendOutput
	)
{
	if (argc == 1)
		{
		PrintHelp();
		exit(0);
		}

	fileName->Clear();
	*printInfo        = kJFalse;
	*transparentColor = kTransparentColorNotSet;
	*interlace        = kIgnoreInterlace;
	*padColormap      = kJFalse;
	*blend            = kJFalse;

	JIndex index = 1;
	while (index < argc)
		{
		if (strcmp(argv[index], "-h") == 0 ||
			strcmp(argv[index], "--help") == 0)
			{
			PrintHelp();
			exit(0);
			}
		else if (strcmp(argv[index], "-v") == 0 ||
				 strcmp(argv[index], "--version") == 0)
			{
			PrintVersion();
			exit(0);
			}

		else if (strcmp(argv[index], "-i") == 0)
			{
			*printInfo = kJTrue;
			}

		else if (strcmp(argv[index], "-t") == 0)
			{
			JCheckForValues(1, &index, argc, argv);
			if (strcmp(argv[index], "none") == 0)
				{
				*transparentColor = kNoTransparentColor;
				}
			else if ('0' <= argv[index][0] && argv[index][0] <= '9')
				{
				*transparentColor = atoi(argv[index]);
				}
			else
				{
				cerr << argv[0] << ": -t requires a number or none" << endl;
				exit(1);
				}
			}

		else if (strcmp(argv[index], "-l") == 0)
			{
			JCheckForValues(1, &index, argc, argv);
			if (strcmp(argv[index], "on") == 0)
				{
				*interlace = kTurnInterlaceOn;
				}
			else if (strcmp(argv[index], "off") == 0)
				{
				*interlace = kTurnInterlaceOff;
				}
			else
				{
				cerr << argv[0] << ": -l requires either on or off" << endl;
				exit(1);
				}
			}

		else if (strcmp(argv[index], "-p") == 0)
			{
			*padColormap = kJTrue;
			}

		else if (strcmp(argv[index], "-b") == 0)
			{
			JCheckForValues(5, &index, argc, argv);
			*blend            = kJTrue;
			*alpha            = atof(argv[index]);
			alphaColor->red   = atoi(argv[index+1]);
			alphaColor->green = atoi(argv[index+2]);
			alphaColor->blue  = atoi(argv[index+3]);
			*blendOutput      = argv[index+4];
			index += 4;
			}

		else if (argv[index][0] == '-')
			{
			cerr << argv[0] << ": unknown option " << argv[index] << endl;
			exit(1);
			}

		else if (fileName->IsEmpty())
			{
			if (!JFileReadable(argv[index]))
				{
				cerr << argv[0] << ": file is unreadable" << endl;
				exit(1);
				}
			if (!JFileWritable(argv[index]))
				{
				cerr << argv[0] << ": file is unwriteable" << endl;
				exit(1);
				}
			*fileName = argv[index];
			}

		else
			{
			cerr << argv[0] << ": too many parameters" << endl;
			exit(1);
			}
		index++;
		}

	if (fileName->IsEmpty())
		{
		cerr << argv[0] << ": no input file specified" << endl;
		exit(1);
		}

	if (argc == 2)
		{
		*printInfo = kJTrue;
		}
}