Improved abbreviation.
authorFlorian Pose <fp@igh-essen.com>
Tue, 22 Jul 2008 14:23:41 +0000
changeset 1127 bd7aef6c310c
parent 1126 b09fd81894cb
child 1128 b69b2c850160
Improved abbreviation.
tool/main.cpp
--- a/tool/main.cpp	Tue Jul 22 14:17:20 2008 +0000
+++ b/tool/main.cpp	Tue Jul 22 14:23:41 2008 +0000
@@ -273,6 +273,13 @@
 
 /****************************************************************************/
 
+bool substrMatch(const string &abb, const string &full)
+{
+    return full.substr(0, abb.length()) == abb;
+}
+    
+/****************************************************************************/
+
 bool abbrevMatch(const string &abb, const string &full)
 {
     unsigned int abbIndex;
@@ -294,13 +301,22 @@
     const Command *cmd;
     list<const Command *> res;
 
-    // find matching commands
+    // find matching commands from beginning of the string
     for (cmd = commands; cmd < cmdEnd; cmd++) {
-        if (abbrevMatch(cmdStr, cmd->name)) {
+        if (substrMatch(cmdStr, cmd->name)) {
             res.push_back(cmd);
         }
     }
 
+    if (!res.size()) { // nothing found
+        // find /any/ matching commands
+        for (cmd = commands; cmd < cmdEnd; cmd++) {
+            if (abbrevMatch(cmdStr, cmd->name)) {
+                res.push_back(cmd);
+            }
+        }
+    }
+
     return res;
 }