summaryrefslogtreecommitdiffstats
path: root/src/util.cc
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2011-11-16 05:38:21 (GMT)
committerNico Weber <nicolasweber@gmx.de>2011-11-16 05:42:34 (GMT)
commitf72a4137f5a9b3ee4001d60888612b22a6a63020 (patch)
tree7901b64ddb1a4def692eb6c151e357367443a720 /src/util.cc
parentd838f8ed07d5cc2550a8b083ad7e866de49fe45d (diff)
downloadNinja-f72a4137f5a9b3ee4001d60888612b22a6a63020.zip
Ninja-f72a4137f5a9b3ee4001d60888612b22a6a63020.tar.gz
Ninja-f72a4137f5a9b3ee4001d60888612b22a6a63020.tar.bz2
Add spelling suggestions for four cases:
1. For targets, when invoking ninja to build a target. 2. For targets, when doing a "query" command. 3. For command names. 4. For the subcommands of the "targets" command. Also change CmdTargets() to call LookupNode() instead of GetNode() -- since the result was checked for NULL, that's probably what was intended here originally.
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index f386a8c..0bbcaf2 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -37,6 +37,8 @@
#include <direct.h> // _mkdir
#endif
+#include "edit_distance.h"
+
void Fatal(const char* msg, ...) {
va_list ap;
fprintf(stderr, "ninja: FATAL: ");
@@ -184,3 +186,26 @@ int64_t GetTimeMillis() {
return ((int64_t)now.tv_sec * 1000) + (now.tv_usec / 1000);
#endif
}
+
+const char* SpellcheckString(const string& text, ...) {
+ const bool kAllowReplacements = true;
+ const int kMaxValidEditDistance = 3;
+
+ va_list ap;
+ va_start(ap, text);
+ const char* correct_spelling;
+
+ int min_distance = kMaxValidEditDistance + 1;
+ const char* result = NULL;
+ while ((correct_spelling = va_arg(ap, const char*))) {
+ int distance = EditDistance(
+ correct_spelling, text, kAllowReplacements, kMaxValidEditDistance);
+ if (distance < min_distance) {
+ min_distance = distance;
+ result = correct_spelling;
+ }
+ }
+
+ va_end(ap);
+ return result;
+}