/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Christoph Renner co-programmer: ... */ //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ #include "cmd_line_prefs_reader.h" using namespace std; static const argp_option argp_options[] = { {"server", 's', 0, 0, "Run as Server"}, {"client", 'c', 0, 0, "Run as Client"}, {"host", 'h', "ADDRESS", 0, "Host to connect to"}, {"port", 'p', "PORT", 0, "Port number"}, {"user-config", 1000, "FILE", 0, "Location of config file" }, { 0 } }; const char* argp_program_version = "orxonox"; const char* argp_program_bug_address = "bugs@orxonox.net"; static char doc[] = "doc goes here"; static char args_doc[] = "args doc goes here"; static Argp argp = { argp_options, CmdLinePrefsReader::parse_opt, args_doc, doc }; /** * standard constructor */ CmdLinePrefsReader::CmdLinePrefsReader(int argc, char** argv) { //set default values cmdLineArgs.host = NULL; cmdLineArgs.port = NULL; cmdLineArgs.configFile = NULL; cmdLineArgs.isServer = false; cmdLineArgs.isClient = false; int endIndex = 0; argp_parse(&argp, argc, argv, 0, &endIndex, &(this->cmdLineArgs)); PRINTF(0)("host = %s\n", cmdLineArgs.host); PRINTF(0)("port = %s\n", cmdLineArgs.port); PRINTF(0)("configfile = %s\n", cmdLineArgs.configFile); PRINTF(0)("server = %d\n", cmdLineArgs.isServer); PRINTF(0)("client = %d\n", cmdLineArgs.isClient); } /** * standard deconstructor */ CmdLinePrefsReader::~CmdLinePrefsReader () { } error_t CmdLinePrefsReader::parse_opt(int key, char *arg, ArgpState *state) { CmdLineArgs * cmdLineArgs = (CmdLineArgs*)(state->input); switch ( key ) { case 1000: if ( cmdLineArgs->configFile!=NULL ) delete[] cmdLineArgs->configFile; cmdLineArgs->configFile = new char[strlen(arg)+1]; strcpy(cmdLineArgs->configFile, arg); break; case 's': cmdLineArgs->isServer = true; break; case 'c': cmdLineArgs->isClient = true; break; case 'h': if ( cmdLineArgs->host!=NULL ) delete[] cmdLineArgs->host; cmdLineArgs->host = new char[strlen(arg)+1]; strcpy(cmdLineArgs->host, arg); break; case 'p': if ( cmdLineArgs->port!=NULL ) delete[] cmdLineArgs->port; cmdLineArgs->port = new char[strlen(arg)+1]; strcpy(cmdLineArgs->port, arg); break; default: return ARGP_ERR_UNKNOWN; } return 0; }