2014-06-16 03:34:39 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/config.h>
|
|
|
|
#include "keyword.h"
|
|
|
|
|
2015-09-12 17:06:47 +02:00
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/umlaut.h>
|
|
|
|
#include <util/log.h>
|
2017-12-30 19:49:21 +01:00
|
|
|
#include <util/strings.h>
|
2014-06-16 03:34:39 +02:00
|
|
|
|
|
|
|
#include <critbit.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2014-08-14 09:57:05 +02:00
|
|
|
const char * keyword(keyword_t kwd)
|
2014-06-16 03:34:39 +02:00
|
|
|
{
|
2017-02-18 21:15:14 +01:00
|
|
|
static char result[32]; /* FIXME: static return value */
|
2018-09-15 18:35:27 +02:00
|
|
|
if (kwd==NOKEYWORD || keywords[kwd] == NULL) {
|
2016-11-14 02:21:49 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-14 09:57:05 +02:00
|
|
|
if (!result[0]) {
|
|
|
|
strcpy(result, "keyword::");
|
|
|
|
}
|
2017-12-30 19:49:21 +01:00
|
|
|
str_strlcpy(result + 9, keywords[kwd], sizeof(result) - 9);
|
2014-08-14 09:57:05 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char * keyword_key(int kwd) {
|
|
|
|
assert(kwd < MAXKEYWORDS && kwd >= 0);
|
|
|
|
return keyword((keyword_t)kwd);
|
2014-06-16 03:34:39 +02:00
|
|
|
}
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str) {
|
|
|
|
void **tokens = get_translations(lang, UT_KEYWORDS);
|
2014-06-16 19:32:23 +02:00
|
|
|
struct critbit_tree **cb = (critbit_tree **)tokens;
|
|
|
|
add_translation(cb, str, (int)kwd);
|
2014-06-16 17:01:59 +02:00
|
|
|
}
|
|
|
|
|
2014-06-21 08:59:04 +02:00
|
|
|
void init_keywords(const struct locale *lang) {
|
|
|
|
init_translations(lang, UT_KEYWORDS, keyword_key, MAXKEYWORDS);
|
|
|
|
}
|
|
|
|
|
2014-06-16 17:01:59 +02:00
|
|
|
keyword_t findkeyword(const char *s) {
|
|
|
|
int i;
|
2014-08-14 09:57:05 +02:00
|
|
|
for (i = 0; i != MAXKEYWORDS; ++i) {
|
2018-09-15 18:35:27 +02:00
|
|
|
if (keywords[i] && (strcmp(s, keywords[i]) == 0)) {
|
2014-06-16 17:01:59 +02:00
|
|
|
return (keyword_t)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NOKEYWORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyword_t get_keyword(const char *s, const struct locale *lang) {
|
2014-06-16 03:34:39 +02:00
|
|
|
keyword_t result = NOKEYWORD;
|
|
|
|
|
|
|
|
assert(lang);
|
|
|
|
assert(s);
|
|
|
|
while (*s == '@') ++s;
|
|
|
|
|
|
|
|
if (*s) {
|
2018-12-09 03:42:08 +01:00
|
|
|
char buffer[64];
|
2014-06-16 03:34:39 +02:00
|
|
|
char *str = transliterate(buffer, sizeof(buffer) - sizeof(int), s);
|
|
|
|
|
|
|
|
if (str) {
|
|
|
|
int i;
|
2015-07-12 10:35:09 +02:00
|
|
|
void *match;
|
2014-06-16 03:34:39 +02:00
|
|
|
void **tokens = get_translations(lang, UT_KEYWORDS);
|
|
|
|
critbit_tree *cb = (critbit_tree *)*tokens;
|
2014-06-16 20:30:23 +02:00
|
|
|
if (cb && cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
|
2014-06-16 03:34:39 +02:00
|
|
|
cb_get_kv(match, &i, sizeof(int));
|
|
|
|
result = (keyword_t)i;
|
|
|
|
return keyword_disabled(result) ? NOKEYWORD : result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NOKEYWORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool disabled_kwd[MAXKEYWORDS];
|
|
|
|
|
|
|
|
void enable_keyword(keyword_t kwd, bool enabled) {
|
2014-08-14 09:57:05 +02:00
|
|
|
assert(kwd < MAXKEYWORDS);
|
2014-06-16 03:34:39 +02:00
|
|
|
disabled_kwd[kwd] = !enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool keyword_disabled(keyword_t kwd) {
|
2014-08-14 09:57:05 +02:00
|
|
|
assert(kwd < MAXKEYWORDS);
|
2014-06-16 03:34:39 +02:00
|
|
|
return disabled_kwd[kwd];
|
|
|
|
}
|
|
|
|
|
2018-12-02 15:51:35 +01:00
|
|
|
const char *keyword_name(keyword_t kwd, const struct locale *lang)
|
|
|
|
{
|
|
|
|
return LOC(lang, mkname("keyword", keywords[kwd]));
|
|
|
|
}
|
|
|
|
|
2014-06-16 03:34:39 +02:00
|
|
|
const char *keywords[MAXKEYWORDS] = {
|
2014-08-14 09:57:05 +02:00
|
|
|
"//",
|
|
|
|
"banner",
|
|
|
|
"work",
|
|
|
|
"attack",
|
|
|
|
"steal",
|
2018-09-15 18:35:27 +02:00
|
|
|
NULL,
|
2014-08-14 09:57:05 +02:00
|
|
|
"name",
|
|
|
|
"use",
|
|
|
|
"describe",
|
|
|
|
"enter",
|
|
|
|
"guard",
|
|
|
|
"message",
|
|
|
|
"end",
|
|
|
|
"ride",
|
|
|
|
"number",
|
|
|
|
"follow",
|
|
|
|
"research",
|
|
|
|
"give",
|
|
|
|
"help",
|
2014-10-20 17:13:32 +02:00
|
|
|
"combat",
|
2014-08-14 09:57:05 +02:00
|
|
|
"ready",
|
|
|
|
"buy",
|
|
|
|
"contact",
|
|
|
|
"teach",
|
|
|
|
"study",
|
|
|
|
"make",
|
2014-08-16 03:07:37 +02:00
|
|
|
"maketemp",
|
2014-08-14 09:57:05 +02:00
|
|
|
"move",
|
|
|
|
"password",
|
|
|
|
"recruit",
|
|
|
|
"reserve",
|
|
|
|
"route",
|
|
|
|
"sabotage",
|
|
|
|
"option",
|
|
|
|
"spy",
|
|
|
|
"quit",
|
|
|
|
"hide",
|
|
|
|
"carry",
|
|
|
|
"tax",
|
|
|
|
"entertain",
|
|
|
|
"sell",
|
|
|
|
"leave",
|
|
|
|
"forget",
|
|
|
|
"cast",
|
|
|
|
"show",
|
|
|
|
"destroy",
|
2017-06-24 13:36:18 +02:00
|
|
|
"plant",
|
2014-08-14 09:57:05 +02:00
|
|
|
"grow",
|
|
|
|
"default",
|
|
|
|
"origin",
|
|
|
|
"email",
|
|
|
|
"piracy",
|
|
|
|
"group",
|
|
|
|
"sort",
|
|
|
|
"prefix",
|
|
|
|
"alliance",
|
|
|
|
"claim",
|
|
|
|
"promote",
|
|
|
|
"pay",
|
2014-09-15 15:51:40 +02:00
|
|
|
"loot",
|
2018-07-05 20:06:32 +02:00
|
|
|
"autostudy",
|
2014-06-16 03:34:39 +02:00
|
|
|
};
|
|
|
|
|