+- Try first ${HOME}/.AUMIXRC, then AUMIXRC_PATH/AUMIXRC;
++ Try first ${CONFIG_DIR}/AUMIXRC, then ${HOME}/.AUMIXRC
++ and eventually AUMIXRC_PATH/AUMIXRC;
+ become an error generator if neither can be opened.
+
+ Input:
+@@ -548,22 +550,34 @@
+ Success: pointer to the default settings file structure
+ Failure: NULL
+ */
+- FILE *setfile;
++ FILE *setfile = NULL;
+ char *home;
+ char filename[FILENAME_MAX];
++ struct cfv etcfile;
++
+ if (save_filename == NULL) {
+- home = getenv("HOME");
+- sprintf(filename, "%s/.%s", home, AUMIXRC);
+- setfile = fopen(filename, mode);
+- if (setfile == NULL) {
+- sprintf(filename, "%s/%s", AUMIXRC_PATH, AUMIXRC);
+- setfile = fopen(filename, mode);
+- }
+- if (setfile == NULL) {
+- return NULL;
+- }
++ etcfile.variable = "CONFIG_DIR";
++ etcfile.home_dir = NULL;
++ etcfile.home_scd = NULL;
++ etcfile.subname = AUMIXRC;
++ etcfile.prefix = ".";
++ etcfile.suffix = "";
++ etcfile.mode = M_REGULAR_FILE;
++
++ if ((usercfv (&etcfile)) == -1)
++ setfile = notnullfopencfv(&etcfile, mode);
++ else
++ setfile = fopen(etcfile.result, mode);
++
++ if (setfile == NULL) {
++ sprintf(filename, "%s/%s", AUMIXRC_PATH, AUMIXRC);
++ setfile = fopen(filename, mode);
++ }
++ if (setfile == NULL)
++ return NULL;
++
+ } else
+- setfile = fopen(save_filename, mode);
++ setfile = fopen(save_filename, mode);
+ return setfile;
+ }
+
+@@ -649,7 +663,7 @@
+ other options:\n\
+ d: adjust a device besides /dev/mixer\n\
+ f: specify file for saving and loading settings (defaults to\n\
+- ~ /.aumixrc or /etc/aumixrc)\n\
++ $CONFIG_DIR/aumixrc, ~/.aumixrc or /etc/aumixrc)\n\
+ C: specify color scheme\n\
+ h: this helpful message\n"));
+ #ifdef HAVE_CURSES
+--- aumix-2.1/src/userdir.c Thu Jan 1 01:00:00 1970
++++ aumix-2.1.pius/src/userdir.c Thu Feb 3 01:24:28 2000
+@@ -0,0 +1,146 @@
++// $Id$
++#include "userdir.h"
++
++static char *nonulhome = "";
++
++/******************************************************************************/
++
++int getusercfv (char *variable,
++ char *home_dir,
++ char *user_dir,
++ size_t stringsize)
++{
++ struct stat st;
++ char *d;
++
++ bzero (user_dir, stringsize);
++ if (variable == NULL || *variable == '\0') return (-1);
++ if (home_dir == NULL) home_dir = nonulhome;
++ d = getenv (variable);
++ if (d == NULL || *d == '\0') return (-1);
++ if (*d == '/')
++ {
++ strncpy (user_dir, d, stringsize-1);
++ }
++ else
++ {
++ snprintf (user_dir, stringsize-1, "%s/%s", home_dir, d);
++ }
++
++ if (stat(user_dir,&st) != -1 && S_ISDIR(st.st_mode))
++ {
++ return (0);
++ }
++
++ return (-1);
++}
++
++/******************************************************************************/
++
++int detectcfv(struct cfv *CFV) {
++ if (CFV->subname == NULL) CFV->subname = nonulhome;
++ if (CFV->home_dir == NULL) CFV->home_dir = getenv ("HOME");
++ if (CFV->home_dir == NULL) CFV->home_dir = CFV->home_scd;
++ if (CFV->home_dir == NULL) return (-1);
++ return 0;
++}
++
++int preparemain(struct cfv *CFV) {
++ char *p;
++ struct stat st;
++ if ((p = strrchr(CFV->result, '/')) && *(p+1) == '\0')
++ p = '\0';
++ snprintf ((rindex(CFV->result,'\0')), MAXPATHLEN-1, "/%s",
++ CFV->subname);
++ if (stat( CFV->result,&st) != -1
++ && CFV->mode ?
++ S_ISDIR(st.st_mode) :
++ S_ISREG(st.st_mode)) /* have file or dir */
++ return (1);
++ return 0;
++}
++
++int preparehome(struct cfv *CFV) {
++ struct stat st;
++ if (CFV->home_dir == NULL || *(CFV->home_dir) == '\0') return (-1);
++ if (CFV->prefix == NULL && CFV->suffix == NULL) return (-1);
++ snprintf (CFV->result, MAXPATHLEN-1, "%s/%s%s%s",
++ CFV->home_dir,
++ CFV->prefix? CFV->prefix:"",
++ CFV->subname,
++ CFV->suffix? CFV->suffix:"");
++ if (stat(CFV->result,&st) != -1
++ && CFV->mode ?
++ S_ISDIR(st.st_mode) :
++ S_ISREG(st.st_mode)) /* have file or dir */
++ return (2);
++ return (-1);
++}
++
++int usercfv (struct cfv *CFV) {
++ int gr;
++ gr = detectcfv(CFV);
++ if (gr) return gr;
++ /* get environment variable */
++ gr = getusercfv (CFV->variable,
++ CFV->home_dir,
++ CFV->result,
++ MAXPATHLEN);
++ if (gr != -1) /* have main directory */
++ {
++ gr = preparemain(CFV);
++ if (gr) return gr;
++ }
++ /* don't have main directory or a proper variable set */
++ gr = preparehome(CFV);
++ return gr;
++}
++
++/******************************************************************************/
++
++/* If directory or file doesn't exist returns the best one wich may be created*/
++int notnullusercfv (struct cfv *CFV) {
++ int gr;
++ if ((usercfv(CFV)) == -1) {
++ gr = detectcfv(CFV);
++ if (gr) return gr;
++ /* get environment variable */
++ gr = getusercfv (CFV->variable,
++ CFV->home_dir,
++ CFV->result,
++ MAXPATHLEN);
++ if (gr != -1) /* have main directory */
++ {
++ gr = preparemain(CFV);
++ return 0;
++ }
++ /* don't have main directory or a proper variable set */
++ gr = preparehome(CFV);
++ return 0;
++ }
++ return 0;
++}
++
++/******************************************************************************/
++
++FILE *fopencfv (struct cfv *CFV, const char *mode)
++ {
++ FILE *cfvfile = NULL;
++
++ CFV->mode = M_REGULAR_FILE;
++ if ((usercfv (CFV)) == -1) return (NULL);
++ cfvfile = fopen (CFV->result, mode);
++ return (cfvfile);
++ }
++/******************************************************************************/
++
++FILE *notnullfopencfv (struct cfv *CFV, const char *mode)
++ {
++ FILE *cfvfile = NULL;
++
++ CFV->mode = M_REGULAR_FILE;
++ if ((notnullusercfv (CFV)) == -1) return (NULL);
++ cfvfile = fopen (CFV->result, mode);
++ return (cfvfile);
++ }
++
+--- aumix-2.1/src/userdir.h Thu Jan 1 01:00:00 1970
++++ aumix-2.1.pius/src/userdir.h Thu Feb 3 01:58:57 2000
+@@ -0,0 +1,55 @@
++// $Id$
++#ifndef USERDIR__H
++#define USERDIR__H
++
++#include <unistd.h>
++#include <string.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <sys/param.h>
++
++#define M_REGULAR_FILE 0
++#define M_DIRECTORY 1
++
++struct cfv {
++ char result[MAXPATHLEN]; /* our result */
++ char *variable; /* name of an environment variable */
++ char *home_dir; /* home directory or NULL for autodetect */
++ char *home_scd; /* directory if home_dir==NULL and no result */
++ char *subname; /* core name of a file/directory */
++ char *prefix; /* prefix when using directly home_dir */
++ char *suffix; /* suffix when using directly home_dir */
++ int mode; /* expected: M_REGULAR_FILE or M_DIRECTORY */
++ };
++
++/* reads environment variable. if the path isn't absolute will add $HOME/
++ * at the beginning
++ * return: 0 - directory exists
++ * -1 - directory doesn't exist
++ */
++int getusercfv (char *variable,
++ char *home_dir,
++ char *user_dir,
++ size_t stringsize);
++/* reads the $HOME variable */
++int detectcfv(struct cfv *CFV);
++
++/* looks for the config/data file/dir.
++ * result: -1 - error - cannot find file/dir
++ * 0 - ok
++ * CFV.result set
++ */
++int usercfv (struct cfv *CFV);
++/* looks for the config/data file/dir.
++ * result: -1 - error - cannot read $HOME
++ * 0 - ok - if the CFV.result exists, read it. If not create it.
++ * CFV.result set
++ */
++int notnullusercfv (struct cfv *CFV);
++
++FILE *fopencfv (struct cfv *CFV, const char *mode);
++FILE *notnullfopencfv (struct cfv *CFV, const char *mode);
++
++#endif
+--- aumix-2.1/po/aumix.pot Mon Jan 31 23:30:12 2000
++++ aumix-2.1.pius/po/aumix.pot Fri Feb 4 01:11:42 2000
+@@ -175,7 +175,7 @@