diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2016-09-04 14:20:41 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2016-09-04 14:25:10 -0400 |
commit | 3cce36f24f02146986c11cd9ef6381e36952f866 (patch) | |
tree | 170e16ecf9abb73eb9d2db4e65b67017e65fdeb3 /parse.c | |
parent | 69df7d53ed702334a21590e5b91f20bbafab206a (diff) | |
download | bfs-3cce36f24f02146986c11cd9ef6381e36952f866.tar.xz |
Implement typo detection for literals.
Diffstat (limited to 'parse.c')
-rw-r--r-- | parse.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -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; } |