Skip to content

Commit 3981e7d

Browse files
committed
fix envvar behavior
1 parent 2866cd4 commit 3981e7d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/cskk.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,26 +201,29 @@ void FcitxCskkEngine::loadDictionary() {
201201
CSKK_WARN() << "Invalid dictionary path or mode. Ignored";
202202
continue;
203203
}
204+
205+
constexpr char configDir[] = "$FCITX_CONFIG_DIR/";
206+
constexpr auto var_len = sizeof(configDir) - 1;
207+
std::string realpath = path;
208+
if (stringutils::startsWith(path, configDir)) {
209+
realpath =
210+
StandardPaths::global().userDirectory(StandardPathsType::PkgData) /
211+
path.substr(var_len);
212+
}
213+
204214
if (mode == 1) {
205215
// readonly mode
206-
auto *dict = skk_file_dict_new(path.c_str(), encoding.c_str(), complete);
216+
auto *dict =
217+
skk_file_dict_new(realpath.c_str(), encoding.c_str(), complete);
207218
if (dict) {
208-
CSKK_DEBUG() << "Adding file dict: " << path
219+
CSKK_DEBUG() << "Adding file dict: " << realpath
209220
<< " complete:" << complete;
210221
dictionaries_.emplace_back(dict);
211222
} else {
212-
CSKK_WARN() << "Static dictionary load error. Ignored: " << path;
223+
CSKK_WARN() << "Static dictionary load error. Ignored: " << realpath;
213224
}
214225
} else {
215226
// read/write mode
216-
constexpr char configDir[] = "$FCITX_CONFIG_DIR/";
217-
constexpr auto var_len = sizeof(configDir) - 1;
218-
std::string realpath = path;
219-
if (stringutils::startsWith(path, configDir)) {
220-
realpath =
221-
StandardPaths::global().userDirectory(StandardPathsType::PkgData) /
222-
path.substr(var_len);
223-
}
224227
auto *userdict =
225228
skk_user_dict_new(realpath.c_str(), encoding.c_str(), complete);
226229
if (userdict) {

0 commit comments

Comments
 (0)