Changeset 8316 in orxonox.OLD for trunk/src/lib/parser
- Timestamp:
- Jun 11, 2006, 1:57:27 PM (19 years ago)
- Location:
- trunk/src/lib/parser
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/parser/cmdline_parser/cmdline_parser.cc
r7319 r8316 52 52 else 53 53 argTable.push_front( entry ); 54 return true; 54 55 } 55 56 … … 70 71 if ( s.length() > 2 && s[0] == '-' && s[1] != '-' ) 71 72 { 72 for ( int j = 1; j < s.length(); j++ )73 for (unsigned int j = 1; j < s.length(); j++ ) 73 74 { 74 75 std::string t = "-"; … … 95 96 } 96 97 97 int i = 0;98 unsigned int i = 0; 98 99 99 100 ArgTable::iterator it; … … 110 111 found = true; 111 112 112 int posArgs = 1;113 unsigned int posArgs = 1; 113 114 114 115 while ( i + posArgs < args.size() ) … … 130 131 std::vector<MultiType> argArgs; 131 132 132 for ( int j = 1; j <= it->numArgs; j++ )133 for (unsigned int j = 1; j <= it->numArgs; j++ ) 133 134 argArgs.push_back( args[i+j] ); 134 135 … … 219 220 assert( it->numArgs == substr.size() ); 220 221 221 for ( int i = 0; i<it->numArgs; i++ )222 for (unsigned int i = 0; i<it->numArgs; i++ ) 222 223 { 223 224 args += " [" + substr[i] + "]"; … … 251 252 output.reverse(); 252 253 253 int maxShort = 0;254 int maxLong = 0;254 unsigned int maxShort = 0; 255 unsigned int maxLong = 0; 255 256 256 257 std::list<std::vector<std::string> >::const_iterator it; … … 269 270 printf("%s ", (*it)[0].c_str()); 270 271 271 for ( int i = 0; i<maxShort-(*it)[0].length(); i++ )272 for (unsigned int i = 0; i<maxShort-(*it)[0].length(); i++ ) 272 273 printf(" "); 273 274 274 275 printf("%s ", (*it)[1].c_str()); 275 276 276 for ( int i = 0; i<maxLong-(*it)[1].length(); i++ )277 for (unsigned int i = 0; i<maxLong-(*it)[1].length(); i++ ) 277 278 printf(" "); 278 279 -
trunk/src/lib/parser/cmdline_parser/cmdline_parser.h
r7256 r8316 17 17 struct ArgTableEntry 18 18 { 19 intid;20 std::string longOption;21 char shortOption;22 intnumArgs;23 std::string argNames;24 std::string help;19 unsigned int id; 20 std::string longOption; 21 char shortOption; 22 unsigned int numArgs; 23 std::string argNames; 24 std::string help; 25 25 }; 26 26 … … 36 36 CmdLineParser(); 37 37 virtual ~CmdLineParser(); 38 38 39 39 bool add( int id, const std::string& longOption, char shortOption, int numArgs, const std::string & argNames, const std::string& help, bool back=false ); 40 40 41 41 bool parse( ArgParserCallback cb, void* data, int argc, char** argv ); 42 42 43 43 void showHelp(); 44 44 45 45 private: 46 46 ArgTable argTable; 47 47 std::string exeName; 48 48 49 49 inline bool matches( ArgTableEntry entry, std::string arg, bool & finish ); 50 50 -
trunk/src/lib/parser/preferences/cmd_line_prefs_reader.cc
r7261 r8316 43 43 { 44 44 CallbackData * cbd = (CallbackData *)data; 45 45 46 46 switch ( entry.id ) 47 47 { … … 54 54 key.erase( 0, key.find(".")+1 ); 55 55 //PRINTF(0)("SECTION '%s', KEY '%s'\n", section.c_str(), key.c_str()); 56 56 57 57 if ( key == "" || section == "" || argArgs.size() != 1 ) 58 58 { … … 60 60 return false; 61 61 } 62 62 63 63 //Preferences::getInstance()->setMultiType( section, key, argArgs[0], true ); 64 64 cbd->iniEntries.push_back( IniEntry() ); … … 72 72 return true; 73 73 } 74 75 if ( entry.id >= ID_PREFS && entry.id - ID_PREFS < regArgs.size())74 75 if ( entry.id >= ID_PREFS && entry.id < regArgs.size() + ID_PREFS) 76 76 { 77 77 if ( regArgs[entry.id - ID_PREFS].value == "%arg%" ) 78 78 { 79 79 assert( argArgs.size() == 1 ); 80 80 81 81 cbd->iniEntries.push_back( IniEntry() ); 82 82 cbd->iniEntries.back().section = regArgs[entry.id - ID_PREFS].section; … … 96 96 assert(false); 97 97 } 98 98 99 99 return true; 100 100 } … … 104 104 { 105 105 CmdLineParser parser; 106 106 107 107 parser.add( ID_HELP, "help", 'h', 0, "", "Shows this help and exits"); 108 109 for ( int i = 0; i<regArgs.size(); i++ )108 109 for (unsigned int i = 0; i<regArgs.size(); i++ ) 110 110 { 111 111 if ( regArgs[i].value == "%arg%" ) … … 118 118 } 119 119 } 120 120 121 121 parser.add( ID_SET_INI, "set-%", '\0', 1, "value", "Override a configuration element." ); 122 122 123 123 CallbackData cbd; 124 124 125 125 cbd.parser = &parser; 126 126 127 127 if ( parser.parse( &callBack, &cbd, argc, argv ) ) 128 128 { … … 137 137 exit(EXIT_FAILURE); 138 138 } 139 139 140 140 return true; 141 141 } … … 144 144 { 145 145 RegistredArgument arg; 146 146 147 147 arg.longOption = longOption; 148 148 while ( arg.longOption.find("_") != std::string::npos ) … … 158 158 arg.section = section; 159 159 arg.key = key; 160 160 161 161 regArgs.push_back( arg ); 162 return true; 162 163 } 163 164
Note: See TracChangeset
for help on using the changeset viewer.