- Timestamp:
- Mar 27, 2006, 8:01:11 PM (19 years ago)
- Location:
- branches/preferences/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.cc
r7250 r7251 21 21 22 22 using namespace std; 23 24 RegistredArgs CmdLinePrefsReader::regArgs; 23 25 24 26 /** … … 64 66 cbd->iniEntries.back().key = key; 65 67 cbd->iniEntries.back().value = argArgs[0].getString(); 66 break;68 return true; 67 69 } 68 70 case ID_HELP: 69 71 cbd->parser->showHelp(); 70 break; 71 default: 72 assert(false); 72 return true; 73 } 74 75 if ( entry.id >= ID_LAST && entry.id - ID_LAST < regArgs.size() ) 76 { 77 if ( regArgs[entry.id - ID_LAST].value == "%arg%" ) 78 { 79 assert( argArgs.size() == 1 ); 80 81 cbd->iniEntries.push_back( IniEntry() ); 82 cbd->iniEntries.back().section = regArgs[entry.id - ID_LAST].section; 83 cbd->iniEntries.back().key = regArgs[entry.id - ID_LAST].key; 84 cbd->iniEntries.back().value = argArgs[0].getString(); 85 } 86 else 87 { 88 cbd->iniEntries.push_back( IniEntry() ); 89 cbd->iniEntries.back().section = regArgs[entry.id - ID_LAST].section; 90 cbd->iniEntries.back().key = regArgs[entry.id - ID_LAST].key; 91 cbd->iniEntries.back().value = regArgs[entry.id - ID_LAST].value; 92 } 93 } 94 else 95 { 96 assert(false); 73 97 } 74 98 … … 81 105 CmdLineParser parser; 82 106 83 parser.add( ID_HELP, "help", 'h', 0, "", "Show this help"); 84 parser.add( 99, "port", 'p', 0, "", "dont know"); 107 parser.add( ID_HELP, "help", 'h', 0, "", "Shows this help"); 108 109 for ( int i = 0; i<regArgs.size(); i++ ) 110 { 111 if ( regArgs[i].value == "%arg%" ) 112 { 113 parser.add( ID_LAST + i, regArgs[i].longOption, regArgs[i].shortOption, 1, regArgs[i].argName, regArgs[i].help ); 114 } 115 else 116 { 117 parser.add( ID_LAST + i, regArgs[i].longOption, regArgs[i].shortOption, 0, "", regArgs[i].help ); 118 } 119 } 85 120 86 121 parser.add( ID_SET_INI, "set-%", '\0', 1, "value", "Override a configuration element." ); … … 90 125 cbd.parser = &parser; 91 126 92 parser.parse( &callBack, &cbd, argc, argv ); 127 if ( parser.parse( &callBack, &cbd, argc, argv ) ) 128 { 129 std::list<IniEntry>::const_iterator it; 130 for ( it = cbd.iniEntries.begin(); it != cbd.iniEntries.end(); it++ ) 131 { 132 Preferences::getInstance()->setString( it->section, it->key, it->value, true); 133 } 134 } 135 else 136 { 137 exit(EXIT_FAILURE); 138 } 139 140 return true; 141 } 142 143 bool CmdLinePrefsReader::registerArgument( const char shortOption, const std::string & longOption, const std::string & section, const std::string & key, const std::string & help, const std::string & argName, const std::string & value ) 144 { 145 RegistredArgument arg; 146 147 arg.longOption = longOption; 148 arg.shortOption = shortOption; 149 arg.value = value; 150 arg.help = help; 151 arg.argName = argName; 152 arg.section = section; 153 arg.key = key; 154 155 regArgs.push_back( arg ); 93 156 } 94 157 -
branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.h
r7250 r7251 25 25 }; 26 26 27 struct RegistredArgument 28 { 29 char shortOption; 30 std::string longOption; 31 std::string value; 32 std::string help; 33 std::string argName; 34 std::string section; 35 std::string key; 36 }; 37 38 typedef std::vector<RegistredArgument> RegistredArgs; 39 27 40 enum 28 41 { 29 42 ID_SET_INI = 1, 30 ID_HELP 43 ID_HELP, 44 ID_LAST 31 45 }; 46 47 #define REGISTER_ARG_FLAG(shortOption,longOption,section,key,description,value) bool _ARGVAR_##shortOption##_##longOption = CmdLinePrefsReader::registerArgument(#shortOption[0],#longOption,section,key,description,"",value) 48 49 #define REGISTER_ARG_ARG(shortOption,longOption,section,key,description,argname) bool _ARGVAR_##shortOption##_##longOption = CmdLinePrefsReader::registerArgument(#shortOption[0],#longOption,section,key,description,argname) 32 50 33 51 //! A class for reading commandline arguments into Preferences … … 41 59 bool parse(int argc, char** argv); 42 60 61 static bool registerArgument( const char shortOption, const std::string & longOption, const std::string & section, const std::string & key, const std::string & help, const std::string & argName = "", const std::string & value = "%arg%" ); 62 63 static bool asdf; 64 43 65 private: 44 66 static bool callBack( ArgTableEntry entry, void* data, const std::string & arg, const std::vector<MultiType> & argArgs ); 67 68 static RegistredArgs regArgs; 45 69 46 70 }; -
branches/preferences/src/orxonox.cc
r7248 r7251 67 67 68 68 SHELL_COMMAND(restart, Orxonox, restart); 69 70 REGISTER_ARG_FLAG( s, server, "game", "isServer", "Start Orxonox as Game Server", "1" ); 71 REGISTER_ARG_ARG( p, port, "game", "port", "Port to use", "port" ); 69 72 70 73 /** … … 405 408 prefs.parse(argc, argv); 406 409 407 //Preferences::getInstance()->debug();408 409 410 int i; 410 411 for(i = 1; i < argc; ++i)
Note: See TracChangeset
for help on using the changeset viewer.