diff --git a/GUI/xephem/help/xephem.html b/GUI/xephem/help/xephem.html index 574d346..d1fec8e 100644 --- a/GUI/xephem/help/xephem.html +++ b/GUI/xephem/help/xephem.html @@ -559,6 +559,11 @@ resources then exit

1.3.1 Shared and Private Directories

When XEphem is launched it looks for a file named xephemrc in the user's $HOME/.config directory (or +the location specified by the $XDG_CONFIG_HOME +environment variable), or if that doesn't exist, .xephemrc in the user's $HOME directory. This file is optional. If it exists, it should contain a line with the following @@ -576,10 +581,13 @@ A leading "." in the file name can be used to refer to the current working directory of the running program. The example above causes the Private directory to be .xephem in the users $HOME -directory. If .xephemrc -does not exist or does not contain this line the default Private -directory is ~/.xephem. -The private directory will be created if it does not already exist.
+directory. If xephemrc +does not exist or does not contain this line XEphem will first search for +the Private directory at ~/.xephem, +followed by ~/.config/xephem. +The private directory will be created in one of those locations if it doe +not already exist, depending on whether the +~/.config directory exists.

XEphem then also searches for another directory for Shared files. This directory contains files presumed to be shared diff --git a/GUI/xephem/homeio.c b/GUI/xephem/homeio.c index 8fd0300..1a597b0 100644 --- a/GUI/xephem/homeio.c +++ b/GUI/xephem/homeio.c @@ -31,6 +31,9 @@ expand_home (char *path) char *p; int l; + if (!path) + return NULL; + /* get home, if we don't already know it */ if (!home) { home = getenv ("HOME"); diff --git a/GUI/xephem/saveres.c b/GUI/xephem/saveres.c index c722a95..9e35759 100644 --- a/GUI/xephem/saveres.c +++ b/GUI/xephem/saveres.c @@ -172,6 +172,9 @@ static char mydirdef[] = "~/.xephem"; static char mdovride[] = "~/.xephemrc"; static char mdres[] = "XEphem.PrivateDir"; #endif +static char xdgprivdir[] = "xephem"; +static char xdgovride[] = "xephemrc"; +static char dotconfig[] = "~/.config"; #define RESWID 45 /* columns for resource name, if possible */ #define PGWID 75 /* overall number of default columns */ @@ -930,13 +933,49 @@ sr_getDirPM (Pixmap *pmopen, Pixmap *pmclose) *pmclose = nomore_pm; } +/* Returns a full path in the directory specified by $XDG_CONFIG_HOME, or + * $HOME/.config if not set. Passing NULL returns the root of the directory. + */ +static char * +getXdgConfigPath (const char *subpath) +{ + static char *xdgconfig; + unsigned pathlen; + char *path; + + if (!xdgconfig) + xdgconfig = getenv("XDG_CONFIG_HOME"); + if (!xdgconfig) + xdgconfig = XtNewString(expand_home(dotconfig)); + + if (!subpath) { + path = XtNewString(xdgconfig); + } else { + pathlen = (unsigned)(strlen(xdgconfig) + strlen(subpath) + 2); + path = XtMalloc(pathlen); + snprintf(path, pathlen, "%s/%s", xdgconfig, subpath); + } + + return path; +} + /* return full path of per-user working directory, * allowing for possible override. + * Directories are searched in this order: + * 1. Directory specified by $HOME/.xephemrc + * 2. Directory specified by $XDG_CONFIG_HOME/xephemrc or $home/.config/xephemrc + * 3. $HOME/.xephem + * 4. $XDG_CONFIG_HOME/xephem or $HOME/.config/xephem + * If none of these directories exists, a new one is created: + * 1. If $XDG_CONFIG_HOME or $HOME/.config exists, create xephem directory there + * 2. if not, create .xephem directory in $HOME */ char * getPrivateDir (void) { static char *mydir; + char *xdgdir; + char *ovride = mdovride; if (!mydir) { /* try mdovride else use default */ @@ -944,6 +983,13 @@ getPrivateDir (void) char *vhome, *vp = NULL; char nam[MRNAM], val[MLL], buf[MLL]; +#if !defined(__APPLE__) || !defined(__VMS) + if (!ofp) { + ovride = getXdgConfigPath(xdgovride); + ofp = fopenh (ovride, "r"); + } +#endif + if (ofp) { while (fgets (buf, sizeof(buf), ofp)) { if (!crackNam (buf, nam) && !strcmp (nam, mdres) && @@ -954,13 +1000,24 @@ getPrivateDir (void) } fclose(ofp); if (!vp) - fprintf (stderr, "%s: %s not found. Using %s\n", - mdovride, mdres, mydirdef); + fprintf (stderr, "%s: %s not found. Trying default dirs\n", + ovride, mdres); } + if (!vp) vp = mydirdef; vhome = expand_home(vp); mydir = XtNewString (vhome); /* macro! */ + +#if !defined(__APPLE__) || !defined(__VMS) + xdgdir = getXdgConfigPath(NULL); + if (access (mydir, X_OK) < 0 && access (xdgdir, X_OK) == 0) { + XtFree (mydir); + mydir = getXdgConfigPath(xdgprivdir); + } + XtFree (xdgdir); +#endif + if (access (mydir, X_OK) < 0 && mkdir (mydir, 0744) < 0) { /* don't try and fake it */ printf ("%s: %s\n", mydir, syserrstr()); diff --git a/GUI/xephem/xephem.1 b/GUI/xephem/xephem.1 index e85a7f4..28c1bd0 100644 --- a/GUI/xephem/xephem.1 +++ b/GUI/xephem/xephem.1 @@ -126,15 +126,22 @@ references; version number and the Copyright statement. .SH X Resources When first started, XEphem looks for a file named .B .xephemrc -in your $HOME directory. It should contain one line of the form: +in your $HOME directory, or if that doesn't exist, +.B xephemrc +in your $HOME/.config directory. It should contain one line of the form: XEphem.PrivateDir: ~/.xephem This defines the Private directory, where XEphem will store your personal -settings. The example line shown here, which is also the assumption if the -file is not present, means XEphem will create and use a directory named +settings. The example line shown here means XEphem will create and use a +directory named .B .xephem -for this purpose in your home directory. +for this purpose in your home directory. If the file is not present, the +XEphem will look for the directory in +.B $HOME/.xephem +first, followed by +.B $HOME/.config/xephem +if that does not exist. If neither exists, a new directory will be created. Within this directory a text file named .B XEphem