Merge pull request #59 from guidocella/xdg

Comply with the XDG Base Directory Specification
This commit is contained in:
Evgeniy Dushistov
2020-05-11 17:19:06 +03:00
committed by GitHub
9 changed files with 33 additions and 27 deletions

View File

@@ -64,7 +64,7 @@ Use ANSI escape codes for colorizing sdcv output (does not work with json output
.TP .TP
/usr/share/stardict/dic /usr/share/stardict/dic
.TP .TP
$(HOME)/.stardict/dic $(XDG_DATA_HOME)/stardict/dic
Place where sdcv expects to find dictionaries. Place where sdcv expects to find dictionaries.
Instead of /usr/share/stardict/dic you can use any directory 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, For example, if you have dictionaries in /mnt/data/stardict-dicts/dic,
set STARDICT_DATA_DIR to /mnt/data/stardict-dicts. set STARDICT_DATA_DIR to /mnt/data/stardict-dicts.
.TP .TP
$(HOME)/.sdcv_history $(XDG_DATA_HOME)/sdcv_history
This file includes the last $(SDCV_HISTSIZE) words, which you sought with sdcv. 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. SDCV uses this file only if it was compiled with readline library support.
.TP .TP
$(HOME)/.sdcv_ordering $(XDG_CONFIG_HOME)/sdcv_ordering
This is a text file containing one dictionary bookname per line. This is a text file containing one dictionary bookname per line.
It specifies in which order the results of a search should be shown. 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 searches dictionaries in $\fBSTARDICT_DATA_DIR\fR/dic
.TP 20 .TP 20
.B SDCV_HISTSIZE .B SDCV_HISTSIZE
If set, sdcv writes in $(HOME)/.sdcv_history (or $(SDCV_HISTFILE)) the last $(SDCV_HISTSIZE) words, 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 $(HOME)/.sdcv_history. 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 .TP 20
.B SDCV_HISTFILE .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 .TP 20
.B SDCV_PAGER .B SDCV_PAGER
If SDCV_PAGER is set, its value is used as the name of the program If SDCV_PAGER is set, its value is used as the name of the program

View File

@@ -50,7 +50,7 @@ sdcv проста, міжплатформена текстова утиліта
.TP .TP
/usr/share/stardict/dic /usr/share/stardict/dic
.TP .TP
$(HOME)/.stardict/dic $(XDG_DATA_HOME)/stardict/dic
Місце, де sdcv очікує знайти словники. Місце, де sdcv очікує знайти словники.
Замість шляху /usr/share/stardict/dic Ви можете використовувати все, Замість шляху /usr/share/stardict/dic Ви можете використовувати все,
@@ -58,7 +58,7 @@ $(HOME)/.stardict/dic
Наприклад, якщо Ви маєте словники у теці /mnt/data/stardict-dicts/dic, Наприклад, якщо Ви маєте словники у теці /mnt/data/stardict-dicts/dic,
встановіть STARDICT_DATA_DIR у /mnt/data/stardict-dicts. встановіть STARDICT_DATA_DIR у /mnt/data/stardict-dicts.
.TP .TP
$(HOME)/.sdcv_history $(XDG_DATA_HOME)/sdcv_history
Цей файл містить останні $(SDCV_HISTSIZE) слова, які Ви шукали з sdcv. Цей файл містить останні $(SDCV_HISTSIZE) слова, які Ви шукали з sdcv.
SDCV використовує цей файл при умові, якщо sdcv був скомпільований SDCV використовує цей файл при умові, якщо sdcv був скомпільований
@@ -72,9 +72,9 @@ SDCV використовує цей файл при умові, якщо sdcv
що sdcv шукатиме словники у $\fBSTARDICT_DATA_DIR\fR/dic що sdcv шукатиме словники у $\fBSTARDICT_DATA_DIR\fR/dic
.TP 20 .TP 20
.B SDCV_HISTSIZE .B SDCV_HISTSIZE
Якщо встановлена, sdcv писатиме у $(HOME)/.sdcv_history лише Якщо встановлена, sdcv писатиме у $(XDG_DATA_HOME)/sdcv_history лише
останні $(SDCV_HISTSIZE) слова, які Ви шукали з sdcv. Якщо не встановлена, останні $(SDCV_HISTSIZE) слова, які Ви шукали з sdcv. Якщо не встановлена,
то збірігатиметься останніх 2000 слів у $(HOME)/.sdcv_history. то збірігатиметься останніх 2000 слів у $(XDG_DATA_HOME)/sdcv_history.
.SH BUGS .SH BUGS
Звіти про помилки висилайте на адресу dushistov на mail крапка ru. Звіти про помилки висилайте на адресу dushistov на mail крапка ru.
Не забувайте включати слово "sdcv" десь у полі "Тема:". Не забувайте включати слово "sdcv" десь у полі "Тема:".

View File

@@ -68,8 +68,12 @@ std::string get_hist_file_path()
if (hist_file_str != nullptr) if (hist_file_str != nullptr)
return std::string(hist_file_str); 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 class real_readline : public IReadLine

View File

@@ -141,13 +141,13 @@ int main(int argc, char *argv[]) try {
data_dir = get_impl(opt_data_dir); data_dir = get_impl(opt_data_dir);
} }
const char *homedir = g_getenv("HOME"); std::string conf_dir = std::string(g_get_home_dir()) + G_DIR_SEPARATOR + ".stardict";
if (!homedir) if (!g_file_test(conf_dir.c_str(), G_FILE_TEST_IS_DIR))
homedir = g_get_home_dir(); conf_dir = std::string(g_get_user_data_dir()) + G_DIR_SEPARATOR + "stardict";
std::list<std::string> dicts_dir_list; std::list<std::string> dicts_dir_list;
if (!only_data_dir) 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); dicts_dir_list.push_back(data_dir);
if (show_list_dicts) { if (show_list_dicts) {
list_dicts(dicts_dir_list, json_output); list_dicts(dicts_dir_list, json_output);
@@ -186,8 +186,12 @@ int main(int argc, char *argv[]) try {
++p; ++p;
} }
} else { } else {
const std::string odering_cfg_file = std::string(homedir) + G_DIR_SEPARATOR_S ".sdcv_ordering"; std::string ordering_cfg_file = std::string(g_get_user_config_dir()) + G_DIR_SEPARATOR_S "sdcv_ordering";
FILE *ordering_file = fopen(odering_cfg_file.c_str(), "r"); 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) { if (ordering_file != nullptr) {
std::string line; std::string line;
while (stdio_getline(ordering_file, 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) { if (g_mkdir(conf_dir.c_str(), S_IRWXU) == -1 && errno != EEXIST) {
fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno)); fprintf(stderr, _("g_mkdir failed: %s\n"), strerror(errno));
} }

Binary file not shown.

View File

@@ -6,7 +6,7 @@ unset SDCV_PAGER
have=`"$PATH_TO_SDCV" --data-dir /tmp/bugagaga -l | wc -l` have=`"$PATH_TO_SDCV" --data-dir /tmp/bugagaga -l | wc -l`
#do not count header #do not count header
have=$(($have-1)) 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)) #ndicts=$(($ndicts+1))
if [ $have -ne $ndicts ]; then if [ $have -ne $ndicts ]; then
ndicts=$(($ndicts-1)) ndicts=$(($ndicts-1))

View File

@@ -4,7 +4,7 @@ PATH_TO_SDCV="$1"
ndicts=`"$PATH_TO_SDCV" -l | wc -l` ndicts=`"$PATH_TO_SDCV" -l | wc -l`
ndicts=$(($ndicts-1)) ndicts=$(($ndicts-1))
ncom=`find /usr/share/stardict/dic -name "*.ifo" | wc -l` 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)) nmy=$(($ncom+$nspe))
if [ $nmy -ne $ndicts ]; then if [ $nmy -ne $ndicts ]; then

View File

@@ -5,8 +5,8 @@ set -e
PATH_TO_SDCV="$1" PATH_TO_SDCV="$1"
TESTS_DIR="$2" TESTS_DIR="$2"
mkdir -p "${HOME}"/.stardict/dic mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic
cp -R "${TESTS_DIR}/stardict-test_dict-2.4.2" "${HOME}"/.stardict/dic cp -R "${TESTS_DIR}/stardict-test_dict-2.4.2" "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic
unset SDCV_PAGER unset SDCV_PAGER
RES=`"$PATH_TO_SDCV" -n -u test_dict test | grep "test passed"` RES=`"$PATH_TO_SDCV" -n -u test_dict test | grep "test passed"`
@@ -15,6 +15,6 @@ if [ -z "$RES" ]; then
exit 1 exit 1
fi 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 exit 0

View File

@@ -4,9 +4,8 @@ set -e
PATH_TO_SDCV="$1" PATH_TO_SDCV="$1"
TESTS_DIR="$2" TESTS_DIR="$2"
mkdir -p "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic
mkdir -p "${HOME}"/.stardict/dic cp -R "${TESTS_DIR}/rus-eng-stardict-2.4.2" "${XDG_DATA_HOME:-$HOME/.local/share}"/stardict/dic/
cp -R "${TESTS_DIR}/rus-eng-stardict-2.4.2" "${HOME}"/.stardict/dic/
unset SDCV_PAGER unset SDCV_PAGER
export LANG=ru_RU.KOI8-R export LANG=ru_RU.KOI8-R