opencc_t opencc_open(const char* config_file) { if (!lib_initialized) { lib_initialize(); } OpenccDesc* opencc; opencc = (OpenccDesc*)malloc(sizeof(OpenccDesc)); opencc->dict_chain = NULL; opencc->converter = converter_open(); converter_set_conversion_mode(opencc->converter, OPENCC_CONVERSION_FAST); if (config_file == NULL) { /* TODO load default */ assert(0); } else { /* Load config */ Config* config = config_open(config_file); if (config == (Config*)-1) { errnum = OPENCC_ERROR_CONFIG; return (opencc_t)-1; } opencc->dict_chain = config_get_dict_chain(config); converter_assign_dictionary(opencc->converter, opencc->dict_chain); config_close(config); } return (opencc_t)opencc; }
opencc_t opencc_open(const char * config_file, const char* home_path) { if (!lib_initialized) lib_initialize(); opencc_desc * opencc; opencc = (opencc_desc *) malloc(sizeof(opencc_desc)); opencc->dictionary_set = NULL; opencc->converter = converter_open(); converter_set_conversion_mode(opencc->converter, OPENCC_CONVERSION_FAST); /* 加載默認辭典 */ int retval; if (config_file == NULL) retval = 0; else { config_t config = config_open(config_file, home_path); if (config == (config_t) -1) { errnum = OPENCC_ERROR_CONFIG; return (opencc_t) -1; } opencc->dictionary_set = config_get_dictionary_set(config); converter_assign_dictionary(opencc->converter, opencc->dictionary_set); config_close(config); } return (opencc_t) opencc; }