6 #include <subcmd/help.h> 7 #include "../builtin.h" 13 void *cb __maybe_unused)
15 if (!strcmp(var,
"help.autocorrect"))
23 const struct cmdname *
const *c1 = p1, *
const *c2 = p2;
24 const char *s1 = (*c1)->name, *s2 = (*c2)->name;
27 return l1 != l2 ? l1 - l2 : strcmp(s1, s2);
30 static int add_cmd_list(
struct cmdnames *cmds,
struct cmdnames *old)
32 unsigned int i, nr = cmds->cnt + old->cnt;
35 if (nr > cmds->alloc) {
41 tmp = realloc(cmds->names, cmds->alloc *
sizeof(*cmds->names));
46 for (i = 0; i < old->cnt; i++)
47 cmds->names[cmds->cnt++] = old->names[i];
55 unsigned int i, n = 0, best_similarity = 0;
56 struct cmdnames main_cmds, other_cmds;
58 memset(&main_cmds, 0,
sizeof(main_cmds));
59 memset(&other_cmds, 0,
sizeof(main_cmds));
63 load_command_list(
"perf-", &main_cmds, &other_cmds);
66 fprintf(stderr,
"ERROR: Failed to allocate command list for unknown command.\n");
69 qsort(main_cmds.names, main_cmds.cnt,
70 sizeof(main_cmds.names), cmdname_compare);
75 for (i = 0; i < main_cmds.cnt; ++i)
76 main_cmds.names[i]->len =
77 levenshtein(cmd, main_cmds.names[i]->name, 0, 2, 1, 4);
79 qsort(main_cmds.names, main_cmds.cnt,
82 best_similarity = main_cmds.names[0]->len;
84 while (n < main_cmds.cnt && best_similarity == main_cmds.names[n]->len)
89 const char *assumed = main_cmds.names[0]->name;
91 main_cmds.names[0] = NULL;
92 clean_cmdnames(&main_cmds);
93 fprintf(stderr,
"WARNING: You called a perf program named '%s', " 94 "which does not exist.\n" 95 "Continuing under the assumption that you meant '%s'\n",
98 fprintf(stderr,
"in %0.1f seconds automatically...\n",
105 fprintf(stderr,
"perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd);
107 if (main_cmds.cnt && best_similarity < 6) {
108 fprintf(stderr,
"\nDid you mean %s?\n",
109 n < 2 ?
"this":
"one of these");
111 for (i = 0; i < n; i++)
112 fprintf(stderr,
"\t%s\n", main_cmds.names[i]->name);
static int add_cmd_list(struct cmdnames *cmds, struct cmdnames *old)
int perf_config_int(int *dest, const char *name, const char *value)
x86 movsq based memset() in arch/x86/lib/memset_64.S") MEMSET_FN(memset_erms
int levenshtein(const char *string1, const char *string2, int w, int s, int a, int d)
static int levenshtein_compare(const void *p1, const void *p2)
static int perf_unknown_cmd_config(const char *var, const char *value, void *cb __maybe_unused)
const char * help_unknown_cmd(const char *cmd)
int perf_config(config_fn_t fn, void *data)