summaryrefslogtreecommitdiffstats
path: root/parse.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2016-09-04 14:20:41 -0400
committerTavian Barnes <tavianator@tavianator.com>2016-09-04 14:25:10 -0400
commit3cce36f24f02146986c11cd9ef6381e36952f866 (patch)
tree170e16ecf9abb73eb9d2db4e65b67017e65fdeb3 /parse.c
parent69df7d53ed702334a21590e5b91f20bbafab206a (diff)
downloadbfs-3cce36f24f02146986c11cd9ef6381e36952f866.tar.xz
Implement typo detection for literals.
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index e720ba3..b8f79ad 100644
--- a/parse.c
+++ b/parse.c
@@ -10,6 +10,7 @@
*********************************************************************/
#include "bfs.h"
+#include "typo.h"
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
@@ -1499,8 +1500,18 @@ static struct expr *parse_literal(struct parser_state *state) {
}
}
+ const struct table_entry *best = NULL;
+ int best_dist;
+ for (const struct table_entry *entry = parse_table; entry->arg; ++entry) {
+ int dist = typo_distance(arg, entry->arg);
+ if (!best || dist < best_dist) {
+ best = entry;
+ best_dist = dist;
+ }
+ }
+
pretty_error(cmdline->stderr_colors,
- "error: Unknown argument '%s'.\n", arg);
+ "error: Unknown argument '-%s'; did you mean '-%s'?\n", arg, best->arg);
return NULL;
}