Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6397 was 6397, 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  int endIndex = 0;
51  argp_parse(&argp, argc, argv, 0, &endIndex, &(this->cmdLineArgs));
52
53
54  PRINTF(0)("host       = %s\n", cmdLineArgs.host);
55  PRINTF(0)("port       = %s\n", cmdLineArgs.port);
56  PRINTF(0)("configfile = %s\n", cmdLineArgs.configFile);
57  PRINTF(0)("server     = %d\n", cmdLineArgs.isServer);
58  PRINTF(0)("client     = %d\n", cmdLineArgs.isClient);
59
60}
61
62
63/**
64 * standard deconstructor
65*/
66CmdLinePrefsReader::~CmdLinePrefsReader ()
67{
68}
69
70error_t CmdLinePrefsReader::parse_opt(int key, char *arg, ArgpState *state)
71{
72  CmdLineArgs * cmdLineArgs = (CmdLineArgs*)(state->input);
73
74  switch ( key )
75  {
76    case 1000:
77      if ( cmdLineArgs->configFile!=NULL ) delete[] cmdLineArgs->configFile;
78      cmdLineArgs->configFile = new char[strlen(arg)+1];
79      strcpy(cmdLineArgs->configFile, arg);
80      break;
81
82    case 's':
83      cmdLineArgs->isServer = true;
84      break;
85
86    case 'c':
87      cmdLineArgs->isClient = true;
88      break;
89
90    case 'h':
91      if ( cmdLineArgs->host!=NULL ) delete[] cmdLineArgs->host;
92      cmdLineArgs->host = new char[strlen(arg)+1];
93      strcpy(cmdLineArgs->host, arg);
94      break;
95
96    case 'p':
97      if ( cmdLineArgs->port!=NULL ) delete[] cmdLineArgs->port;
98      cmdLineArgs->port = new char[strlen(arg)+1];
99      strcpy(cmdLineArgs->port, arg);
100      break;
101
102    default:
103      return ARGP_ERR_UNKNOWN;
104  }
105
106  return 0;
107}
108
109
110
Note: See TracBrowser for help on using the repository browser.