Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6392 in orxonox.OLD for branches/preferences/src/lib


Ignore:
Timestamp:
Jan 3, 2006, 11:29:18 AM (19 years ago)
Author:
rennerc
Message:

orxonox.cc in main(): reading command line
cmd_line_prefs_reader: should work now

Location:
branches/preferences/src/lib/parser/preferences
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.cc

    r6388 r6392  
    2020using namespace std;
    2121
     22static const argp_option   argp_options[] = {
     23  {"server",        's',        0,         0,   "Run as Server"},
     24  {"client",        'c',        0,         0,   "Run as Client"},
     25  {"host",          'h',        "ADDRESS", 0,   "Host to connect to"},
     26  {"port",          'p',        "PORT",    0,   "Port number"},
     27  {"user-config",   1000,       "FILE",    0,   "Location of config file" },
     28  { 0 }
     29};
     30
     31const char* argp_program_version     = "orxonox";
     32const char* argp_program_bug_address = "bugs@orxonox.net";
     33static char doc[]                    = "doc goes here";
     34static char args_doc[]               = "args doc goes here";
     35
     36static Argp argp = { argp_options, CmdLinePrefsReader::parse_opt, args_doc, doc };
    2237
    2338/**
    2439 * standard constructor
    2540*/
    26 CmdLinePrefsReader::CmdLinePrefsReader ()
     41CmdLinePrefsReader::CmdLinePrefsReader(int argc, char** argv)
    2742{
     43  //set default values
     44  cmdLineArgs.host       = NULL;
     45  cmdLineArgs.port       = NULL;
     46  cmdLineArgs.configFile = NULL;
     47  cmdLineArgs.isServer   = false;
     48  cmdLineArgs.isClient   = false;
     49
     50  argp_parse(&argp, argc, argv, 0, 0, &(this->cmdLineArgs));
     51
     52
     53  PRINTF(0)("host       = %s\n", cmdLineArgs.host);
     54  PRINTF(0)("port       = %s\n", cmdLineArgs.port);
     55  PRINTF(0)("configfile = %s\n", cmdLineArgs.configFile);
     56  PRINTF(0)("server     = %d\n", cmdLineArgs.isServer);
     57  PRINTF(0)("client     = %d\n", cmdLineArgs.isClient);
     58
    2859}
    2960
     
    3667}
    3768
     69error_t CmdLinePrefsReader::parse_opt(int key, char *arg, ArgpState *state)
     70{
     71  CmdLineArgs * cmdLineArgs = (CmdLineArgs*)(state->input);
    3872
     73  switch ( key )
     74  {
     75    case 1000:
     76      if ( cmdLineArgs->configFile!=NULL ) delete[] cmdLineArgs->configFile;
     77      cmdLineArgs->configFile = new char[strlen(arg)+1];
     78      strcpy(cmdLineArgs->configFile, arg);
     79      break;
     80
     81    case 's':
     82      cmdLineArgs->isServer = true;
     83      break;
     84
     85    case 'c':
     86      cmdLineArgs->isClient = true;
     87      break;
     88
     89    case 'h':
     90      if ( cmdLineArgs->host!=NULL ) delete[] cmdLineArgs->host;
     91      cmdLineArgs->host = new char[strlen(arg)+1];
     92      strcpy(cmdLineArgs->host, arg);
     93      break;
     94
     95    case 'p':
     96      if ( cmdLineArgs->port!=NULL ) delete[] cmdLineArgs->port;
     97      cmdLineArgs->port = new char[strlen(arg)+1];
     98      strcpy(cmdLineArgs->port, arg);
     99      break;
     100
     101    default:
     102      return ARGP_ERR_UNKNOWN;
     103  }
     104
     105  return 0;
     106}
     107
     108
     109
  • branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.h

    r6388 r6392  
    77#define _CMD_LINE_PREFS_READER_H
    88
     9#include "stdincl.h"
     10#include "debug.h"
     11
     12#include <argp.h>
     13
     14typedef struct {
     15  bool isServer;
     16  bool isClient;
     17  char * host;
     18  char * port;
     19  char * configFile;
     20} CmdLineArgs;
     21
     22typedef struct argp Argp;
     23typedef struct argp_state ArgpState;
     24
    925//! A class for reading commandline arguments into Preferences
    1026class CmdLinePrefsReader {
    1127
    1228 public:
    13    CmdLinePrefsReader();
     29   CmdLinePrefsReader(int argc, char** argv);
    1430   virtual ~CmdLinePrefsReader();
    1531
     32   static error_t parse_opt(int key, char *arg, ArgpState *state);
     33
    1634 private:
     35   CmdLineArgs cmdLineArgs;
    1736
    1837};
Note: See TracChangeset for help on using the changeset viewer.