- corrected a silly mistake
[packages/aumix-gtk.git] / aumix-home_etc.patch
CommitLineData
ac9fa1ac 1--- aumix-2.1/doc/aumix.1 Mon Jan 31 23:30:12 2000
2+++ aumix-2.1.pius/doc/aumix.1 Fri Feb 4 00:50:48 2000
3@@ -115,7 +115,8 @@
7476d76d 4 go into interactive mode after doing things non-interactively.
5 .It Fl L
ac9fa1ac 6 load settings from
7-.Pa $HOME/.aumixrc ,
8-or
9+.Pa $CONFIG_DIR/aumixrc ,
10+.Pa $HOME/.aumixrc
11+(depreciated), or
12 .Pa /etc/aumixrc
13 if the former is inaccessible
14@@ -123,7 +125,10 @@
7476d76d 15 query all devices and print their settings
16 .It Fl S
ac9fa1ac 17 save settings to
18-.Pa $HOME/.aumixrc
19+.Pa $CONFIG_DIR/aumixrc
20+or
21+.Pa $HOME/.aumixrc
22+(depreciated)
7476d76d 23 .El
7476d76d 24 .Sh EXAMPLE
ac9fa1ac 25 The command
26@@ -179,7 +184,10 @@
7476d76d 27 show a description of the functions of keys
ac9fa1ac 28 .It L or l
29 load settings from
30-.Pa $HOME/.aumixrc ,
31+.Pa $CONFIG_DIR/aumixrc ,
32+or
33+.Pa $HOME/.aumixrc
34+(depreciated),
35 falling back to
36 .Pa /etc/aumixrc
37 .It M or m
38@@ -247,8 +255,11 @@
39 Saved settings for the mixer are kept in the
40 .Pa /etc/aumixrc
41 and
42-.Pa $HOME/.aumixrc
43-files, but can be kept anywhere if specified explicitly.
44+.Pa $CONFIG_DIR/aumixrc
45+files, (
46+.Pa $HOME/.aumixrc
47+is now obsolete, though it still works),
48+but can be kept anywhere if specified explicitly.
49 Color schemes are normally kept in the directory given
50 by
51 .Ev DATADIRNAME
52--- aumix-2.1/src/Makefile.am Sat Dec 25 17:53:54 1999
53+++ aumix-2.1.pius/src/Makefile.am Thu Feb 3 16:26:12 2000
54@@ -1,8 +1,8 @@
55 bin_PROGRAMS = aumix
56 bin_SCRIPTS = xaumix
57-aumix_SOURCES = common.c curses.c dummy.c gpm-xterm.c gtk.c interactive.c \
58- mouse.c common.h curses.h gpm-xterm.h gtk.h interactive.h \
59- mouse.h
60+aumix_SOURCES = userdir.c common.c curses.c dummy.c gpm-xterm.c gtk.c \
61+ interactive.c mouse.c userdir.h common.h curses.h gpm-xterm.h \
62+ gtk.h interactive.h mouse.h
63 localedir = $(datadir)/locale
64 INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\" -I@includedir@
65 CFLAGS = @CFLAGS@ @GLIB_CFLAGS@ @GTK_CFLAGS@
66--- aumix-2.1/src/Makefile.in Mon Jan 31 23:19:53 2000
67+++ aumix-2.1.pius/src/Makefile.in Thu Feb 3 16:25:03 2000
68@@ -84,7 +84,7 @@
69
70 bin_PROGRAMS = aumix
71 bin_SCRIPTS = xaumix
72-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 mouse.h
73+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
74
75 localedir = $(datadir)/locale
76 INCLUDES = -I../intl -DLOCALEDIR=\"$(localedir)\" -I@includedir@
77@@ -99,7 +99,7 @@
78
79 CPPFLAGS = @CPPFLAGS@
80 LDFLAGS = @LDFLAGS@
81-aumix_OBJECTS = common.o curses.o dummy.o gpm-xterm.o gtk.o \
82+aumix_OBJECTS = userdir.o common.o curses.o dummy.o gpm-xterm.o gtk.o \
83 interactive.o mouse.o
84 aumix_LDADD = $(LDADD)
85 aumix_DEPENDENCIES =
86--- aumix-2.1/src/common.c Mon Jan 31 23:30:12 2000
87+++ aumix-2.1.pius/src/common.c Thu Feb 3 23:51:47 2000
88@@ -24,6 +24,7 @@
89 #include "gtk.h"
90 #endif
91 #include "interactive.h"
92+#include "userdir.h"
93
94 void ExitIfError(int error);
95 int InitializeMixer(char *device_file);
96@@ -536,7 +537,8 @@
97 {
98 /* Open the settings file for reading or writing.
7476d76d 99
ac9fa1ac 100- Try first ${HOME}/.AUMIXRC, then AUMIXRC_PATH/AUMIXRC;
101+ Try first ${CONFIG_DIR}/AUMIXRC, then ${HOME}/.AUMIXRC
102+ and eventually AUMIXRC_PATH/AUMIXRC;
103 become an error generator if neither can be opened.
104
105 Input:
8c3304d6 106@@ -545,19 +547,31 @@
107 FILE *setfile;
ac9fa1ac 108 char *home;
109 char filename[FILENAME_MAX];
110+ struct cfv etcfile;
111+
112 if (save_filename == NULL) {
113- home = getenv("HOME");
114- sprintf(filename, "%s/.%s", home, AUMIXRC);
115- setfile = fopen(filename, mode);
116- if (setfile == NULL) {
117- sprintf(filename, "%s/%s", AUMIXRC_PATH, AUMIXRC);
118- setfile = fopen(filename, mode);
119- }
120- if (setfile == NULL) {
121- return NULL;
122- }
123+ etcfile.variable = "CONFIG_DIR";
124+ etcfile.home_dir = NULL;
125+ etcfile.home_scd = NULL;
126+ etcfile.subname = AUMIXRC;
127+ etcfile.prefix = ".";
128+ etcfile.suffix = "";
129+ etcfile.mode = M_REGULAR_FILE;
130+
131+ if ((usercfv (&etcfile)) == -1)
132+ setfile = notnullfopencfv(&etcfile, mode);
133+ else
134+ setfile = fopen(etcfile.result, mode);
135+
136+ if (setfile == NULL) {
137+ sprintf(filename, "%s/%s", AUMIXRC_PATH, AUMIXRC);
138+ setfile = fopen(filename, mode);
139+ }
140+ if (setfile == NULL)
141+ return NULL;
142+
143 } else
144- setfile = fopen(save_filename, mode);
145+ setfile = fopen(save_filename, mode);
146 return setfile;
147 }
148
149@@ -649,7 +663,7 @@
150 other options:\n\
151 d: adjust a device besides /dev/mixer\n\
152 f: specify file for saving and loading settings (defaults to\n\
153- ~ /.aumixrc or /etc/aumixrc)\n\
154+ $CONFIG_DIR/aumixrc, ~/.aumixrc or /etc/aumixrc)\n\
155 C: specify color scheme\n\
156 h: this helpful message\n"));
157 #ifdef HAVE_CURSES
158--- aumix-2.1/src/userdir.c Thu Jan 1 01:00:00 1970
159+++ aumix-2.1.pius/src/userdir.c Thu Feb 3 01:24:28 2000
160@@ -0,0 +1,146 @@
161+// $Id$
162+#include "userdir.h"
163+
164+static char *nonulhome = "";
165+
166+/******************************************************************************/
167+
168+int getusercfv (char *variable,
169+ char *home_dir,
170+ char *user_dir,
171+ size_t stringsize)
172+{
173+ struct stat st;
174+ char *d;
175+
176+ bzero (user_dir, stringsize);
177+ if (variable == NULL || *variable == '\0') return (-1);
178+ if (home_dir == NULL) home_dir = nonulhome;
179+ d = getenv (variable);
180+ if (d == NULL || *d == '\0') return (-1);
181+ if (*d == '/')
182+ {
183+ strncpy (user_dir, d, stringsize-1);
184+ }
185+ else
186+ {
187+ snprintf (user_dir, stringsize-1, "%s/%s", home_dir, d);
188+ }
189+
190+ if (stat(user_dir,&st) != -1 && S_ISDIR(st.st_mode))
191+ {
192+ return (0);
193+ }
194+
195+ return (-1);
196+}
197+
198+/******************************************************************************/
199+
200+int detectcfv(struct cfv *CFV) {
201+ if (CFV->subname == NULL) CFV->subname = nonulhome;
202+ if (CFV->home_dir == NULL) CFV->home_dir = getenv ("HOME");
203+ if (CFV->home_dir == NULL) CFV->home_dir = CFV->home_scd;
204+ if (CFV->home_dir == NULL) return (-1);
205+ return 0;
206+}
207+
208+int preparemain(struct cfv *CFV) {
209+ char *p;
210+ struct stat st;
211+ if ((p = strrchr(CFV->result, '/')) && *(p+1) == '\0')
212+ p = '\0';
213+ snprintf ((rindex(CFV->result,'\0')), MAXPATHLEN-1, "/%s",
214+ CFV->subname);
215+ if (stat( CFV->result,&st) != -1
216+ && CFV->mode ?
217+ S_ISDIR(st.st_mode) :
218+ S_ISREG(st.st_mode)) /* have file or dir */
219+ return (1);
220+ return 0;
221+}
222+
223+int preparehome(struct cfv *CFV) {
224+ struct stat st;
225+ if (CFV->home_dir == NULL || *(CFV->home_dir) == '\0') return (-1);
226+ if (CFV->prefix == NULL && CFV->suffix == NULL) return (-1);
227+ snprintf (CFV->result, MAXPATHLEN-1, "%s/%s%s%s",
228+ CFV->home_dir,
229+ CFV->prefix? CFV->prefix:"",
230+ CFV->subname,
231+ CFV->suffix? CFV->suffix:"");
232+ if (stat(CFV->result,&st) != -1
233+ && CFV->mode ?
234+ S_ISDIR(st.st_mode) :
235+ S_ISREG(st.st_mode)) /* have file or dir */
236+ return (2);
237+ return (-1);
238+}
239+
240+int usercfv (struct cfv *CFV) {
241+ int gr;
242+ gr = detectcfv(CFV);
243+ if (gr) return gr;
244+ /* get environment variable */
245+ gr = getusercfv (CFV->variable,
246+ CFV->home_dir,
247+ CFV->result,
248+ MAXPATHLEN);
249+ if (gr != -1) /* have main directory */
250+ {
251+ gr = preparemain(CFV);
252+ if (gr) return gr;
253+ }
254+ /* don't have main directory or a proper variable set */
255+ gr = preparehome(CFV);
256+ return gr;
257+}
258+
259+/******************************************************************************/
260+
261+/* If directory or file doesn't exist returns the best one wich may be created*/
262+int notnullusercfv (struct cfv *CFV) {
263+ int gr;
264+ if ((usercfv(CFV)) == -1) {
265+ gr = detectcfv(CFV);
266+ if (gr) return gr;
267+ /* get environment variable */
268+ gr = getusercfv (CFV->variable,
269+ CFV->home_dir,
270+ CFV->result,
271+ MAXPATHLEN);
272+ if (gr != -1) /* have main directory */
273+ {
274+ gr = preparemain(CFV);
275+ return 0;
276+ }
277+ /* don't have main directory or a proper variable set */
278+ gr = preparehome(CFV);
279+ return 0;
280+ }
281+ return 0;
282+}
283+
284+/******************************************************************************/
285+
286+FILE *fopencfv (struct cfv *CFV, const char *mode)
287+ {
288+ FILE *cfvfile = NULL;
289+
290+ CFV->mode = M_REGULAR_FILE;
291+ if ((usercfv (CFV)) == -1) return (NULL);
292+ cfvfile = fopen (CFV->result, mode);
293+ return (cfvfile);
294+ }
295+/******************************************************************************/
296+
297+FILE *notnullfopencfv (struct cfv *CFV, const char *mode)
298+ {
299+ FILE *cfvfile = NULL;
300+
301+ CFV->mode = M_REGULAR_FILE;
302+ if ((notnullusercfv (CFV)) == -1) return (NULL);
303+ cfvfile = fopen (CFV->result, mode);
304+ return (cfvfile);
305+ }
306+
307--- aumix-2.1/src/userdir.h Thu Jan 1 01:00:00 1970
308+++ aumix-2.1.pius/src/userdir.h Thu Feb 3 01:58:57 2000
309@@ -0,0 +1,55 @@
310+// $Id$
311+#ifndef USERDIR__H
312+#define USERDIR__H
313+
314+#include <unistd.h>
315+#include <string.h>
316+#include <stdio.h>
317+#include <stdlib.h>
318+#include <sys/types.h>
319+#include <sys/stat.h>
320+#include <sys/param.h>
321+
322+#define M_REGULAR_FILE 0
323+#define M_DIRECTORY 1
324+
325+struct cfv {
326+ char result[MAXPATHLEN]; /* our result */
327+ char *variable; /* name of an environment variable */
328+ char *home_dir; /* home directory or NULL for autodetect */
329+ char *home_scd; /* directory if home_dir==NULL and no result */
330+ char *subname; /* core name of a file/directory */
331+ char *prefix; /* prefix when using directly home_dir */
332+ char *suffix; /* suffix when using directly home_dir */
333+ int mode; /* expected: M_REGULAR_FILE or M_DIRECTORY */
334+ };
335+
336+/* reads environment variable. if the path isn't absolute will add $HOME/
337+ * at the beginning
338+ * return: 0 - directory exists
339+ * -1 - directory doesn't exist
340+ */
341+int getusercfv (char *variable,
342+ char *home_dir,
343+ char *user_dir,
344+ size_t stringsize);
345+/* reads the $HOME variable */
346+int detectcfv(struct cfv *CFV);
347+
348+/* looks for the config/data file/dir.
349+ * result: -1 - error - cannot find file/dir
350+ * 0 - ok
351+ * CFV.result set
352+ */
353+int usercfv (struct cfv *CFV);
354+/* looks for the config/data file/dir.
355+ * result: -1 - error - cannot read $HOME
356+ * 0 - ok - if the CFV.result exists, read it. If not create it.
357+ * CFV.result set
358+ */
359+int notnullusercfv (struct cfv *CFV);
360+
361+FILE *fopencfv (struct cfv *CFV, const char *mode);
362+FILE *notnullfopencfv (struct cfv *CFV, const char *mode);
363+
364+#endif
365--- aumix-2.1/po/aumix.pot Mon Jan 31 23:30:12 2000
366+++ aumix-2.1.pius/po/aumix.pot Fri Feb 4 01:11:42 2000
367@@ -175,7 +175,7 @@
7476d76d 368 "other options:\n"
369 " d: adjust a device besides /dev/mixer\n"
370 " f: specify file for saving and loading settings (defaults to\n"
371-" ~ /.aumixrc or /etc/aumixrc)\n"
ac9fa1ac 372+" $CONFIG_DIR/aumixrc, ~ /.aumixrc or /etc/aumixrc)\n"
7476d76d 373 " C: specify color scheme\n"
374 " h: this helpful message\n"
375 msgstr ""
ac9fa1ac 376--- aumix-2.1/po/de.po Sun Nov 28 07:35:18 1999
377+++ aumix-2.1.pius/po/de.po Fri Feb 4 01:10:08 2000
7476d76d 378@@ -81,7 +81,7 @@
379 "other options:\n"
380 " d: adjust a device besides /dev/mixer\n"
381 " f: specify file for saving and loading settings (defaults to\n"
382-" ~ /.aumixrc or /etc/aumixrc)\n"
ac9fa1ac 383+" $CONFIG_DIR/aumixrc, ~ /.aumixrc or /etc/aumixrc)\n"
7476d76d 384 " C: specify color scheme\n"
385 " h: this helpful message\n"
386 msgstr ""
387@@ -99,7 +99,7 @@
388 "Weitere Optionen:\n"
389