Lines Matching +full:cmd +full:- +full:cnt +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0
26 const char *s1 = (*c1)->name, *s2 = (*c2)->name; in levenshtein_compare()
27 int l1 = (*c1)->len; in levenshtein_compare()
28 int l2 = (*c2)->len; in levenshtein_compare()
29 return l1 != l2 ? l1 - l2 : strcmp(s1, s2); in levenshtein_compare()
34 unsigned int i, nr = cmds->cnt + old->cnt; in add_cmd_list()
37 if (nr > cmds->alloc) { in add_cmd_list()
39 if (alloc_nr(cmds->alloc) < nr) in add_cmd_list()
40 cmds->alloc = nr; in add_cmd_list()
42 cmds->alloc = alloc_nr(cmds->alloc); in add_cmd_list()
43 tmp = realloc(cmds->names, cmds->alloc * sizeof(*cmds->names)); in add_cmd_list()
45 return -1; in add_cmd_list()
46 cmds->names = tmp; in add_cmd_list()
48 for (i = 0; i < old->cnt; i++) in add_cmd_list()
49 cmds->names[cmds->cnt++] = old->names[i]; in add_cmd_list()
50 zfree(&old->names); in add_cmd_list()
51 old->cnt = 0; in add_cmd_list()
55 const char *help_unknown_cmd(const char *cmd, struct cmdnames *main_cmds) in help_unknown_cmd() argument
64 load_command_list("perf-", main_cmds, &other_cmds); in help_unknown_cmd()
70 qsort(main_cmds->names, main_cmds->cnt, in help_unknown_cmd()
71 sizeof(main_cmds->names), cmdname_compare); in help_unknown_cmd()
74 if (main_cmds->cnt) { in help_unknown_cmd()
75 /* This reuses cmdname->len for similarity index */ in help_unknown_cmd()
76 for (i = 0; i < main_cmds->cnt; ++i) { in help_unknown_cmd()
77 main_cmds->names[i]->len = in help_unknown_cmd()
78 levenshtein(cmd, main_cmds->names[i]->name, in help_unknown_cmd()
84 qsort(main_cmds->names, main_cmds->cnt, in help_unknown_cmd()
85 sizeof(*main_cmds->names), levenshtein_compare); in help_unknown_cmd()
87 best_similarity = main_cmds->names[0]->len; in help_unknown_cmd()
89 while (n < main_cmds->cnt && best_similarity == main_cmds->names[n]->len) in help_unknown_cmd()
94 const char *assumed = main_cmds->names[0]->name; in help_unknown_cmd()
96 main_cmds->names[0] = NULL; in help_unknown_cmd()
101 cmd, assumed); in help_unknown_cmd()
110 fprintf(stderr, "perf: '%s' is not a perf-command. See 'perf --help'.\n", cmd); in help_unknown_cmd()
112 if (main_cmds->cnt && best_similarity < 6) { in help_unknown_cmd()
117 fprintf(stderr, "\t%s\n", main_cmds->names[i]->name); in help_unknown_cmd()