Example #1
0
FCITX_EXPORT_API
void fcitx_string_map_from_string(FcitxStringMap* map, const char* str, char delim)
{
    fcitx_string_map_clear(map);
    UT_array* list = fcitx_utils_split_string(str, delim);
    utarray_foreach(s, list, char*) {
        UT_array* item = fcitx_utils_split_string(*s, ':');
        if (utarray_len(item) == 2) {
            char* key = *(char**) utarray_eltptr(item, 0);
            char* value = *(char**) utarray_eltptr(item, 1);
            boolean bvalue = strcmp(value, "true") == 0;
            fcitx_string_map_set(map, key, bvalue);
        }
        fcitx_utils_free_string_list(item);
    }
Example #2
0
boolean ProcessOption(FcitxInstance* instance, int argc, char* argv[])
{
    struct option longOptions[] = {
        {"ui", 1, 0, 0},
        {"replace", 0, 0, 0},
        {"enable", 1, 0, 0},
        {"disable", 1, 0, 0},
        {"help", 0, 0, 0},
        {NULL, 0, 0, 0}
    };

    int optionIndex = 0;
    int c;
    char* uiname = NULL;
    boolean runasdaemon = true;
    int             overrideDelay = -1;
    while ((c = getopt_long(argc, argv, "ru:dDs:hv", longOptions, &optionIndex)) != EOF) {
        switch (c) {
        case 0: {
            switch (optionIndex) {
            case 0:
                uiname = strdup(optarg);
                break;
            case 1:
                instance->tryReplace = true;
                break;
            case 2:
                {
                    if (instance->enableList)
                        fcitx_utils_free_string_list(instance->enableList);
                    instance->enableList = fcitx_utils_split_string(optarg, ',');
                }
                break;
            case 3:
                {
                    if (instance->disableList)
                        fcitx_utils_free_string_list(instance->disableList);
                    instance->disableList = fcitx_utils_split_string(optarg, ',');
                }
                break;
            default:
                instance->quietQuit = true;
                Usage();
                return false;
            }
        }
        break;
        case 'r':
            instance->tryReplace = true;
            break;
        case 'u':
            uiname = strdup(optarg);
            break;
        case 'd':
            runasdaemon = true;
            break;
        case 'D':
            runasdaemon = false;
            break;
        case 's':
            overrideDelay = atoi(optarg);
            break;
        case 'h':
            Usage();
            return false;
        case 'v':
            Version();
            return false;
            break;
        default:
            Usage();
            return false;
        }
    }

    if (uiname)
        instance->uiname = uiname;
    else
        instance->uiname = NULL;

    if (runasdaemon)
        fcitx_utils_init_as_daemon();

    if (overrideDelay < 0)
        overrideDelay = instance->config->iDelayStart;

    if (overrideDelay > 0)
        sleep(overrideDelay);

    return true;
}
Example #3
0
boolean FcitxKkcLoadDictionary(FcitxKkc* kkc)
{
    FILE* fp = FcitxXDGGetFileWithPrefix("kkc", "dictionary_list", "r", NULL);
    if (!fp) {
        return false;
    }

    UT_array dictionaries;
    utarray_init(&dictionaries, &dict_icd);

    char *buf = NULL;
    size_t len = 0;
    char *trimmed = NULL;

    while (getline(&buf, &len, fp) != -1) {
        if (trimmed)
            free(trimmed);
        trimmed = fcitx_utils_trim(buf);

        UT_array* list = fcitx_utils_split_string(trimmed, ',');
        do {
            if (utarray_len(list) < 3) {
                break;
            }
            boolean typeFile = false;
            char* path = NULL;
            int mode = 0;
            utarray_foreach(item, list, char*) {
                char* key = *item;
                char* value = strchr(*item, '=');
                if (!value)
                    continue;
                *value = '\0';
                value++;

                if (strcmp(key, "type") == 0) {
                    if (strcmp(value, "file") == 0) {
                        typeFile = true;
                    }
                } else if (strcmp(key, "file") == 0) {
                    path = value;
                } else if (strcmp(key, "mode") == 0) {
                    if (strcmp(value, "readonly") == 0) {
                        mode = 1;
                    } else if (strcmp(value, "readwrite") == 0) {
                        mode = 2;
                    }
                }
            }

            if (mode == 0 || path == NULL || !typeFile) {
                break;
            }

            if (mode == 1) {
                KkcSystemSegmentDictionary* dict = kkc_system_segment_dictionary_new(path, "EUC-JP", NULL);
                if (dict) {
                    utarray_push_back(&dictionaries, &dict);
                }
            } else {
                char* needfree = NULL;
                char* realpath = NULL;
                if (strncmp(path, "$FCITX_CONFIG_DIR/", strlen("$FCITX_CONFIG_DIR/")) == 0) {
                    FcitxXDGGetFileUserWithPrefix("", path + strlen("$FCITX_CONFIG_DIR/"), NULL, &needfree);
                    realpath = needfree;
                } else {
                    realpath = path;
                }
                KkcUserDictionary* userdict = kkc_user_dictionary_new(realpath, NULL);
                if (needfree) {
                    free(needfree);
                }
                if (userdict) {
                    utarray_push_back(&dictionaries, &userdict);
                }
            }
        } while(0);
        fcitx_utils_free_string_list(list);
    }