diff -Nru aumix-2.6.1/doc/aumix.1 aumix-2.6.1.new/doc/aumix.1 --- aumix-2.6.1/doc/aumix.1 Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/doc/aumix.1 Tue Jun 27 23:11:28 2000 @@ -115,15 +115,19 @@ go into interactive mode after doing things non-interactively. .It Fl L load settings from -.Pa $HOME/.aumixrc , -or +.Pa $CONFIG_DIR/aumixrc , +.Pa $HOME/.aumixrc +(depreciated), or .Pa /etc/aumixrc if the former is inaccessible .It Fl q query all devices and print their settings .It Fl S save settings to +.Pa $CONFIG_DIR/aumixrc +or .Pa $HOME/.aumixrc +(depreciated) .El .Sh EXAMPLES The command @@ -189,7 +193,10 @@ show a description of the functions of keys .It L or l load settings from -.Pa $HOME/.aumixrc , +.Pa $CONFIG_DIR/aumixrc , +or +.Pa $HOME/.aumixrc +(depreciated), falling back to .Pa /etc/aumixrc .It M or m @@ -264,8 +271,11 @@ Saved settings for the mixer are kept in the .Pa /etc/aumixrc and -.Pa $HOME/.aumixrc -files, but can be kept anywhere if specified explicitly. +.Pa $CONFIG_DIR/aumixrc +files, ( +.Pa $HOME/.aumixrc +is now obsolete, though it still works), +but can be kept anywhere if specified explicitly. Color schemes are normally kept in the directory given by .Ev DATADIR diff -Nru aumix-2.6.1/po/de.po aumix-2.6.1.new/po/de.po --- aumix-2.6.1/po/de.po Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/po/de.po Tue Jun 27 23:15:28 2000 @@ -206,12 +206,12 @@ msgid "" " 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 or /etc/aumixrc)\n" " h: this helpful message\n" msgstr "" " d: Anderes Gerät als /dev/mixer benutzen\n" " f: Spezifizieren Sie die Datei zum Speichern und Laden von Einstellungen\n" -" (Standard sind ~/.aumixrc oder /etc/aumixrc)\n" +" (Standard sind $CONFIG_DIR/aumixrc oder /etc/aumixrc) or /etc/aumixrc)\n" " h: Diese nützlichen Informationen\n" #: src/common.c:689 diff -Nru aumix-2.6.1/po/es.po aumix-2.6.1.new/po/es.po --- aumix-2.6.1/po/es.po Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/po/es.po Tue Jun 27 23:14:48 2000 @@ -206,12 +206,12 @@ msgid "" " 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 or /etc/aumixrc)\n" " h: this helpful message\n" msgstr "" " d: ajustar dispositivos además de /dev/mixer\n" " f: indicar el fichero para guardar y cargar las preferencias (por\n" -" defecto es ~/.aumixrc o /etc/aumixrc\n" +" defecto es $CONFIG_DIR/aumixrc o /etc/aumixrc\n" " h: este mensaje de ayuda\n" #: src/common.c:689 diff -Nru aumix-2.6.1/po/fr.po aumix-2.6.1.new/po/fr.po --- aumix-2.6.1/po/fr.po Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/po/fr.po Tue Jun 27 23:15:18 2000 @@ -206,12 +206,12 @@ msgid "" " 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 or /etc/aumixrc)\n" " h: this helpful message\n" msgstr "" " d: ajuster un périphérique autre que /dev/mixer\n" " f: spécifier le fichier de sauvegarde/chargement des paramètres\n" -" (par défaut il s'agit de ~/.aumixrc ou /etc/aumixrc)\n" +" (par défaut il s'agit de $CONFIG_DIR/aumixrc ou /etc/aumixrc)\n" " h: ce message d'aide\n" #: src/common.c:689 diff -Nru aumix-2.6.1/po/gl.po aumix-2.6.1.new/po/gl.po --- aumix-2.6.1/po/gl.po Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/po/gl.po Tue Jun 27 23:14:38 2000 @@ -214,12 +214,12 @@ msgid "" " 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 or /etc/aumixrc)\n" " h: this helpful message\n" msgstr "" " d: axustar outro dispositivo que non sexa /dev/mixer\n" " f: especificar ficheiro para gardar e cargar parámetros (por omisión é\n" -" ~/.aumixrc ou /etc/aumixrc)\n" +" $CONFIG_DIR/aumixrc ou /etc/aumixrc)\n" " h: amosar esta mensaxe de axuda\n" #: src/common.c:689 diff -Nru aumix-2.6.1/po/pl.po aumix-2.6.1.new/po/pl.po --- aumix-2.6.1/po/pl.po Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/po/pl.po Tue Jun 27 23:16:16 2000 @@ -210,12 +210,12 @@ msgid "" " 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 or /etc/aumixrc)\n" " h: this helpful message\n" msgstr "" " d: dostosowuje urz±dzenie inne ni¿ /dev/mixer\n" " f: okre¶la plik do zapisywania i ³adowania ustawieñ (domy¶lnie jest to\n" -" ~/.aumixrc lub /etc/aumixrc)\n" +" $CONFIG_DIR/aumixrc lub /etc/aumixrc)\n" " h: ta pomocna informacja\n" #: src/common.c:689 diff -Nru aumix-2.6.1/po/pt_BR.po aumix-2.6.1.new/po/pt_BR.po --- aumix-2.6.1/po/pt_BR.po Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/po/pt_BR.po Tue Jun 27 23:14:27 2000 @@ -212,12 +212,12 @@ msgid "" " 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 or /etc/aumixrc)\n" " h: this helpful message\n" msgstr "" " d: usar outro dispositivo que não o /dev/mixer\n" " f: SPECIFY FILE FOR SAVING AND LOADING SETTINGS (DEFAULTS TO\n" -" ~/.aumixrc or /etc/aumixrc)\n" +" $CONFIG_DIR/aumixrc or /etc/aumixrc)\n" " h: esta mensagem de ajuda\n" #: src/common.c:689 diff -Nru aumix-2.6.1/po/ru.po aumix-2.6.1.new/po/ru.po --- aumix-2.6.1/po/ru.po Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/po/ru.po Tue Jun 27 23:16:07 2000 @@ -210,12 +210,12 @@ msgid "" " 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 or /etc/aumixrc)\n" " h: this helpful message\n" msgstr "" " d: ÒÅÇÕÌÉÒÏ×ÁÔØ ÕÓÔÒÏÊÓÔ×Á ËÒÏÍÅ /dev/mixer\n" " f: ÕËÁÚÁÎÉÅ ÉÍÅÎÉ ÆÁÊÌÁ ÄÌÑ ÈÒÁÎÅÎÉÑ ÕÓÔÁÎÏ×ÏË (ÐÏ ÕÍÏÌÞÁÎÉÀ\n" -" ~/.aumixrc ÉÌÉ /etc/aumixrc)\n" +" $CONFIG_DIR/aumixrc ÉÌÉ /etc/aumixrc)\n" " h: ÜÔÁ ÐÏÍÏÝØ\n" #: src/common.c:689 diff -Nru aumix-2.6.1/po/uk.po aumix-2.6.1.new/po/uk.po --- aumix-2.6.1/po/uk.po Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/po/uk.po Tue Jun 27 23:14:13 2000 @@ -212,12 +212,12 @@ msgid "" " 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 or /etc/aumixrc)\n" " h: this helpful message\n" msgstr "" " d: ÒÅÇÕÌÀ×ÁÔÉ ÐÒÉÓÔÒϧ ÏËÒ¦Í /dev/mixer\n" " f: ×ËÁÚÁÎÎÑ ¦ÍÅΦ ÆÁÊÌÕ ÄÌÑ ÚÂÅÒ¦ÇÁÎÎÑ Ò¦×Î¦× (ÚÁ ÚÁÍÏ×ÞÁÎÎÑÍ\n" -" ~/.aumixrc ÞÉ /etc/aumixrc)\n" +" $CONFIG_DIR/aumixrc ÞÉ /etc/aumixrc)\n" " h: ÃÑ ÄÏÐÏÍÏÇÁ\n" #: src/common.c:689 diff -Nru aumix-2.6.1/src/Makefile.am aumix-2.6.1.new/src/Makefile.am --- aumix-2.6.1/src/Makefile.am Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/src/Makefile.am Wed Jun 28 00:12:13 2000 @@ -2,8 +2,8 @@ if CURSES bin_SCRIPTS = xaumix endif -aumix_SOURCES = common.c curses.c dummy.c gpm-xterm.c gtk.c interactive.c \ - mouse.c common.h curses.h gpm-xterm.h gtk.h interactive.h \ +aumix_SOURCES = userdir.c common.c curses.c dummy.c gpm-xterm.c gtk.c interactive.c \ + mouse.c userdir.h common.h curses.h gpm-xterm.h gtk.h interactive.h \ mouse.h play.xpm record.xpm localedir = $(datadir)/locale INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\" -I@includedir@ diff -Nru aumix-2.6.1/src/Makefile.in aumix-2.6.1.new/src/Makefile.in --- aumix-2.6.1/src/Makefile.in Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/src/Makefile.in Tue Jun 27 23:11:28 2000 @@ -100,7 +100,7 @@ CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ -aumix_OBJECTS = common.o curses.o dummy.o gpm-xterm.o gtk.o \ +aumix_OBJECTS = userdir.o common.o curses.o dummy.o gpm-xterm.o gtk.o \ interactive.o mouse.o aumix_LDADD = $(LDADD) aumix_DEPENDENCIES = diff -Nru aumix-2.6.1/src/common.c aumix-2.6.1.new/src/common.c --- aumix-2.6.1/src/common.c Tue Jun 27 23:11:47 2000 +++ aumix-2.6.1.new/src/common.c Wed Jun 28 00:10:45 2000 @@ -26,6 +26,7 @@ #include "gtk.h" #endif /* HAVE_GTK */ #include "interactive.h" +#include "userdir.h" FILE *OpenDefaultFile(char *mode); FILE *setfile; @@ -556,7 +557,8 @@ { /* Open the settings file for reading or writing. - Try first ${HOME}/.AUMIXRC, then AUMIXRC_PATH/AUMIXRC; + Try first ${HOME}/.AUMIXRC, then then ${HOME}/.AUMIXRC + and eventualy AUMIXRC_PATH/AUMIXRC; become an error generator if neither can be opened. Input: @@ -571,6 +573,8 @@ FILE *setfile; char *home; char filename[FILENAME_MAX]; + struct cfv etcfile; + if (save_filename == NULL) { home = getenv("HOME"); if ((strlen(home) + strlen(AUMIXRC)) < PATH_MAX) { @@ -585,6 +589,19 @@ } 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; + + setfile = fopencfv(&etcfile, mode); + if (setfile == NULL) { + sprintf(filename, "%s/%s", AUMIXRC_PATH, AUMIXRC); + setfile = fopen(filename, mode); } } else setfile = fopen(save_filename, mode); diff -Nru aumix-2.6.1/src/userdir.c aumix-2.6.1.new/src/userdir.c --- aumix-2.6.1/src/userdir.c Thu Jan 1 01:00:00 1970 +++ aumix-2.6.1.new/src/userdir.c Tue Jun 27 23:11:28 2000 @@ -0,0 +1,167 @@ +// $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; /* remember, it works for errors! */ + /* get the 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 *maynullfopencfv (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); + } + +/******************************************************************************/ + +FILE *fopencfv (struct cfv *CFV, const char *mode) + { + FILE *cfvfile = NULL; + + if (cfvfile == NULL && (strpbrk(mode, "wa")) != NULL) /* create in best location */ + cfvfile = notnullfopencfv (CFV, mode); + else + cfvfile = maynullfopencfv (CFV, mode); + + return (cfvfile); + } + +/******************************************************************************/ \ No newline at end of file diff -Nru aumix-2.6.1/src/userdir.h aumix-2.6.1.new/src/userdir.h --- aumix-2.6.1/src/userdir.h Thu Jan 1 01:00:00 1970 +++ aumix-2.6.1.new/src/userdir.h Tue Jun 27 23:11:28 2000 @@ -0,0 +1,56 @@ +// $Id$ +#ifndef USERDIR__H +#define USERDIR__H + +#include +#include +#include +#include +#include +#include +#include + +#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 *maynullfopencfv (struct cfv *CFV, const char *mode); +FILE *notnullfopencfv (struct cfv *CFV, const char *mode); + +#endif