static void system_dictionary_tests_test_load (SystemDictionaryTests* self) {
	gchar* srcdir = NULL;
	const gchar* _tmp2_ = NULL;
	gchar* _tmp3_ = NULL;
	GError * _inner_error_ = NULL;
#line 22 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	g_return_if_fail (self != NULL);
#line 198 "system-dictionary.c"
	{
		KkcSystemSegmentDictionary* _tmp0_ = NULL;
		KkcSystemSegmentDictionary* _tmp1_ = NULL;
#line 24 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp0_ = kkc_system_segment_dictionary_new ("nonexistent-system-segment-dictionary", "EUC-JP", &_inner_error_);
#line 24 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp1_ = _tmp0_;
#line 24 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_object_unref0 (_tmp1_);
#line 24 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 210 "system-dictionary.c"
			goto __catch1_g_error;
		}
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
#line 23 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		e = _inner_error_;
#line 23 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_inner_error_ = NULL;
#line 23 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_error_free0 (e);
#line 224 "system-dictionary.c"
	}
	__finally1:
#line 23 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 23 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 23 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_clear_error (&_inner_error_);
#line 23 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		return;
#line 235 "system-dictionary.c"
	}
#line 29 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_tmp2_ = g_getenv ("srcdir");
#line 29 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_tmp3_ = g_strdup (_tmp2_);
#line 29 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	srcdir = _tmp3_;
#line 30 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_vala_assert (srcdir != NULL, "srcdir != null");
#line 245 "system-dictionary.c"
	{
		gchar* _tmp4_ = NULL;
		gchar* _tmp5_ = NULL;
		KkcSystemSegmentDictionary* _tmp6_ = NULL;
		KkcSystemSegmentDictionary* _tmp7_ = NULL;
#line 33 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp4_ = g_build_filename (srcdir, "system-segment-dictionary", NULL);
#line 33 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp5_ = _tmp4_;
#line 33 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp6_ = kkc_system_segment_dictionary_new (_tmp5_, "unknown encoding", &_inner_error_);
#line 33 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp7_ = _tmp6_;
#line 33 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_object_unref0 (_tmp7_);
#line 33 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (_tmp5_);
#line 33 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 265 "system-dictionary.c"
			goto __catch2_g_error;
		}
#line 36 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_assert_not_reached ();
#line 270 "system-dictionary.c"
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* e = NULL;
#line 32 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		e = _inner_error_;
#line 32 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_inner_error_ = NULL;
#line 32 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_error_free0 (e);
#line 282 "system-dictionary.c"
	}
	__finally2:
#line 32 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 32 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (srcdir);
#line 32 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 32 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_clear_error (&_inner_error_);
#line 32 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		return;
#line 295 "system-dictionary.c"
	}
	{
		gchar* _tmp8_ = NULL;
		gchar* _tmp9_ = NULL;
		KkcSystemSegmentDictionary* _tmp10_ = NULL;
		KkcSystemSegmentDictionary* _tmp11_ = NULL;
#line 41 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp8_ = g_build_filename (srcdir, "system-segment-dictionary-bad1", NULL);
#line 41 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp9_ = _tmp8_;
#line 41 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp10_ = kkc_system_segment_dictionary_new (_tmp9_, "EUC-JP", &_inner_error_);
#line 41 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp11_ = _tmp10_;
#line 41 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_object_unref0 (_tmp11_);
#line 41 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (_tmp9_);
#line 41 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 316 "system-dictionary.c"
			goto __catch3_g_error;
		}
#line 43 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_assert_not_reached ();
#line 321 "system-dictionary.c"
	}
	goto __finally3;
	__catch3_g_error:
	{
		GError* e = NULL;
#line 40 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		e = _inner_error_;
#line 40 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_inner_error_ = NULL;
#line 40 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_error_free0 (e);
#line 333 "system-dictionary.c"
	}
	__finally3:
#line 40 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 40 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (srcdir);
#line 40 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 40 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_clear_error (&_inner_error_);
#line 40 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		return;
#line 346 "system-dictionary.c"
	}
	{
		gchar* _tmp12_ = NULL;
		gchar* _tmp13_ = NULL;
		KkcSystemSegmentDictionary* _tmp14_ = NULL;
		KkcSystemSegmentDictionary* _tmp15_ = NULL;
#line 48 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp12_ = g_build_filename (srcdir, "system-segment-dictionary-bad2", NULL);
#line 48 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp13_ = _tmp12_;
#line 48 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp14_ = kkc_system_segment_dictionary_new (_tmp13_, "EUC-JP", &_inner_error_);
#line 48 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp15_ = _tmp14_;
#line 48 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_object_unref0 (_tmp15_);
#line 48 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (_tmp13_);
#line 48 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 367 "system-dictionary.c"
			goto __catch4_g_error;
		}
#line 50 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_assert_not_reached ();
#line 372 "system-dictionary.c"
	}
	goto __finally4;
	__catch4_g_error:
	{
		GError* e = NULL;
#line 47 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		e = _inner_error_;
#line 47 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_inner_error_ = NULL;
#line 47 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_error_free0 (e);
#line 384 "system-dictionary.c"
	}
	__finally4:
#line 47 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 47 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (srcdir);
#line 47 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 47 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_clear_error (&_inner_error_);
#line 47 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		return;
#line 397 "system-dictionary.c"
	}
	{
		gchar* _tmp16_ = NULL;
		gchar* _tmp17_ = NULL;
		KkcSystemSegmentDictionary* _tmp18_ = NULL;
		KkcSystemSegmentDictionary* _tmp19_ = NULL;
#line 55 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp16_ = g_build_filename (srcdir, "system-segment-dictionary-bad3", NULL);
#line 55 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp17_ = _tmp16_;
#line 55 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp18_ = kkc_system_segment_dictionary_new (_tmp17_, "EUC-JP", &_inner_error_);
#line 55 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp19_ = _tmp18_;
#line 55 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_object_unref0 (_tmp19_);
#line 55 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (_tmp17_);
#line 55 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 418 "system-dictionary.c"
			goto __catch5_g_error;
		}
#line 57 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_assert_not_reached ();
#line 423 "system-dictionary.c"
	}
	goto __finally5;
	__catch5_g_error:
	{
		GError* e = NULL;
#line 54 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		e = _inner_error_;
#line 54 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_inner_error_ = NULL;
#line 54 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_error_free0 (e);
#line 435 "system-dictionary.c"
	}
	__finally5:
#line 54 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 54 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (srcdir);
#line 54 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 54 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_clear_error (&_inner_error_);
#line 54 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		return;
#line 448 "system-dictionary.c"
	}
#line 22 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_g_free0 (srcdir);
#line 452 "system-dictionary.c"
}
static void system_dictionary_tests_test_properties (SystemDictionaryTests* self) {
	KkcSystemSegmentDictionary* system_segment_dictionary = NULL;
	gchar* srcdir = NULL;
	const gchar* _tmp0_ = NULL;
	gchar* _tmp1_ = NULL;
	GError * _inner_error_ = NULL;
#line 9 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	g_return_if_fail (self != NULL);
#line 10 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	system_segment_dictionary = NULL;
#line 11 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_tmp0_ = g_getenv ("srcdir");
#line 11 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_tmp1_ = g_strdup (_tmp0_);
#line 11 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	srcdir = _tmp1_;
#line 12 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_vala_assert (srcdir != NULL, "srcdir != null");
#line 108 "system-dictionary.c"
	{
		KkcSystemSegmentDictionary* _tmp2_ = NULL;
		gchar* _tmp3_ = NULL;
		gchar* _tmp4_ = NULL;
		KkcSystemSegmentDictionary* _tmp5_ = NULL;
		KkcSystemSegmentDictionary* _tmp6_ = NULL;
		KkcSystemSegmentDictionary* _tmp7_ = NULL;
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp3_ = g_build_filename (srcdir, "system-segment-dictionary", NULL);
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp4_ = _tmp3_;
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp5_ = kkc_system_segment_dictionary_new (_tmp4_, "EUC-JP", &_inner_error_);
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp6_ = _tmp5_;
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (_tmp4_);
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp2_ = _tmp6_;
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 130 "system-dictionary.c"
			goto __catch0_g_error;
		}
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp7_ = _tmp2_;
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp2_ = NULL;
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_object_unref0 (system_segment_dictionary);
#line 15 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		system_segment_dictionary = _tmp7_;
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_object_unref0 (_tmp2_);
#line 143 "system-dictionary.c"
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		FILE* _tmp8_ = NULL;
		GError* _tmp9_ = NULL;
		const gchar* _tmp10_ = NULL;
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		e = _inner_error_;
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_inner_error_ = NULL;
#line 18 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp8_ = stderr;
#line 18 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp9_ = e;
#line 18 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_tmp10_ = _tmp9_->message;
#line 18 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		fprintf (_tmp8_, "%s\n", _tmp10_);
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_error_free0 (e);
#line 166 "system-dictionary.c"
	}
	__finally0:
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	if (G_UNLIKELY (_inner_error_ != NULL)) {
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_free0 (srcdir);
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		_g_object_unref0 (system_segment_dictionary);
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		g_clear_error (&_inner_error_);
#line 14 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
		return;
#line 181 "system-dictionary.c"
	}
#line 9 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_g_free0 (srcdir);
#line 9 "/home/ueno/devel/libkkc/tests/system-dictionary.vala"
	_g_object_unref0 (system_segment_dictionary);
#line 187 "system-dictionary.c"
}
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);
    }