コード例 #1
0
ファイル: main.c プロジェクト: brunobottazzini/soletta
static struct sol_str_slice
get_node_name(const struct sol_fbp_node *node)
{
    static const struct sol_str_table_ptr component_to_glyph[] = {
        SOL_STR_TABLE_PTR_ITEM("timer", "🕐 Timer"),
        SOL_STR_TABLE_PTR_ITEM("boolean/and", "∧ And"),
        SOL_STR_TABLE_PTR_ITEM("boolean/or", "∨ Or"),
        SOL_STR_TABLE_PTR_ITEM("boolean/not", "¬ Not"),
        SOL_STR_TABLE_PTR_ITEM("boolean/xor", "⊕ Xor"),
        { }
    };
    const char *glyph;

    if (sol_str_table_ptr_lookup(component_to_glyph, node->component, &glyph))
        return sol_str_slice_from_str(glyph);

    return node->name;
}
コード例 #2
0
SOL_API struct sol_message_digest *
sol_message_digest_new(const struct sol_message_digest_config *config)
{
    const struct sol_message_digest_info *dinfo;
    struct sol_message_digest *handle;
    struct sol_message_digest_common_new_params params;
    struct sol_str_slice algorithm;

    errno = EINVAL;
    SOL_NULL_CHECK(config, NULL);
    SOL_NULL_CHECK(config->on_digest_ready, NULL);
    SOL_NULL_CHECK(config->algorithm, NULL);

#ifndef SOL_NO_API_VERSION
    if (config->api_version != SOL_MESSAGE_DIGEST_CONFIG_API_VERSION) {
        SOL_WRN("sol_message_digest_config->api_version=%" PRIu16 ", "
            "expected version is %" PRIu16 ".",
            config->api_version, SOL_MESSAGE_DIGEST_CONFIG_API_VERSION);
        return NULL;
    }
#endif

    algorithm = sol_str_slice_from_str(config->algorithm);
    if (!sol_str_table_ptr_lookup(_available_digests, algorithm, &dinfo)) {
        SOL_WRN("failed to get digest algorithm \"%s\".",
            config->algorithm);
        return NULL;
    }

    params.config = config;
    params.ops = &dinfo->ops;
    params.context_size = dinfo->context_size;
    params.digest_size = dinfo->digest_size;
    params.context_template = NULL;

    handle = sol_message_digest_common_new(params);
    SOL_NULL_CHECK(handle, NULL);

    dinfo->init(handle);

    return handle;
}