// BlinkGame - Hunt for the Lost Pixels
// an SDL game in honor of the BlinkenArea crew
//
// (C) 2005-06 Rene Schickbauer
//
// See License.txt for licensing information
//
#ifdef NOP_CODE
/*--------------------------------------------------------------------
CVS AUTO-GENERATED INFO
$Author: dauti $
$Date: 2006/03/16 20:37:17 $
$Name: rel-0-3-patches $
$Revision: 1.7 $
$State: Exp $

$Log: cmdopts.cpp,v $
Revision 1.7  2006/03/16 20:37:17  dauti
Include the name of the called executable in the help text. Just "blinkensisters" was wrong.

Revision 1.6  2006/03/07 16:52:11  dauti
Modified output of "-h/--help", so that it is like the output of many other programs.
The compiled in default (fullscreen or not) is now printed.

Revision 1.5  2006/03/02 13:03:41  cavac
Re-formatted all .cpp and .h files a bit to get rid of the TAB/SPACE mess
that makes troubles with XCode's "re-format" feature

Revision 1.4  2006/02/10 18:56:17  cavac
Code Audit: Fixed many 64Bit based problems (mostly untested)

Revision 1.3  2006/02/10 17:50:26  cavac
Added ActionCapture feature (define ALLOW_ACTIONCAPTURE to allow this
resource-hungry extra)

Revision 1.2  2006/02/06 11:47:10  cavac
Changed command-line support in main.cpp to use cmdopts.*

Revision 1.1  2006/02/06 11:14:37  cavac
Module for handling command-line options


--------------------------------------------------------------------*/
#endif //NOP_CODE

#include "globals.h"
#include "cmdopts.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


CMD_OPTS cmd_opt_data[] = {
/* {short option name, long option name, description, is_boolean, defaultvalue_boolean, defaultvalue_string} */
#ifdef ENABLE_FULLSCREEN
#ifdef START_WITH_FULLSCREEN
{"-f", "--fullscreen", "Use Fullscreen (default)", true, true, ""},
{"-w", "--windowed", "Use windowed mode", true, false, ""},
#else // START_WITH_FULLSCREEN not defined
{"-f", "--fullscreen", "Use Fullscreen", true, true, ""},
{"-w", "--windowed", "Use windowed mode (default", true, false, ""},
#endif // START_WITH_FULLSCREEN
#endif // ENABLE_FULLSCREEN
#ifndef DISABLE_SOUND
{"-s", "--disable-sound", "Disable sound", true, false, ""},
#endif // DISABLE_SOUND
{"-v", "--version", "Print version information and exit", true, false, ""},
{"-h", "--help", "Command-line help", true, false, ""},
{"END", "END", "END", false, false, "END"}
};

//CMD_OPTS cmd_opt_data;

bool initCmdOpt(int ARGC, char **ARGV) {
	//memset(&cmd_opt_data, 0, sizeof(cmd_opt_data));
	
	bool paramOK = true;
	
	for(Uint32 i = 1; i < (Uint32)ARGC; i++) {
		CMD_OPTS *it = cmd_opt_data;
		bool found = false;
		while(strcmp(it->shortname, "END") != 0) {
			if(strcmp(ARGV[i], it->shortname) == 0 || strcmp(ARGV[i], it->fullname) == 0) {
				found = true;
				if(it->isBool) {
					it->defaultBool = true;
				} else {
					// FIXME
				}
			}
			it++;
		}
		if(!found) {
			printf("Unknown parameter: %s\n", ARGV[i]);
			paramOK = false;
		}
		
	}
	
	
	return paramOK;
}

bool getCmdOptBool(char* name) {
	CMD_OPTS *it = cmd_opt_data;
	bool found = false;
	bool value = false;
	
	while(strcmp(it->shortname, "END") != 0) {
		if(strcmp(name, it->shortname) == 0 || strcmp(name, it->fullname) == 0) {
			found = true;
			if(it->isBool) {
				value = it->defaultBool;
			} else {
				printf("Parameter %s is not a BOOL!\n", name);
				exit(1);
			}
		}
		it++;
	}
	if(!found) {
		printf("Unknown parameter: %s\n", name);
		exit(1);
	}
	return value;
}

char* getCmdOptString(char* name) {
	// FIXME
	return 0;
}

/* output help text, the argument is the name of the executable (determined from argv[0] */
void helpCmdOpt(char* name) {
	printf("Usage: %s [Options]\n",name);
	CMD_OPTS *it = cmd_opt_data;
	
	while(strcmp(it->shortname, "END") != 0) {
		printf("  %s, %-24s %s\n", it->shortname, it->fullname, it->description);
		it++;
	}
	exit(1);
}

