[6383] | 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 | |
---|
| 20 | using namespace std; |
---|
| 21 | |
---|
[6392] | 22 | static 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 | }; |
---|
[6383] | 30 | |
---|
[6392] | 31 | const char* argp_program_version = "orxonox"; |
---|
| 32 | const char* argp_program_bug_address = "bugs@orxonox.net"; |
---|
| 33 | static char doc[] = "doc goes here"; |
---|
| 34 | static char args_doc[] = "args doc goes here"; |
---|
| 35 | |
---|
| 36 | static Argp argp = { argp_options, CmdLinePrefsReader::parse_opt, args_doc, doc }; |
---|
| 37 | |
---|
[6383] | 38 | /** |
---|
| 39 | * standard constructor |
---|
| 40 | */ |
---|
[6392] | 41 | CmdLinePrefsReader::CmdLinePrefsReader(int argc, char** argv) |
---|
[6383] | 42 | { |
---|
[6392] | 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 | |
---|
[6397] | 50 | int endIndex = 0; |
---|
| 51 | argp_parse(&argp, argc, argv, 0, &endIndex, &(this->cmdLineArgs)); |
---|
[6392] | 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 | |
---|
[6383] | 60 | } |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | /** |
---|
| 64 | * standard deconstructor |
---|
| 65 | */ |
---|
| 66 | CmdLinePrefsReader::~CmdLinePrefsReader () |
---|
| 67 | { |
---|
| 68 | } |
---|
| 69 | |
---|
[6392] | 70 | error_t CmdLinePrefsReader::parse_opt(int key, char *arg, ArgpState *state) |
---|
| 71 | { |
---|
| 72 | CmdLineArgs * cmdLineArgs = (CmdLineArgs*)(state->input); |
---|
[6388] | 73 | |
---|
[6392] | 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 | |
---|