diff --git a/doc/sdcv.1 b/doc/sdcv.1 index 604cfc5..fe6fd96 100644 --- a/doc/sdcv.1 +++ b/doc/sdcv.1 @@ -64,7 +64,7 @@ Use ANSI escape codes for colorizing sdcv output (does not work with json output .TP /usr/share/stardict/dic .TP -$(HOME)/.stardict/dic +$(XDG_DATA_HOME)/stardict/dic Place where sdcv expects to find dictionaries. Instead of /usr/share/stardict/dic you can use any directory @@ -72,12 +72,12 @@ you want, just set the STARDICT_DATA_DIR environment variable. For example, if you have dictionaries in /mnt/data/stardict-dicts/dic, set STARDICT_DATA_DIR to /mnt/data/stardict-dicts. .TP -$(HOME)/.sdcv_history +$(XDG_DATA_HOME)/sdcv_history This file includes the last $(SDCV_HISTSIZE) words, which you sought with sdcv. SDCV uses this file only if it was compiled with readline library support. .TP -$(HOME)/.sdcv_ordering +$(XDG_CONFIG_HOME)/sdcv_ordering This is a text file containing one dictionary bookname per line. It specifies in which order the results of a search should be shown. @@ -89,11 +89,11 @@ If set, sdcv uses this variable as the data directory, this means that sdcv searches dictionaries in $\fBSTARDICT_DATA_DIR\fR/dic .TP 20 .B SDCV_HISTSIZE -If set, sdcv writes in $(HOME)/.sdcv_history (or $(SDCV_HISTFILE)) the last $(SDCV_HISTSIZE) words, -which you look up using sdcv. If it is not set, then the last 2000 words are saved in $(HOME)/.sdcv_history. +If set, sdcv writes in $(XDG_DATA_HOME)/sdcv_history (or $(SDCV_HISTFILE)) the last $(SDCV_HISTSIZE) words, +which you look up using sdcv. If it is not set, then the last 2000 words are saved in $(XDG_DATA_HOME)/sdcv_history. .TP 20 .B SDCV_HISTFILE -If set, sdcv writes it's history to $(SDCV_HISTFILE). If it is not set, then the default $(HOME)/.sdcv_history path will be used. +If set, sdcv writes it's history to $(SDCV_HISTFILE). If it is not set, then the default $(XDG_DATA_HOME)/sdcv_history path will be used. .TP 20 .B SDCV_PAGER If SDCV_PAGER is set, its value is used as the name of the program diff --git a/doc/uk/sdcv.1 b/doc/uk/sdcv.1 index aceb0f7..b2a9084 100644 --- a/doc/uk/sdcv.1 +++ b/doc/uk/sdcv.1 @@ -50,7 +50,7 @@ sdcv проста, міжплатформена текстова утиліта .TP /usr/share/stardict/dic .TP -$(HOME)/.stardict/dic +$(XDG_DATA_HOME)/stardict/dic Місце, де sdcv очікує знайти словники. Замість шляху /usr/share/stardict/dic Ви можете використовувати все, @@ -58,7 +58,7 @@ $(HOME)/.stardict/dic Наприклад, якщо Ви маєте словники у теці /mnt/data/stardict-dicts/dic, встановіть STARDICT_DATA_DIR у /mnt/data/stardict-dicts. .TP -$(HOME)/.sdcv_history +$(XDG_DATA_HOME)/sdcv_history Цей файл містить останні $(SDCV_HISTSIZE) слова, які Ви шукали з sdcv. SDCV використовує цей файл при умові, якщо sdcv був скомпільований @@ -72,9 +72,9 @@ SDCV використовує цей файл при умові, якщо sdcv що sdcv шукатиме словники у $\fBSTARDICT_DATA_DIR\fR/dic .TP 20 .B SDCV_HISTSIZE -Якщо встановлена, sdcv писатиме у $(HOME)/.sdcv_history лише +Якщо встановлена, sdcv писатиме у $(XDG_DATA_HOME)/sdcv_history лише останні $(SDCV_HISTSIZE) слова, які Ви шукали з sdcv. Якщо не встановлена, -то збірігатиметься останніх 2000 слів у $(HOME)/.sdcv_history. +то збірігатиметься останніх 2000 слів у $(XDG_DATA_HOME)/sdcv_history. .SH BUGS Звіти про помилки висилайте на адресу dushistov на mail крапка ru. Не забувайте включати слово "sdcv" десь у полі "Тема:". diff --git a/src/readline.cpp b/src/readline.cpp index f4539b9..2204c17 100644 --- a/src/readline.cpp +++ b/src/readline.cpp @@ -68,8 +68,12 @@ std::string get_hist_file_path() if (hist_file_str != nullptr) return std::string(hist_file_str); - else - return std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"; + + const std::string hist_file_path = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".sdcv_history"; + if (g_file_test(hist_file_path.c_str(), G_FILE_TEST_IS_REGULAR)) + return hist_file_path; + + return std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "sdcv_history"; } class real_readline : public IReadLine diff --git a/src/sdcv.cpp b/src/sdcv.cpp index 6ffcc1c..16466ad 100644 --- a/src/sdcv.cpp +++ b/src/sdcv.cpp @@ -141,13 +141,13 @@ int main(int argc, char *argv[]) try { data_dir = get_impl(opt_data_dir); } - const char *homedir = g_getenv("HOME"); - if (!homedir) - homedir = g_get_home_dir(); + std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict"; + if (!g_file_test(conf_dir.c_str(), G_FILE_TEST_IS_DIR)) + conf_dir = std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "stardict"; std::list dicts_dir_list; if (!only_data_dir) - dicts_dir_list.push_back(std::string(homedir) + G_DIR_SEPARATOR + ".stardict" + G_DIR_SEPARATOR + "dic"); + dicts_dir_list.push_back(conf_dir + G_DIR_SEPARATOR + "dic"); dicts_dir_list.push_back(data_dir); if (show_list_dicts) { list_dicts(dicts_dir_list, json_output); @@ -186,8 +186,12 @@ int main(int argc, char *argv[]) try { ++p; } } else { - const std::string odering_cfg_file = std::string(homedir) + G_DIR_SEPARATOR_S ".sdcv_ordering"; - FILE *ordering_file = fopen(odering_cfg_file.c_str(), "r"); + std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering"; + FILE *ordering_file = fopen(ordering_cfg_file.c_str(), "r"); + if (ordering_file == nullptr) { + ordering_cfg_file = std::string(g_get_home_dir()) + G_DIR_SEPARATOR_S ".sdcv_ordering"; + ordering_file = fopen(ordering_cfg_file.c_str(), "r"); + } if (ordering_file != nullptr) { std::string line; while (stdio_getline(ordering_file, line)) { @@ -197,7 +201,6 @@ int main(int argc, char *argv[]) try { } } - const std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict"; if (g_mkdir(conf_dir.c_str(), S_IRWXU) == -1 && errno != EEXIST) { fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno)); } diff --git a/tests/stardict-test_synonyms-2.4.2/test.idx.oft b/tests/stardict-test_synonyms-2.4.2/test.idx.oft new file mode 100644 index 0000000..31dc347 Binary files /dev/null and b/tests/stardict-test_synonyms-2.4.2/test.idx.oft differ diff --git a/tests/t_datadir b/tests/t_datadir index 0ebe965..2fbf06e 100755 --- a/tests/t_datadir +++ b/tests/t_datadir @@ -6,7 +6,7 @@ unset SDCV_PAGER have=`"$PATH_TO_SDCV" --data-dir /tmp/bugagaga -l | wc -l` #do not count header have=$(($have-1)) -ndicts=`find "${HOME}"/.stardict/dic -name "*.ifo" -print | wc -l` +ndicts=`find "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic -name "*.ifo" -print | wc -l` #ndicts=$(($ndicts+1)) if [ $have -ne $ndicts ]; then ndicts=$(($ndicts-1)) diff --git a/tests/t_list b/tests/t_list index 3518731..a8c92c4 100755 --- a/tests/t_list +++ b/tests/t_list @@ -4,7 +4,7 @@ PATH_TO_SDCV="$1" ndicts=`"$PATH_TO_SDCV" -l | wc -l` ndicts=$(($ndicts-1)) ncom=`find /usr/share/stardict/dic -name "*.ifo" | wc -l` -nspe=`find "${HOME}"/.stardict/dic -name "*.ifo" | wc -l` +nspe=`find "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic -name "*.ifo" | wc -l` nmy=$(($ncom+$nspe)) if [ $nmy -ne $ndicts ]; then diff --git a/tests/t_use b/tests/t_use index d141726..ad6f39b 100755 --- a/tests/t_use +++ b/tests/t_use @@ -5,8 +5,8 @@ set -e PATH_TO_SDCV="$1" TESTS_DIR="$2" -mkdir -p "${HOME}"/.stardict/dic -cp -R "${TESTS_DIR}/stardict-test_dict-2.4.2" "${HOME}"/.stardict/dic +mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic +cp -R "${TESTS_DIR}/stardict-test_dict-2.4.2" "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic unset SDCV_PAGER RES=`"$PATH_TO_SDCV" -n -u test_dict test | grep "test passed"` @@ -15,6 +15,6 @@ if [ -z "$RES" ]; then exit 1 fi -rm -fr "${HOME}"/.stardict/dic/stardict-test_dict-2.4.2 +rm -fr "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic/stardict-test_dict-2.4.2 exit 0 diff --git a/tests/t_utf8input b/tests/t_utf8input index 1ad8360..6111ac0 100755 --- a/tests/t_utf8input +++ b/tests/t_utf8input @@ -4,9 +4,8 @@ set -e PATH_TO_SDCV="$1" TESTS_DIR="$2" - -mkdir -p "${HOME}"/.stardict/dic -cp -R "${TESTS_DIR}/rus-eng-stardict-2.4.2" "${HOME}"/.stardict/dic/ +mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic +cp -R "${TESTS_DIR}/rus-eng-stardict-2.4.2" "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic/ unset SDCV_PAGER export LANG=ru_RU.KOI8-R