Changeset 6392 in orxonox.OLD for branches/preferences/src/lib/parser
- Timestamp:
- Jan 3, 2006, 11:29:18 AM (19 years ago)
- 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 20 20 using namespace std; 21 21 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 }; 30 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 }; 22 37 23 38 /** 24 39 * standard constructor 25 40 */ 26 CmdLinePrefsReader::CmdLinePrefsReader ()41 CmdLinePrefsReader::CmdLinePrefsReader(int argc, char** argv) 27 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(&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 28 59 } 29 60 … … 36 67 } 37 68 69 error_t CmdLinePrefsReader::parse_opt(int key, char *arg, ArgpState *state) 70 { 71 CmdLineArgs * cmdLineArgs = (CmdLineArgs*)(state->input); 38 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 -
branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.h
r6388 r6392 7 7 #define _CMD_LINE_PREFS_READER_H 8 8 9 #include "stdincl.h" 10 #include "debug.h" 11 12 #include <argp.h> 13 14 typedef struct { 15 bool isServer; 16 bool isClient; 17 char * host; 18 char * port; 19 char * configFile; 20 } CmdLineArgs; 21 22 typedef struct argp Argp; 23 typedef struct argp_state ArgpState; 24 9 25 //! A class for reading commandline arguments into Preferences 10 26 class CmdLinePrefsReader { 11 27 12 28 public: 13 CmdLinePrefsReader( );29 CmdLinePrefsReader(int argc, char** argv); 14 30 virtual ~CmdLinePrefsReader(); 15 31 32 static error_t parse_opt(int key, char *arg, ArgpState *state); 33 16 34 private: 35 CmdLineArgs cmdLineArgs; 17 36 18 37 };
Note: See TracChangeset
for help on using the changeset viewer.