From: Fredrik Tolf Date: Sat, 23 Mar 2013 04:20:51 +0000 (+0100) Subject: lib: Add $HOME/.ashd/etc to the directories to search for slash-less files. X-Git-Tag: 0.12~2 X-Git-Url: http://www.dolda2000.com/gitweb/?p=ashd.git;a=commitdiff_plain;h=f9a65eb249034b28f604dce099deb1a622d373cf lib: Add $HOME/.ashd/etc to the directories to search for slash-less files. --- diff --git a/doc/dirplex.doc b/doc/dirplex.doc index 10b7609..c38ff4a 100644 --- a/doc/dirplex.doc +++ b/doc/dirplex.doc @@ -85,12 +85,13 @@ CONFIGURATION Configuration in *dirplex* comes from several sources. When *dirplex* starts, unless the *-N* option is given, it tries to find a global -configuration file named `dirplex.rc`. It looks in all directories -named by the *PATH* environment variable, appended with -`../etc/ashd`. For example, then, if *PATH* is -`/usr/local/bin:/bin:/usr/bin`, the directories `/usr/local/etc/ashd`, -`/etc/ashd` and `/usr/etc/ashd` are searched for `dirplex.rc`, in that -order. Only the first file found is used, should there exist several. +configuration file named `dirplex.rc`. It looks in `$HOME/.ashd/etc`, +and then in all directories named by the *PATH* environment variable, +appended with `../etc/ashd`. For example, then, if *PATH* is +`/usr/local/bin:/bin:/usr/bin`, the directories `$HOME/.ashd/etc`, +`/usr/local/etc/ashd`, `/etc/ashd` and `/usr/etc/ashd` are searched +for `dirplex.rc`, in that order. Only the first file found is used, +should there exist several. If the *-c* option is given to *dirplex*, it too specifies a configuration file to load. If the name given contains any slashes, it diff --git a/doc/patplex.doc b/doc/patplex.doc index dff248b..be3da48 100644 --- a/doc/patplex.doc +++ b/doc/patplex.doc @@ -35,15 +35,16 @@ CONFIGURATION In addition to the 'CONFIGFILE' specified on the command-line, *patplex* also attempts to find and read a global configuration file -called `patplex.rc`, unless the *-N* option is given. It looks in all -directories named by the *PATH* environment variable, appended with -`../etc/ashd`. For example, then, if *PATH* is -`/usr/local/bin:/bin:/usr/bin`, the directories `/usr/local/etc/ashd`, -`/etc/ashd` and `/usr/etc/ashd` are searched for `patplex.rc`, in that -order. Only the first file found is used, should there exist -several. If the given 'CONFIGFILE' contains any slashes, it is opened -by that exact name. Otherwise, it is searched for in the same manner -as the global configuration file. +called `patplex.rc`, unless the *-N* option is given. It looks in +`$HOME/.ashd/etc`, and then in all directories named by the *PATH* +environment variable, appended with `../etc/ashd`. For example, then, +if *PATH* is `/usr/local/bin:/bin:/usr/bin`, the directories +`$HOME/.ashd/etc`, `/usr/local/etc/ashd`, `/etc/ashd` and +`/usr/etc/ashd` are searched for `patplex.rc`, in that order. Only the +first file found is used, should there exist several. If the given +'CONFIGFILE' contains any slashes, it is opened by that exact +name. Otherwise, it is searched for in the same manner as the global +configuration file. Should the global and the given configuration files conflict, the directives from the given file take precedence. diff --git a/lib/cf.c b/lib/cf.c index ba63999..f5defd7 100644 --- a/lib/cf.c +++ b/lib/cf.c @@ -233,22 +233,27 @@ void freecfparser(struct cfstate *s) char *findstdconf(char *name) { - char *path, *p, *p2, *t; + char *home, *path, *p, *p2, *t; - if((path = getenv("PATH")) == NULL) - return(NULL); - path = sstrdup(path); - for(p = strtok(path, ":"); p != NULL; p = strtok(NULL, ":")) { - if((p2 = strrchr(p, '/')) == NULL) - continue; - *p2 = 0; - if(!access(t = sprintf2("%s/etc/%s", p, name), R_OK)) { - free(path); + if((home = getenv("HOME")) != NULL) { + if(!access(t = sprintf2("%s/.ashd/etc/%s", home, name), R_OK)) return(t); - } free(t); } - free(path); + if((path = getenv("PATH")) != NULL) { + path = sstrdup(path); + for(p = strtok(path, ":"); p != NULL; p = strtok(NULL, ":")) { + if((p2 = strrchr(p, '/')) == NULL) + continue; + *p2 = 0; + if(!access(t = sprintf2("%s/etc/%s", p, name), R_OK)) { + free(path); + return(t); + } + free(t); + } + free(path); + } return(NULL); }