blob: 12393bd723954bfa0bd7c0eb3fd1bd487a74d8c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include "keywords.h"
#include <libubox/utils.h>
#include <stdlib.h>
#include <string.h>
static const char *const keywords[] = {
#define KW(kw) #kw,
#include "keywords.def"
#undef KW
};
static int compare_keywords(const void *a, const void *b) {
const char *const *ea = a, *const *eb = b;
return strcmp(*ea, *eb);
}
keyword_t lookup_keyword(const char *keyword) {
const char *const *entry = bsearch(
&keyword, keywords, ARRAY_SIZE(keywords), sizeof(const char *),
compare_keywords
);
if (!entry)
return UNKNOWN_KEYWORD;
return (keyword_t) (entry - keywords + 1);
}
|