Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.cc @ 6398

Last change on this file since 6398 was 6398, checked in by rennerc, 18 years ago
File size: 2.8 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Christoph Renner
13   co-programmer: ...
14*/
15
16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
17
18#include "cmd_line_prefs_reader.h"
19
20using namespace std;
21
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 };
37
38/**
39 * standard constructor
40*/
41CmdLinePrefsReader::CmdLinePrefsReader(int argc, char** argv)
42{
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((const struct argp *)&argp, (int)argc, (char**)argv, (unsigned)NULL, (int*)NULL, (void*)&(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
59}
60
61
62/**
63 * standard deconstructor
64*/
65CmdLinePrefsReader::~CmdLinePrefsReader ()
66{
67}
68
69error_t CmdLinePrefsReader::parse_opt(int key, char *arg, ArgpState *state)
70{
71  CmdLineArgs * cmdLineArgs = (CmdLineArgs*)(state->input);
72
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
Note: See TracBrowser for help on using the repository browser.