Skip to content

Commit 20f77ef

Browse files
committed
Add support for shortened mnemonic elements
1 parent f277405 commit 20f77ef

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/wordlist.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ static int bstrcmp(const void *l, const void *r)
66
return strcmp(l, (*(const char **)r));
77
}
88

9+
static int bstr4cmp(const void *l, const void *r) {
10+
return strncmp(l, (*(const char **)r), 4);
11+
}
12+
913
/* https://graphics.stanford.edu/~seander/bithacks.html#IntegerLogObvious */
1014
static int get_bits(size_t n)
1115
{
@@ -72,12 +76,12 @@ size_t wordlist_lookup_word(const struct words *w, const char *word)
7276
const size_t size = sizeof(const char *);
7377
const char **found = NULL;
7478

75-
if (w->sorted)
76-
found = (const char **)bsearch(word, w->indices, w->len, size, bstrcmp);
77-
else {
79+
if (w->sorted) {
80+
found = (const char **)bsearch(word, w->indices, w->len, size, bstr4cmp);
81+
} else {
7882
size_t i;
7983
for (i = 0; i < w->len && !found; ++i)
80-
if (!strcmp(word, w->indices[i]))
84+
if (!strncmp(word, w->indices[i], 4))
8185
found = w->indices + i;
8286
}
8387
return found ? found - w->indices + 1u : 0u;

0 commit comments

Comments
 (0)