Index: trunk/src/orxonox.cc
===================================================================
--- trunk/src/orxonox.cc	(revision 7221)
+++ trunk/src/orxonox.cc	(revision 7256)
@@ -58,5 +58,6 @@
 
 #include "state.h"
-
+#include "lib/parser/preferences/cmd_line_prefs_reader.h"
+#include "lib/parser/preferences/ini_file_prefs_reader.h"
 #include <string.h>
 
@@ -66,4 +67,11 @@
 
 SHELL_COMMAND(restart, Orxonox, restart);
+
+REGISTER_ARG_FLAG( l, license, "misc", "showLicenseAndExit", "Prints the licence and exit",    "1" );
+REGISTER_ARG_FLAG( c, client,  "game", "gameType",           "Connect to Server (-H)",         "multiplayer_client" );
+REGISTER_ARG_FLAG( s, server,  "game", "gameType",           "Start Orxonox as Game Server",   "multiplayer_server" );
+REGISTER_ARG_ARG(  H, host,    "game", "host",               "Host to connect to",             "host");
+REGISTER_ARG_ARG(  p, port,    "game", "port",               "Port to use",                    "port" );
+REGISTER_ARG_FLAG( g, gui,     "game", "showGui",            "starts the orxonox with the configuration GUI", "1");
 
 /**
@@ -77,11 +85,9 @@
   this->setName("orxonox-main");
 
-  this->iniParser = NULL;
-
   this->argc = 0;
   this->argv = NULL;
 
   /* this way, there is no network enabled: */
-  this->serverName = NULL;
+  this->serverName = "";
   this->port = -1;
 
@@ -114,7 +120,4 @@
   // output-buffer
   delete ShellBuffer::getInstance();
-
-  // orxonox class-stuff
-  delete this->iniParser;
 
   SDL_QuitSubSystem(SDL_INIT_TIMER);
@@ -175,5 +178,5 @@
   else
     this->configFileName = ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE);
-  this->iniParser = new IniParser(this->configFileName);
+
   PRINTF(3)("Parsed Config File: '%s'\n", this->configFileName);
 }
@@ -182,5 +185,5 @@
  * initialize Orxonox with command line
  */
-int Orxonox::init (int argc, char** argv, const char* name, int port)
+int Orxonox::init (int argc, char** argv, const std::string & name, int port)
 {
   this->argc = argc;
@@ -227,5 +230,5 @@
   GraphicsEngine::getInstance();
 
-  GraphicsEngine::getInstance()->initFromIniFile(this->iniParser);
+  GraphicsEngine::getInstance()->initFromPreferences();
 
   std::string iconName = ResourceManager::getFullName("pictures/fighter-top-32x32.bmp");
@@ -247,5 +250,5 @@
   SoundEngine::getInstance();
 
-  SoundEngine::getInstance()->loadSettings(this->iniParser);
+  SoundEngine::getInstance()->loadSettings();
   SoundEngine::getInstance()->initAudio();
   return 0;
@@ -260,5 +263,5 @@
   PRINT(3)("> Initializing input\n");
 
-  EventHandler::getInstance()->init(this->iniParser);
+  EventHandler::getInstance()->init();
   EventHandler::getInstance()->subscribe(GraphicsEngine::getInstance(), ES_ALL, EV_VIDEO_RESIZE);
 
@@ -274,5 +277,5 @@
   PRINT(3)("> Initializing networking\n");
 
-  if( this->serverName != NULL) // we are a client
+  if( this->serverName != "") // we are a client
   {
     State::setOnline(true);
@@ -299,5 +302,5 @@
   // init the resource manager
   std::string dataPath;
-  if ((dataPath = this->iniParser->getVar(CONFIG_NAME_DATADIR, CONFIG_SECTION_DATA))!= "")
+  if ((dataPath = Preferences::getInstance()->getString(CONFIG_SECTION_DATA, CONFIG_NAME_DATADIR, ""))!= "")
   {
     if (!ResourceManager::getInstance()->setDataDir(dataPath) &&
@@ -403,49 +406,25 @@
 int main(int argc, char** argv)
 {
-  int i;
-  for(i = 1; i < argc; ++i)
-  {
-    if(     !strcmp( "--help", argv[i])     || !strcmp("-h", argv[i]))
-      return showHelp(argc, argv);
-    else if(!strcmp( "--gui", argv[i])      || !strcmp("-g", argv[i]))
-      showGui = true;
-    else if(!strcmp( "--client", argv[i])   || !strcmp("-c", argv[i]))
-      return startNetworkOrxonox(argc, argv);
-    else if(!strcmp( "--server", argv[i])   || !strcmp("-s", argv[i]))
-      return startNetworkOrxonox(argc, argv);
-    else if(!strcmp( "--license", argv[i])  || !strcmp("-l", argv[i]))
-      return PRINT(0)(ORXONOX_LICENSE_SHORT);
-  }
-
-  return startOrxonox(argc, argv, NULL, -1);
-}
-
-
-
-int showHelp(int argc, char** argv)
-{
-  PRINT(0)("Orxonox Version %s\n", PACKAGE_VERSION);
-  PRINT(0)(" Starts Orxonox - The most furious 3D Action Game :)\n");
-  PRINT(0)("\n");
-  PRINT(0)("Common options:\n");
-  PRINT(0)(" -g, --gui                        starts the orxonox with the configuration GUI \n");
-  PRINT(0)(" -h, --help                       shows this help\n");
-  PRINT(0)("\n");
-  PRINT(0)("Network options:\n");
-  PRINT(0)(" -s, --server [port]              starts Orxonox and listens on the [port] for players\n");
-  PRINT(0)(" -c, --client [hostname] [port]   starts Orxonox as a Client\n");
-  PRINT(0)(" -c, --client [ip address] [port] starts Orxonox as a Client\n");
-  PRINT(0)("\n");
-  PRINT(0)("Other options:\n");
-  PRINT(0)("     --license     prints the licence and exit\n\n");
-  PRINT(0)("\n");
-
-  //   {
-  //     Gui* gui = new Gui(argc, argv);
-  //     gui->printHelp();
-  //     delete gui;
-  //   }
-}
-
+  CmdLinePrefsReader prefs;
+  
+  IniFilePrefsReader ini(ResourceManager::homeDirCheck(DEFAULT_CONFIG_FILE));
+  
+  prefs.parse(argc, argv);
+  
+  if ( Preferences::getInstance()->getString("misc", "showLicenseAndExit", "") == "1" )
+  {
+    PRINT(0)(ORXONOX_LICENSE_SHORT);
+    return 0;
+  }
+  
+  if( Preferences::getInstance()->getString("game", "showGui", "") == "1" )
+    showGui = true;
+  else if( Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_server" ||
+           Preferences::getInstance()->getString( "game", "gameType", "" ) == "multiplayer_client" )
+    return startNetworkOrxonox(argc, argv);
+  
+  return startOrxonox(argc, argv, "", -1);
+  return 0;
+}
 
 
@@ -459,37 +438,28 @@
 {
 
-  int i;
-  for(i = 0; i < argc; ++i )
-  {
-    if( !strcmp( "--client", argv[i]) || !strcmp("-c", argv[i]))
+  std::string gameType = Preferences::getInstance()->getString( "game", "gameType", "" );
+  
+  if ( gameType == "multiplayer_client" )
+  {
+    int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT );
+    std::string host = Preferences::getInstance()->getString( "game", "host", "" );
+    
+    if ( host == "" )
     {
-      if( argc <= (i+2))
-      {
-        printf(" Wrong arguments try following notations:\n");
-        printf("   --client [server ip address] [port number]\n");
-        printf("   --client [dns name] [port number]\n");
-        return 0;
-      }
-
-      const char* name = argv[i+1];
-      int port = atoi(argv[i+2]);
-      printf("Starting Orxonox as client: connecting to %s, on port %i\n", name, port);
-
-      startOrxonox(argc, argv, name, port);
+      printf("You need to specify a host to connect to ( -H <host> )\n");
+      return 1;
     }
-    else if( !strcmp( "--server", argv[i]) || !strcmp("-s", argv[i]))
-    {
-      if( argc <= (i+1))
-      {
-        printf(" Wrong arguments try following notations:\n");
-        printf("   --server [port number]\n");
-        return 0;
-      }
-
-      int port = atoi(argv[i+1]);
-      printf("Starting Orxonox as server, listening on port %i\n", port);
-
-      startOrxonox(argc, argv, NULL, port);
-    }
+    
+    printf("Starting Orxonox as client: connecting to %s, on port %i\n", host.c_str(), port);
+    
+    startOrxonox(argc, argv, host.c_str(), port);
+  }
+  else if ( gameType == "multiplayer_server" )
+  {
+    int port = Preferences::getInstance()->getInt( "game", "port", DEFAULT_ORXONOX_PORT );
+    
+    printf("Starting Orxonox as server: listening on port %i\n", port);
+    
+    startOrxonox(argc, argv, "", port);
   }
 }
@@ -502,5 +472,5 @@
  * @param argv parameters given to orxonox
  */
-int startOrxonox(int argc, char** argv, const char* name, int port)
+int startOrxonox(int argc, char** argv, const std::string & name, int port)
 {
   // checking for existence of the configuration-files, or if the lock file is still used
