- Timestamp:
- Mar 24, 2006, 4:28:02 PM (19 years ago)
- Location:
- branches/preferences/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/preferences/src/lib/parser/cmdline_parser/cmdline_parser.cc
r7241 r7243 57 57 58 58 for ( int i = 1; i<argc; i++ ) 59 args.push_back( argv[i] ); 59 { 60 std::string s = argv[i]; 61 62 if ( s.find( "=" ) == std::string::npos ) 63 { 64 args.push_back(s); 65 } 66 else 67 { 68 std::string op = s; 69 std::string ar = s; 70 op.erase( op.find("=") ); 71 ar.erase( 0, ar.find("=")+1); 72 73 PRINTF(0)("'%s' '%s'\n", op.c_str(), ar.c_str()); 74 args.push_back( op ); 75 args.push_back( ar ); 76 } 77 } 60 78 61 79 int i = 0; … … 76 94 if ( it->numArgs + i >= args.size() ) 77 95 { 78 PRINTF(1)( "%s needs %d arguments!", args[i].c_str(), it->numArgs ); 96 PRINTF(1)( "%s needs %d arguments!\n", args[i].c_str(), it->numArgs ); 97 return false; 79 98 } 80 99 81 std::vector< std::string> argArgs;100 std::vector<MultiType> argArgs; 82 101 83 for ( int j = 0; j <it->numArgs; j++ )102 for ( int j = 1; j <= it->numArgs; j++ ) 84 103 argArgs.push_back( args[i+j] ); 85 104 … … 87 106 return false; 88 107 89 i += it->numArgs ;108 i += it->numArgs + 1; 90 109 91 110 if ( finish ) … … 121 140 arg.erase( 0, 2 ); 122 141 123 if ( arg.find('%') != std::string::npos )142 if ( entry.longOption.find('%') != std::string::npos ) 124 143 { 125 144 //TODO implement bether match algo 126 assert( arg.find('%') == arg.length()-1 ); 127 arg.erase( arg.length()-1, 1 ); 128 return entry.longOption.find( arg ) == 0; 145 assert( entry.longOption.find('%') == entry.longOption.length()-1 ); 146 std::string lo = entry.longOption; 147 lo.erase( lo.length()-1, 1 ); 148 PRINTF(0)("%s %s\n", arg.c_str(), lo.c_str()); 149 return arg.find( lo ) == 0; 129 150 } 130 151 else 131 152 { 132 return entry.longOption == arg;153 return arg.find( entry.longOption ) != std::string::npos; 133 154 } 134 155 } … … 140 161 return false; 141 162 } 142 finish = false;163 finish = arg.length()==2; 143 164 return arg.find(entry.shortOption) != std::string::npos; 144 165 } -
branches/preferences/src/lib/parser/cmdline_parser/cmdline_parser.h
r7241 r7243 12 12 13 13 #include "src/defs/debug.h" 14 #include "src/lib/util/multi_type.h" 14 15 15 16 … … 24 25 typedef std::list<ArgTableEntry> ArgTable; 25 26 26 typedef bool ( ArgParserCallback)( ArgTableEntry, void*, const std::string &, const std::vector<std::string> & );27 typedef bool (*ArgParserCallback)( ArgTableEntry, void*, const std::string &, const std::vector<MultiType> & ); 27 28 28 29 -
branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.cc
r7241 r7243 18 18 #include "cmd_line_prefs_reader.h" 19 19 20 #include "preferences.h" 21 20 22 using namespace std; 21 23 … … 36 38 } 37 39 38 bool CmdLinePrefsReader::callBack( ArgTableEntry entry, void * data, const std::string & arg, const std::vector< std::string> & argArgs )40 bool CmdLinePrefsReader::callBack( ArgTableEntry entry, void * data, const std::string & arg, const std::vector<MultiType> & argArgs ) 39 41 { 42 switch ( entry.id ) 43 { 44 case ID_SET_INI: 45 { 46 std::string section = arg; 47 section.erase( 0, entry.longOption.length()+1 ); 48 std::string key = section; 49 section.erase( section.find(".") ); 50 key.erase( 0, key.find(".")+1 ); 51 //PRINTF(0)("SECTION '%s', KEY '%s'\n", section.c_str(), key.c_str()); 52 53 if ( key == "" || section == "" || argArgs.size() != 1 ) 54 { 55 PRINTF(1)("usage: --set-section.key=value\n"); 56 return false; 57 } 58 59 Preferences::getInstance()->setMultiType( section, key, argArgs[0], true ); 60 break; 61 } 62 default: 63 assert(false); 64 } 65 66 return true; 40 67 } 41 68 … … 43 70 { 44 71 CmdLineParser parser; 72 73 parser.add( ID_SET_INI, "set-%", '\0', 1 ); 74 75 parser.parse( &callBack, NULL, argc, argv ); 45 76 } 46 77 -
branches/preferences/src/lib/parser/preferences/cmd_line_prefs_reader.h
r7241 r7243 12 12 #include "src/lib/parser/cmdline_parser/cmdline_parser.h" 13 13 14 enum 15 { 16 ID_SET_INI = 1 17 }; 18 14 19 //! A class for reading commandline arguments into Preferences 15 20 class CmdLinePrefsReader … … 23 28 24 29 private: 25 static bool callBack( ArgTableEntry entry, void* data, const std::string & arg, const std::vector< std::string> & argArgs );30 static bool callBack( ArgTableEntry entry, void* data, const std::string & arg, const std::vector<MultiType> & argArgs ); 26 31 27 32 }; -
branches/preferences/src/lib/util/preferences.cc
r7234 r7243 157 157 * @param value value 158 158 */ 159 void Preferences::setMultiType(const char* section, const char* name, MultiType& value, bool dontSetModified)159 void Preferences::setMultiType(const char* section, const char* name, const MultiType& value, bool dontSetModified) 160 160 { 161 161 std::list<prefSection>::iterator it = data.begin(); -
branches/preferences/src/lib/util/preferences.h
r7236 r7243 41 41 void setInt(const std::string& section, const std::string& name, int value, bool dontSetModified = false); 42 42 void setFloat(const std::string& section, const std::string& name, float value, bool dontSetModified = false); 43 void setMultiType(const std::string& section, const std::string& name, MultiType& value, bool dontSetModified = false);43 void setMultiType(const std::string& section, const std::string& name, const MultiType& value, bool dontSetModified = false); 44 44 45 45 const std::string getString(const std::string& section, const std::string& name, const std::string& defaultValue); -
branches/preferences/src/orxonox.cc
r7241 r7243 406 406 prefs.parse(argc, argv); 407 407 408 // assert(false); 409 408 410 int i; 409 411 for(i = 1; i < argc; ++i)
Note: See TracChangeset
for help on using the changeset viewer.