tool/main.cpp
changeset 1127 bd7aef6c310c
parent 1126 b09fd81894cb
child 1128 b69b2c850160
equal deleted inserted replaced
1126:b09fd81894cb 1127:bd7aef6c310c
   271     cerr << binaryBaseName << " " << commandName << " " << helpString;
   271     cerr << binaryBaseName << " " << commandName << " " << helpString;
   272 }
   272 }
   273 
   273 
   274 /****************************************************************************/
   274 /****************************************************************************/
   275 
   275 
       
   276 bool substrMatch(const string &abb, const string &full)
       
   277 {
       
   278     return full.substr(0, abb.length()) == abb;
       
   279 }
       
   280     
       
   281 /****************************************************************************/
       
   282 
   276 bool abbrevMatch(const string &abb, const string &full)
   283 bool abbrevMatch(const string &abb, const string &full)
   277 {
   284 {
   278     unsigned int abbIndex;
   285     unsigned int abbIndex;
   279     size_t fullPos = 0;
   286     size_t fullPos = 0;
   280 
   287 
   292 list<const Command *> getMatchingCommands(const string &cmdStr)
   299 list<const Command *> getMatchingCommands(const string &cmdStr)
   293 {
   300 {
   294     const Command *cmd;
   301     const Command *cmd;
   295     list<const Command *> res;
   302     list<const Command *> res;
   296 
   303 
   297     // find matching commands
   304     // find matching commands from beginning of the string
   298     for (cmd = commands; cmd < cmdEnd; cmd++) {
   305     for (cmd = commands; cmd < cmdEnd; cmd++) {
   299         if (abbrevMatch(cmdStr, cmd->name)) {
   306         if (substrMatch(cmdStr, cmd->name)) {
   300             res.push_back(cmd);
   307             res.push_back(cmd);
       
   308         }
       
   309     }
       
   310 
       
   311     if (!res.size()) { // nothing found
       
   312         // find /any/ matching commands
       
   313         for (cmd = commands; cmd < cmdEnd; cmd++) {
       
   314             if (abbrevMatch(cmdStr, cmd->name)) {
       
   315                 res.push_back(cmd);
       
   316             }
   301         }
   317         }
   302     }
   318     }
   303 
   319 
   304     return res;
   320     return res;
   305 }
   321 }