コード例 #1
0
ファイル: jsonconf.c プロジェクト: stm2/server
static void json_keyword(cJSON *json, struct locale *lang) {
    cJSON *child;
    if (json->type != cJSON_Object) {
        log_error("keywords for locale `%s` not a json object: %d", locale_name(lang), json->type);
        return;
    }
    for (child = json->child; child; child = child->next) {
        keyword_t kwd = findkeyword(child->string);
        if (kwd != NOKEYWORD) {
            if (child->type == cJSON_String) {
                init_keyword(lang, kwd, child->valuestring);
                locale_setstring(lang, mkname("keyword", keywords[kwd]), child->valuestring);
            }
            else if (child->type == cJSON_Array) {
                cJSON *entry;
                for (entry = child->child; entry; entry = entry->next) {
                    init_keyword(lang, kwd, entry->valuestring);
                    if (entry == child->child) {
                        locale_setstring(lang, mkname("keyword", keywords[kwd]), entry->valuestring);
                    }
                }
            }
            else {
                log_error("invalid type %d for keyword `%s`", child->type, child->string);
            }
        }
        else {
            log_error("unknown keyword `%s` for locale `%s`", child->string, locale_name(lang));
        }
    }
}
コード例 #2
0
ファイル: order.test.c プロジェクト: Xolgrim/server
static void test_parse_order(CuTest *tc) {
    char cmd[32];
    order *ord;
    struct locale * lang;

    test_cleanup();
    lang = get_or_create_locale("en");

    locale_setstring(lang, "keyword::move", "MOVE");
    init_keyword(lang, K_MOVE, "MOVE");
    ord = parse_order("MOVE NORTH", lang);
    CuAssertPtrNotNull(tc, ord);
    CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
    CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));

    CuAssertIntEquals(tc, K_MOVE, init_order(ord));
    CuAssertStrEquals(tc, "NORTH", getstrtoken());
    free_order(ord);
    test_cleanup();
}