From 7ea7cacade2edc88c0a66f2a05cc60e716751c3a Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Mon, 26 Dec 2022 17:36:31 +0100 Subject: [PATCH] [.config] Read/write configuration from ~/.config/elinks . Refs #199 Note, configs and other files from ~/.elinks/ are not moved to ~/.config/elinks/ automatically. You must do it yourself. ELINKS_CONFDIR and HOME_ETC also are no longer supported. --- doc/elinks.1.txt | 33 +++++++-------- doc/elinkskeys.5.txt | 4 +- doc/events.txt | 2 +- doc/lua-scripting.txt | 4 +- doc/python.txt | 4 +- doc/remote.txt | 2 +- doc/smjs-scripting.txt | 4 +- src/bfu/inphist.c | 12 +++--- src/bookmarks/backend/common.c | 10 +++-- src/config/conf.c | 11 +++-- src/config/home.c | 60 ++++++++++++++++++++++++++-- src/config/home.h | 2 +- src/config/options.c | 3 +- src/cookies/cookies.c | 12 +++--- src/document/css/css.c | 5 ++- src/ecmascript/ecmascript.cpp | 16 ++++---- src/formhist/formhist.c | 10 +++-- src/globhist/globhist.c | 10 +++-- src/main/interlink.c | 6 ++- src/network/ssl/ssl.c | 2 +- src/scripting/guile/core.c | 7 ++-- src/scripting/lua/core.c | 6 ++- src/scripting/perl/core.c | 6 +-- src/scripting/python/core.c | 10 +++-- src/scripting/ruby/core.c | 9 +++-- src/scripting/smjs/core.cpp | 5 ++- src/scripting/smjs/elinks_object.cpp | 3 +- src/session/session.cpp | 4 +- src/terminal/mouse.c | 2 +- 29 files changed, 171 insertions(+), 93 deletions(-) diff --git a/doc/elinks.1.txt b/doc/elinks.1.txt index e681cf38..d473e790 100644 --- a/doc/elinks.1.txt +++ b/doc/elinks.1.txt @@ -56,10 +56,11 @@ EDITOR:: The program to use for external editor (when editing textareas). -ELINKS_CONFDIR:: +XDG_CONFIG_HOME:: - The location of the directory containing configuration files. If not - set the default is `~/.elinks/`. + The location of the directory containing configuration files. If set + configuration files are located in `$XDG_CONFIG_HOME/elinks/`. + Otherwise in `~/.config/elinks/`. ELINKS_TWTERM, LINKS_TWTERM:: @@ -83,10 +84,6 @@ HOME:: The path to the users home directory. Used when expanding `~/`. -HOME_ETC:: - - If set the location of the directory containing configuration files - is `$HOME_ETC/.elinks/` instead of `~/.elinks/`. WWW_HOME:: @@ -96,41 +93,41 @@ FILES ----- Configuration files controlled by ELinks are located in the user -configuration directory, defaulting to '~/.elinks/'. In addition to the +configuration directory, defaulting to '~/.config/elinks/'. In addition to the files listed below, a user defined CSS stylesheet can be defined using the 'document.css.stylesheet' option. @sysconfdir@/elinks.conf:: Site-wide configuration file. -~/.elinks/elinks.conf:: +~/.config/elinks/elinks.conf:: Per-user config file, loaded after site-wide configuration. -~/.elinks/bookmarks:: +~/.config/elinks/bookmarks:: Bookmarks file. -~/.elinks/cookies:: +~/.config/elinks/cookies:: Cookies file. -~/.elinks/exmodehist:: +~/.config/elinks/exmodehist:: Exmode history file. -~/.elinks/formhist:: +~/.config/elinks/formhist:: Form history file. -~/.elinks/globhist:: +~/.config/elinks/globhist:: History file containing most recently visited URLs. -~/.elinks/gotohist:: +~/.config/elinks/gotohist:: GoTo URL dialog history file. -~/.elinks/hooks.{js,lua,pl,py,rb,scm}:: +~/.config/elinks/hooks.{js,lua,pl,py,rb,scm}:: Browser scripting hooks. -~/.elinks/searchhist:: +~/.config/elinks/searchhist:: Search history file. -~/.elinks/socket:: +~/.config/elinks/socket:: Internal 'ELinks' socket for communication between its instances. ~/.mailcap, /etc/mailcap:: diff --git a/doc/elinkskeys.5.txt b/doc/elinkskeys.5.txt index 30715ee1..efcfe80f 100644 --- a/doc/elinkskeys.5.txt +++ b/doc/elinkskeys.5.txt @@ -14,7 +14,7 @@ keybindings. DESCRIPTION ----------- -Key binding for elinks should be placed in the file `~/.elinks/elinks.conf`. +Key binding for elinks should be placed in the file `~/.config/elinks/elinks.conf`. Note that any information regarding their format/structure may not be up-to-date. If you will discover that, please feed us with a patch. @@ -98,7 +98,7 @@ include::{builddir}keymap-actions.txt[] DEFAULT BINDINGS ---------------- -The default bindings are shown below. Any bindings in `~/.elinks/elinks.conf` +The default bindings are shown below. Any bindings in `~/.config/elinks/elinks.conf` will override these. include::{builddir}keymap-defaults.txt[] diff --git a/doc/events.txt b/doc/events.txt index 1e1caeb2..9ee63386 100644 --- a/doc/events.txt +++ b/doc/events.txt @@ -206,7 +206,7 @@ Arguments: Description: - Makes it possible to periodically save files in ~/.elinks to disk. + Makes it possible to periodically save files in ~/.config/elinks to disk. ------------------------------------------------------------------------------- Name: pre-format-html diff --git a/doc/lua-scripting.txt b/doc/lua-scripting.txt index f80d56de..d66c9ef3 100644 --- a/doc/lua-scripting.txt +++ b/doc/lua-scripting.txt @@ -128,7 +128,7 @@ Config file On startup, ELinks reads in two Lua scripts. Firstly, a system-wide configuration file called `/etc/elinks/hooks.lua`, then a file in your home -directory called `~/.elinks/hooks.lua`. From these files, you can include +directory called `~/.config/elinks/hooks.lua`. From these files, you can include other Lua files with `dofile`, if necessary. To see what kind of things you should put in here, look at @@ -243,7 +243,7 @@ WARNING: The `tmpname` function creates the file but does not bind_key (keymap, keystroke, function):: Currently, `keymap` must be the string `"main"`. Keystroke is a keystroke as you would write it in the ELinks config file - `~/.elinks/elinks.conf`. The function `function` should take no + `~/.config/elinks/elinks.conf`. The function `function` should take no arguments, and should return the same values as `lua_console_hook`. edit_bookmark_dialog (cat, name, url, function):: diff --git a/doc/python.txt b/doc/python.txt index 62707ed7..c635c4f1 100644 --- a/doc/python.txt +++ b/doc/python.txt @@ -15,7 +15,7 @@ DESCRIPTION If ELinks is compiled with an embedded Python interpreter, it will try to import a Python module called hooks when the browser starts up. To use Python code from within ELinks, create a file called hooks.py in - the ~/.elinks directory, or in the system-wide configuration directory + the ~/.config/elinks directory, or in the system-wide configuration directory (defined when ELinks was compiled), or in the standard Python search path. An example hooks.py file can be found in the contrib/python directory of the ELinks source distribution. @@ -112,7 +112,7 @@ DESCRIPTION Other public objects: - home -- A string containing the pathname of the ~/.elinks directory, or + home -- A string containing the pathname of the ~/.config/elinks directory, or None if ELinks has no configuration directory. FUNCTIONS diff --git a/doc/remote.txt b/doc/remote.txt index f12ae9cb..d22732ea 100644 --- a/doc/remote.txt +++ b/doc/remote.txt @@ -31,7 +31,7 @@ Limitations and outstanding issues ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Remote control is implemented using the intercommunication socket created in -~/.elinks/, so the command has to be run on the same machine as the instance +~/.config/elinks/, so the command has to be run on the same machine as the instance you want to control; or put differently: the two ELinkses need to share a file system that supports socket files, which rules out usage of -remote over NFS. This also implies that the ELinks instance you want to control should be diff --git a/doc/smjs-scripting.txt b/doc/smjs-scripting.txt index 155136ad..6a54023c 100644 --- a/doc/smjs-scripting.txt +++ b/doc/smjs-scripting.txt @@ -20,7 +20,7 @@ you don't have a `hooks.js` file, there is not much risk in enabling the feature at compile time. When ELinks starts up, it evaluates the ECMAScript file `hooks.js` in -your ELinks configuration directory (thus normally `~/.elinks/hooks.js` +your ELinks configuration directory (thus normally `~/.config/elinks/hooks.js` on Unix-like systems), or if the file does not exist there, then in the system-wide ELinks configuration directory (the location depends on how ELinks was built, but `/etc/elinks/hooks.js` is typical). @@ -47,7 +47,7 @@ Global Object Methods + -- ---------------------------------------------------------------------- -do_file("/home/me/.elinks/hooks.js"); +do_file("/home/me/.config/elinks/hooks.js"); ---------------------------------------------------------------------- will reload your hooks file. diff --git a/src/bfu/inphist.c b/src/bfu/inphist.c index 3bab9cd5..fb63830f 100644 --- a/src/bfu/inphist.c +++ b/src/bfu/inphist.c @@ -286,19 +286,20 @@ add_to_input_history(struct input_history *history, char *data, int load_input_history(struct input_history *history, const char *filename) { + char *xdg_config_home = get_xdg_config_home(); char *history_file = (char *)filename; char line[MAX_STR_LEN]; FILE *file; if (get_cmd_opt_bool("anonymous")) return 0; - if (elinks_home) { - history_file = straconcat(elinks_home, filename, + if (xdg_config_home) { + history_file = straconcat(xdg_config_home, filename, (char *) NULL); if (!history_file) return 0; } file = fopen(history_file, "rb"); - if (elinks_home) mem_free(history_file); + if (xdg_config_home) mem_free(history_file); if (!file) return 0; history->nosave = 1; @@ -329,17 +330,18 @@ load_input_history(struct input_history *history, const char *filename) int save_input_history(struct input_history *history, const char *filename) { + char *xdg_config_home = get_xdg_config_home(); struct input_history_entry *entry; struct secure_save_info *ssi; char *history_file; int i = 0; if (!history->dirty - || !elinks_home + || !xdg_config_home || get_cmd_opt_bool("anonymous")) return 0; - history_file = straconcat(elinks_home, filename, + history_file = straconcat(xdg_config_home, filename, (char *) NULL); if (!history_file) return -1; diff --git a/src/bookmarks/backend/common.c b/src/bookmarks/backend/common.c index 3dd678a6..80d6947a 100644 --- a/src/bookmarks/backend/common.c +++ b/src/bookmarks/backend/common.c @@ -45,6 +45,7 @@ static int loaded_backend_num = -1; void bookmarks_read(void) { + char *xdg_config_home = get_xdg_config_home(); int backend_num = get_opt_int("bookmarks.file_format", NULL); struct bookmarks_backend *backend = bookmarks_backends[backend_num]; char *file_name; @@ -57,8 +58,8 @@ bookmarks_read(void) file_name_orig = backend->filename(0); if (!file_name_orig) return; - if (elinks_home) { - file_name = straconcat(elinks_home, file_name_orig, + if (xdg_config_home) { + file_name = straconcat(xdg_config_home, file_name_orig, (char *) NULL); if (!file_name) return; f = fopen(file_name, "rb"); @@ -84,11 +85,12 @@ bookmarks_write(LIST_OF(struct bookmark) *bookmarks_list) struct secure_save_info *ssi; char *file_name; const char *file_name_orig; + char *xdg_config_home = get_xdg_config_home(); if (!bookmarks_are_dirty() && backend_num == loaded_backend_num) return; if (!backend || !backend->write - || !elinks_home + || !xdg_config_home || !backend->filename) return; /* We do this two-passes because we want backend to possibly decide to @@ -96,7 +98,7 @@ bookmarks_write(LIST_OF(struct bookmark) *bookmarks_list) * they would be just truncated to zero by secure_open()). */ file_name_orig = backend->filename(1); if (!file_name_orig) return; - file_name = straconcat(elinks_home, file_name_orig, (char *) NULL); + file_name = straconcat(xdg_config_home, file_name_orig, (char *) NULL); if (!file_name) return; ssi = secure_open(file_name); diff --git a/src/config/conf.c b/src/config/conf.c index f2bac301..5627f567 100644 --- a/src/config/conf.c +++ b/src/config/conf.c @@ -578,6 +578,7 @@ static enum parse_error parse_include(struct option *opt_tree, struct conf_parsing_state *state, struct string *mirror, int is_system_conf) { + char *xdg_config_home = get_xdg_config_home(); char *fname; struct string dumbstring; struct conf_parsing_pos before_error; @@ -609,7 +610,7 @@ parse_include(struct option *opt_tree, struct conf_parsing_state *state, /* XXX: We should try CONFDIR/ when proceeding * CONFDIR/ ;). --pasky */ if (load_config_file(fname[0] == '/' ? (char *) "" - : elinks_home, + : xdg_config_home, fname, opt_tree, mirror ? &dumbstring : NULL, 1)) { done_string(&dumbstring); @@ -837,7 +838,7 @@ static void load_config_from(char *file, struct option *tree) { load_config_file(CONFDIR, file, tree, NULL, 1); - load_config_file(empty_string_or_(elinks_home), file, tree, NULL, 0); + load_config_file(empty_string_or_(get_xdg_config_home()), file, tree, NULL, 0); } void @@ -1306,7 +1307,9 @@ free_cfg_str: int write_config(struct terminal *term) { - if (!elinks_home) { + char *xdg_config_home = get_xdg_config_home(); + + if (!xdg_config_home) { if (term) { write_config_dialog(term, get_cmd_opt_str("config-file"), SS_ERR_DISABLED, 0); @@ -1314,7 +1317,7 @@ write_config(struct terminal *term) return -1; } - return write_config_file(elinks_home, get_cmd_opt_str("config-file"), + return write_config_file(xdg_config_home, get_cmd_opt_str("config-file"), term); } diff --git a/src/config/home.c b/src/config/home.c index e075d38b..11bb26b3 100644 --- a/src/config/home.c +++ b/src/config/home.c @@ -24,8 +24,8 @@ #include "util/string.h" -char *elinks_home = NULL; int first_use = 0; +static char *xdg_config_home = NULL; static inline void strip_trailing_dir_sep(char *path) @@ -106,6 +106,58 @@ elinks_dirname(char *path) return dir; } +char * +get_xdg_config_home(void) +{ + if (xdg_config_home) { + return xdg_config_home; + } + char *g_xdg_config_home = getenv("XDG_CONFIG_HOME"); + + if (g_xdg_config_home && *g_xdg_config_home) { + xdg_config_home = test_confdir(g_xdg_config_home, + get_cmd_opt_str("config-dir"), + N_("Commandline options -config-dir set to %s, " + "but could not create directory %s.")); + if (xdg_config_home) { + return xdg_config_home; + } + xdg_config_home = test_confdir(g_xdg_config_home, "elinks", NULL); + + if (xdg_config_home) { + return xdg_config_home; + } + + return NULL; + } + char *home = getenv("HOME"); + + if (!home || !*home) { + return NULL; + } + char *config_dir = straconcat(home, STRING_DIR_SEP, ".config", NULL); + + if (!config_dir) { + return NULL; + } + xdg_config_home = test_confdir(config_dir, + get_cmd_opt_str("config-dir"), + N_("Commandline options -config-dir set to %s, " + "but could not create directory %s.")); + if (xdg_config_home) { + mem_free(config_dir); + return xdg_config_home; + } + xdg_config_home = test_confdir(config_dir, "elinks", NULL); + + if (xdg_config_home) { + mem_free(config_dir); + return xdg_config_home; + } + + return NULL; +} + static char * get_home(void) { @@ -151,8 +203,8 @@ void init_home(void) { first_use = 1; - elinks_home = get_home(); - if (!elinks_home) { + xdg_config_home = get_xdg_config_home(); + if (!xdg_config_home) { ERROR(gettext("Unable to find or create ELinks config " "directory. Please check if you have $HOME " "variable set correctly and if you have " @@ -165,5 +217,5 @@ init_home(void) void done_home(void) { - mem_free_if(elinks_home); + mem_free_set(&xdg_config_home, NULL); } diff --git a/src/config/home.h b/src/config/home.h index 7b7c2c15..70b7a82e 100644 --- a/src/config/home.h +++ b/src/config/home.h @@ -5,11 +5,11 @@ extern "C" { #endif -extern char *elinks_home; extern int first_use; void init_home(void); void done_home(void); +char *get_xdg_config_home(void); #ifdef __cplusplus } diff --git a/src/config/options.c b/src/config/options.c index 3843fea8..721876f5 100644 --- a/src/config/options.c +++ b/src/config/options.c @@ -886,7 +886,8 @@ change_hook_ui_double_esc(struct session *ses, struct option *current, struct op static int change_hook_ui_mouse_disable(struct session *ses, struct option *current, struct option *changed) { - char *lock_filename = straconcat(empty_string_or_(elinks_home), "mouse.lock", (char *)NULL); + char *xdg_config_home = get_xdg_config_home(); + char *lock_filename = straconcat(empty_string_or_(xdg_config_home), "mouse.lock", (char *)NULL); if (lock_filename) { if (changed->value.number) { diff --git a/src/cookies/cookies.c b/src/cookies/cookies.c index 5461aa18..69392852 100644 --- a/src/cookies/cookies.c +++ b/src/cookies/cookies.c @@ -691,6 +691,7 @@ static void done_cookies(struct module *module); void load_cookies(void) { + char *xdg_config_home = get_xdg_config_home(); /* Buffer size is set to be enough to read long lines that * save_cookies may write. 6 is choosen after the fprintf(..) call * in save_cookies(). --Zas */ @@ -700,8 +701,8 @@ load_cookies(void) { FILE *fp; time_t now; - if (elinks_home) { - cookfile = straconcat(elinks_home, cookfile_orig, + if (xdg_config_home) { + cookfile = straconcat(xdg_config_home, cookfile_orig, (char *) NULL); if (!cookfile) return; } @@ -712,7 +713,7 @@ load_cookies(void) { done_cookies(&cookies_module); cookies_nosave = 0; - if (elinks_home) { + if (xdg_config_home) { fp = fopen(cookfile, "rb"); mem_free(cookfile); } else { @@ -821,6 +822,7 @@ save_cookies(struct terminal *term) { char *cookfile; struct secure_save_info *ssi; time_t now; + char *xdg_config_home = get_xdg_config_home(); #ifdef CONFIG_SMALL # define CANNOT_SAVE_COOKIES(flags, message) @@ -838,7 +840,7 @@ save_cookies(struct terminal *term) { if_assert_failed {} return; } - if (!elinks_home) { + if (!xdg_config_home) { CANNOT_SAVE_COOKIES(0, N_("ELinks was started without a home directory.")); return; } @@ -849,7 +851,7 @@ save_cookies(struct terminal *term) { return; } - cookfile = straconcat(elinks_home, COOKIES_FILENAME, + cookfile = straconcat(xdg_config_home, COOKIES_FILENAME, (char *) NULL); if (!cookfile) { CANNOT_SAVE_COOKIES(0, N_("Out of memory")); diff --git a/src/document/css/css.c b/src/document/css/css.c index 74ddcda1..86023dbd 100644 --- a/src/document/css/css.c +++ b/src/document/css/css.c @@ -155,6 +155,7 @@ static void import_css_file(struct css_stylesheet *css, struct uri *base_uri, const char *url, int urllen) { + char *xdg_config_home = get_xdg_config_home(); struct string string, filename; if (!*url @@ -162,8 +163,8 @@ import_css_file(struct css_stylesheet *css, struct uri *base_uri, || !init_string(&filename)) return; - if (*url != '/' && elinks_home) { - add_to_string(&filename, elinks_home); + if (*url != '/' && xdg_config_home) { + add_to_string(&filename, xdg_config_home); } add_bytes_to_string(&filename, url, urllen); diff --git a/src/ecmascript/ecmascript.cpp b/src/ecmascript/ecmascript.cpp index 6d98b926..6ff0ac79 100644 --- a/src/ecmascript/ecmascript.cpp +++ b/src/ecmascript/ecmascript.cpp @@ -163,15 +163,16 @@ is_prefix(char *prefix, char *url, int dl) static void read_url_list(void) { + char *xdg_config_home = get_xdg_config_home(); char line[4096]; char *filename; FILE *f; - if (!elinks_home) { + if (!xdg_config_home) { return; } - filename = straconcat(elinks_home, STRING_DIR_SEP, ALLOWED_ECMASCRIPT_URL_PREFIXES, NULL); + filename = straconcat(xdg_config_home, STRING_DIR_SEP, ALLOWED_ECMASCRIPT_URL_PREFIXES, NULL); if (filename) { @@ -186,7 +187,7 @@ read_url_list(void) mem_free(filename); } - filename = straconcat(elinks_home, STRING_DIR_SEP, DISALLOWED_ECMASCRIPT_URL_PREFIXES, NULL); + filename = straconcat(xdg_config_home, STRING_DIR_SEP, DISALLOWED_ECMASCRIPT_URL_PREFIXES, NULL); if (filename) { @@ -829,17 +830,18 @@ ecmascript_set_timeout2m(js_State *J, const char *handle, int timeout) static void init_ecmascript_module(struct module *module) { + char *xdg_config_home = get_xdg_config_home(); read_url_list(); - if (elinks_home) { + if (xdg_config_home) { /* ecmascript console log */ - console_log_filename = straconcat(elinks_home, "/console.log", NULL); - console_error_filename = straconcat(elinks_home, "/console.err", NULL); + console_log_filename = straconcat(xdg_config_home, "/console.log", NULL); + console_error_filename = straconcat(xdg_config_home, "/console.err", NULL); /* ecmascript local storage db location */ #ifdef CONFIG_OS_DOS local_storage_filename = stracpy("elinks_ls.db"); #else - local_storage_filename = straconcat(elinks_home, "/elinks_ls.db", NULL); + local_storage_filename = straconcat(xdg_config_home, "/elinks_ls.db", NULL); #endif } ecmascript_enabled = get_opt_bool("ecmascript.enable", NULL); diff --git a/src/formhist/formhist.c b/src/formhist/formhist.c index 04fb99c9..d214fcbf 100644 --- a/src/formhist/formhist.c +++ b/src/formhist/formhist.c @@ -90,6 +90,7 @@ static int loaded = 0; int load_formhist_from_file(void) { + char *xdg_config_home = get_xdg_config_home(); struct formhist_data *form; char tmp[MAX_STR_LEN]; char *file; @@ -97,9 +98,9 @@ load_formhist_from_file(void) if (loaded) return 1; - if (!elinks_home) return 0; + if (!xdg_config_home) return 0; - file = straconcat(elinks_home, FORMS_HISTORY_FILENAME, + file = straconcat(xdg_config_home, FORMS_HISTORY_FILENAME, (char *) NULL); if (!file) return 0; @@ -215,15 +216,16 @@ fail: int save_formhist_to_file(void) { + char *xdg_config_home = get_xdg_config_home(); struct secure_save_info *ssi; char *file; struct formhist_data *form; int r; - if (!elinks_home || get_cmd_opt_bool("anonymous")) + if (!xdg_config_home || get_cmd_opt_bool("anonymous")) return 0; - file = straconcat(elinks_home, FORMS_HISTORY_FILENAME, + file = straconcat(xdg_config_home, FORMS_HISTORY_FILENAME, (char *) NULL); if (!file) return 0; diff --git a/src/globhist/globhist.c b/src/globhist/globhist.c index 0df56aeb..7a084055 100644 --- a/src/globhist/globhist.c +++ b/src/globhist/globhist.c @@ -327,6 +327,7 @@ globhist_simple_search(char *search_url, char *search_title) static void read_global_history(void) { + char *xdg_config_home = get_xdg_config_home(); char in_buffer[MAX_STR_LEN * 3]; char *title; FILE *f; @@ -335,8 +336,8 @@ read_global_history(void) || get_cmd_opt_bool("anonymous")) return; - if (elinks_home) { - char *file_name = straconcat(elinks_home, GLOBAL_HISTORY_FILENAME, + if (xdg_config_home) { + char *file_name = straconcat(xdg_config_home, GLOBAL_HISTORY_FILENAME, (char *) NULL); if (!file_name) return; @@ -375,16 +376,17 @@ read_global_history(void) static void write_global_history(void) { + char *xdg_config_home = get_xdg_config_home(); struct global_history_item *history_item; char *file_name; struct secure_save_info *ssi; - if (!global_history.dirty || !elinks_home + if (!global_history.dirty || !xdg_config_home || !get_globhist_enable() || get_cmd_opt_bool("anonymous")) return; - file_name = straconcat(elinks_home, GLOBAL_HISTORY_FILENAME, + file_name = straconcat(xdg_config_home, GLOBAL_HISTORY_FILENAME, (char *) NULL); if (!file_name) return; diff --git a/src/main/interlink.c b/src/main/interlink.c index abf9c792..0bc2f6e8 100644 --- a/src/main/interlink.c +++ b/src/main/interlink.c @@ -114,14 +114,16 @@ enum addr_type { static int get_sun_path(struct string *sun_path) { + char *xdg_config_home = get_xdg_config_home(); + assert(sun_path); if_assert_failed return 0; - if (!elinks_home) return 0; + if (!xdg_config_home) return 0; if (!init_string(sun_path)) return 0; - add_to_string(sun_path, elinks_home); + add_to_string(sun_path, xdg_config_home); add_to_string(sun_path, ELINKS_SOCK_NAME); add_long_to_string(sun_path, get_cmd_opt_int("session-ring")); diff --git a/src/network/ssl/ssl.c b/src/network/ssl/ssl.c index 75849cc8..c2ad3cd0 100644 --- a/src/network/ssl/ssl.c +++ b/src/network/ssl/ssl.c @@ -334,7 +334,7 @@ static union option_info gnutls_options[] = { * change the file name via the option manager. Distributors * of binary packages should of course change the default to * suit their systems. - * TODO: If the file name is relative, look in elinks_home? */ + * TODO: If the file name is relative, look in xdg_config_home? */ INIT_OPT_STRING("connection.ssl", N_("Trusted CA file"), "trusted_ca_file", OPT_ZERO, #ifdef HAVE_GNUTLS_CERTIFICATE_SET_X509_SYSTEM_TRUST diff --git a/src/scripting/guile/core.c b/src/scripting/guile/core.c index 689fba84..9951dc85 100644 --- a/src/scripting/guile/core.c +++ b/src/scripting/guile/core.c @@ -45,6 +45,7 @@ static char elguileversion[32]; void init_guile(struct module *module) { + char *xdg_config_home = get_xdg_config_home(); SCM user_module; char *path; @@ -53,12 +54,12 @@ init_guile(struct module *module) snprintf(elguileversion, 31, "Guile %s", scm_to_locale_string(scm_version())); module->name = elguileversion; - if (!elinks_home) return; + if (!xdg_config_home) return; /* Remember the current module. */ user_module = scm_current_module(); - path = straconcat(elinks_home, GUILE_HOOKS_FILENAME, + path = straconcat(xdg_config_home, GUILE_HOOKS_FILENAME, (char *) NULL); if (!path) return; @@ -81,7 +82,7 @@ init_guile(struct module *module) mem_free(path); - path = straconcat(elinks_home, GUILE_USERHOOKS_FILENAME, + path = straconcat(xdg_config_home, GUILE_USERHOOKS_FILENAME, (char *) NULL); if (!path) return; if (file_can_read(path)) diff --git a/src/scripting/lua/core.c b/src/scripting/lua/core.c index 3156c891..fc30012a 100644 --- a/src/scripting/lua/core.c +++ b/src/scripting/lua/core.c @@ -720,6 +720,8 @@ static char elluaversion[32]; void init_lua(struct module *module) { + char *xdg_config_home = get_xdg_config_home(); + L = luaL_newstate(); luaL_openlibs(L); @@ -741,12 +743,12 @@ init_lua(struct module *module) lua_register(L, "reload", l_reload); lua_register(L, "goto_url", l_goto_url); - lua_pushstring(L, elinks_home ? elinks_home + lua_pushstring(L, xdg_config_home ? xdg_config_home : (char *) CONFDIR); lua_setglobal(L, "elinks_home"); do_hooks_file(L, CONFDIR, LUA_HOOKS_FILENAME); - if (elinks_home) do_hooks_file(L, elinks_home, LUA_HOOKS_FILENAME); + if (xdg_config_home) do_hooks_file(L, xdg_config_home, LUA_HOOKS_FILENAME); strncpy(elluaversion, LUA_RELEASE, 31); module->name = elluaversion; diff --git a/src/scripting/perl/core.c b/src/scripting/perl/core.c index 3051249f..c9a8aa78 100644 --- a/src/scripting/perl/core.c +++ b/src/scripting/perl/core.c @@ -45,14 +45,14 @@ static char * get_local_hook_file(void) { static char buf[1024]; /* TODO: MAX_PATH ??? --Zas */ + char *xdg_config_home = get_xdg_config_home(); - if (!elinks_home) return NULL; - snprintf(buf, sizeof(buf), "%s%s", elinks_home, PERL_HOOKS_FILENAME); + if (!xdg_config_home) return NULL; + snprintf(buf, sizeof(buf), "%s%s", xdg_config_home, PERL_HOOKS_FILENAME); if (file_exists(buf)) return buf; return NULL; } - static void precleanup_perl(struct module *module) { diff --git a/src/scripting/python/core.c b/src/scripting/python/core.c index 19c8aa1d..78e434b5 100644 --- a/src/scripting/python/core.c +++ b/src/scripting/python/core.c @@ -101,11 +101,12 @@ set_python_search_path(void) struct string new_python_path; char *old_python_path; int result = -1; + char *xdg_config_home = get_xdg_config_home(); if (!init_string(&new_python_path)) return result; - if (elinks_home && !add_format_to_string(&new_python_path, "%s%c", - elinks_home, DELIM)) + if (xdg_config_home && !add_format_to_string(&new_python_path, "%s%c", + xdg_config_home, DELIM)) goto end; if (!add_to_string(&new_python_path, CONFDIR)) @@ -329,6 +330,7 @@ PyMODINIT_FUNC PyInit_elinks(void) { PyObject *elinks_module, *module_dict, *module_name; + char *xdg_config_home = get_xdg_config_home(); if (replace_showwarning() != 0) { goto python_error; @@ -344,9 +346,9 @@ PyInit_elinks(void) goto python_error; } - /* If @elinks_home is NULL, Py_BuildValue() returns a None reference. */ + /* If @xdg_config_home is NULL, Py_BuildValue() returns a None reference. */ if (PyModule_AddObject(elinks_module, "home", - Py_BuildValue("s", elinks_home)) != 0) { + Py_BuildValue("s", xdg_config_home)) != 0) { goto python_error; } diff --git a/src/scripting/ruby/core.c b/src/scripting/ruby/core.c index 64c8311b..508ab5f1 100644 --- a/src/scripting/ruby/core.c +++ b/src/scripting/ruby/core.c @@ -206,12 +206,12 @@ erb_module_method_missing(int argc, VALUE *argv, VALUE self) static void init_erb_module(void) { - char *home; + char *home = get_xdg_config_home(); erb_module = rb_define_module("ELinks"); rb_define_const(erb_module, "VERSION", rb_str_new2(VERSION_STRING)); - home = elinks_home ? elinks_home : (char *) CONFDIR; + home = home ?: (char *) CONFDIR; rb_define_const(erb_module, "HOME", rb_str_new2(home)); rb_define_module_function(erb_module, "message", (VALUE (*)(ANYARGS))erb_module_message, 1); @@ -225,6 +225,7 @@ static char elrubyversion[32]; void init_ruby(struct module *module) { + char *xdg_config_home = get_xdg_config_home(); char *path; /* Set up and initialize the interpreter. This function should be called @@ -243,8 +244,8 @@ init_ruby(struct module *module) snprintf(elrubyversion, 31, "Ruby %s", ruby_version); module->name = elrubyversion; - if (elinks_home) { - path = straconcat(elinks_home, RUBY_HOOKS_FILENAME, + if (xdg_config_home) { + path = straconcat(xdg_config_home, RUBY_HOOKS_FILENAME, (char *) NULL); } else { diff --git a/src/scripting/smjs/core.cpp b/src/scripting/smjs/core.cpp index a13eb079..e02e3783 100644 --- a/src/scripting/smjs/core.cpp +++ b/src/scripting/smjs/core.cpp @@ -121,11 +121,12 @@ static void smjs_load_hooks(void) { char *path; + char *xdg_config_home = get_xdg_config_home(); assert(smjs_ctx); - if (elinks_home) { - path = straconcat(elinks_home, SMJS_HOOKS_FILENAME, + if (xdg_config_home) { + path = straconcat(xdg_config_home, SMJS_HOOKS_FILENAME, (char *) NULL); } else { path = stracpy(CONFDIR STRING_DIR_SEP SMJS_HOOKS_FILENAME); diff --git a/src/scripting/smjs/elinks_object.cpp b/src/scripting/smjs/elinks_object.cpp index e69e311c..2c56344f 100644 --- a/src/scripting/smjs/elinks_object.cpp +++ b/src/scripting/smjs/elinks_object.cpp @@ -183,6 +183,7 @@ smjs_invoke_elinks_object_method(const char *method, int argc, JS::Value *argv, static bool elinks_get_property_home(JSContext *ctx, unsigned int argc, JS::Value *vp) { + char *xdg_config_home = get_xdg_config_home(); JS::CallArgs args = CallArgsFromVp(argc, vp); JS::RootedObject hobj(ctx, &args.thisv().toObject()); @@ -192,7 +193,7 @@ elinks_get_property_home(JSContext *ctx, unsigned int argc, JS::Value *vp) if (!JS_InstanceOf(ctx, hobj, (JSClass *) &elinks_class, NULL)) return false; - args.rval().setString(JS_NewStringCopyZ(smjs_ctx, elinks_home)); + args.rval().setString(JS_NewStringCopyZ(smjs_ctx, xdg_config_home)); return true; } diff --git a/src/session/session.cpp b/src/session/session.cpp index 4bec06a2..86289972 100644 --- a/src/session/session.cpp +++ b/src/session/session.cpp @@ -964,7 +964,9 @@ setup_first_session(struct session *ses, struct uri *uri) N_("Welcome"), ALIGN_CENTER, N_("Welcome to ELinks!\n\n" "Press ESC for menu. Documentation is available in " - "Help menu."), + "Help menu.\n" + "ATTENTION. Since 0.17.GIT configuration is read from and written to $XDG_CONFIG_HOME/elinks or ~/.config/elinks.\n" + "So if you did not copy it yet from ~/.elinks, do it now and start again."), ses, 1, MSG_BOX_BUTTON(N_("~OK"), (void (*)(void *))handler, B_ENTER | B_ESC)); diff --git a/src/terminal/mouse.c b/src/terminal/mouse.c index dec22986..b51aaa0c 100644 --- a/src/terminal/mouse.c +++ b/src/terminal/mouse.c @@ -88,7 +88,7 @@ disable_mouse(void) static int mouse_lock_exists(void) { - char *lock_filename = straconcat(empty_string_or_(elinks_home), "mouse.lock", (char *) NULL); + char *lock_filename = straconcat(empty_string_or_(get_xdg_config_home()), "mouse.lock", (char *) NULL); int res = 0; if (lock_filename) {