char * match(char * s, hash_table_t * ht, char a[][BUFSIZ], int * p) { uint32_t dist, mindst, minidx, i; mindst = INT_MAX; minidx = 0; for (i = 0; i < NUMA; i++) { dist = string_distance(s, a[i]); if (dist < mindst) { mindst = dist; minidx = i; } } hkey_t k; k.size = strlen(a[minidx])+1; k.key = a[minidx]; void * addr = hash_table_lookup(ht, k); if (addr == NULL) { printf("match_str: lookup failure\n"); exit(EXIT_FAILURE); } key_val_t kv = *(key_val_t*)addr; char * correct = kv.val.val; double len = MIN((double)strlen(s), (double)strlen(a[minidx])); double num = MAX(0.0, len - (double)mindst); double den = MAX((double)strlen(s), (double)strlen(a[minidx])); double match = num / den; uint32_t md = (int)(100 * match * match); *p = md; /* printf("matched %s (confidence: %d%%)\n", correct, md); */ return correct; }
int show_cmd_help(struct fio_option *options, const char *name) { struct fio_option *o, *closest; unsigned int best_dist; int found = 0; int show_all = 0; if (!name || !strcmp(name, "all")) show_all = 1; closest = NULL; best_dist = -1; for (o = &options[0]; o->name; o++) { int match = 0; if (o->type == FIO_OPT_DEPRECATED) continue; if (name) { if (!strcmp(name, o->name) || (o->alias && !strcmp(name, o->alias))) match = 1; else { unsigned int dist; dist = string_distance(name, o->name); if (dist < best_dist) { best_dist = dist; closest = o; } } } if (show_all || match) { found = 1; if (match) printf("%24s: %s\n", o->name, o->help); if (show_all) { if (!o->parent) print_option(o); continue; } } if (!match) continue; show_option_help(o, stdout); } if (found) return 0; printf("No such command: %s", name); if (closest) { printf(" - showing closest match\n"); printf("%20s: %s\n", closest->name, closest->help); show_option_help(closest, stdout); } else printf("\n"); return 1; }