1 |
/* |
2 |
* prefs_unix.cpp - Preferences handling, Unix specific things |
3 |
* |
4 |
* SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig |
5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
7 |
* it under the terms of the GNU General Public License as published by |
8 |
* the Free Software Foundation; either version 2 of the License, or |
9 |
* (at your option) any later version. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
20 |
|
21 |
#include "sysdeps.h" |
22 |
|
23 |
#include <string.h> |
24 |
#include <stdlib.h> |
25 |
#include <stdio.h> |
26 |
|
27 |
#include "prefs.h" |
28 |
|
29 |
|
30 |
// Platform-specific preferences items |
31 |
prefs_desc platform_prefs_items[] = { |
32 |
{"ether", TYPE_STRING, false, "device name of Mac ethernet adapter"}, |
33 |
{"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"}, |
34 |
{"keycodefile", TYPE_STRING, false, "path of keycode translation file"}, |
35 |
{"dsp", TYPE_STRING, false, "audio output (dsp) device name"}, |
36 |
{"mixer", TYPE_STRING, false, "audio mixer device name"}, |
37 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
38 |
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"}, |
39 |
#endif |
40 |
{NULL, TYPE_END, false, NULL} // End of list |
41 |
}; |
42 |
|
43 |
|
44 |
// Prefs file name and path |
45 |
const char PREFS_FILE_NAME[] = ".sheepshaver_prefs"; |
46 |
static char prefs_path[1024]; |
47 |
|
48 |
|
49 |
/* |
50 |
* Load preferences from settings file |
51 |
*/ |
52 |
|
53 |
void LoadPrefs(void) |
54 |
{ |
55 |
// Construct prefs path |
56 |
prefs_path[0] = 0; |
57 |
char *home = getenv("HOME"); |
58 |
if (home != NULL && strlen(home) < 1000) { |
59 |
strncpy(prefs_path, home, 1000); |
60 |
strcat(prefs_path, "/"); |
61 |
} |
62 |
strcat(prefs_path, PREFS_FILE_NAME); |
63 |
|
64 |
// Read preferences from settings file |
65 |
FILE *f = fopen(prefs_path, "r"); |
66 |
if (f != NULL) { |
67 |
|
68 |
// Prefs file found, load settings |
69 |
LoadPrefsFromStream(f); |
70 |
fclose(f); |
71 |
|
72 |
} else { |
73 |
|
74 |
// No prefs file, save defaults |
75 |
SavePrefs(); |
76 |
} |
77 |
} |
78 |
|
79 |
|
80 |
/* |
81 |
* Save preferences to settings file |
82 |
*/ |
83 |
|
84 |
void SavePrefs(void) |
85 |
{ |
86 |
FILE *f; |
87 |
if ((f = fopen(prefs_path, "w")) != NULL) { |
88 |
SavePrefsToStream(f); |
89 |
fclose(f); |
90 |
} |
91 |
} |
92 |
|
93 |
|
94 |
/* |
95 |
* Add defaults of platform-specific prefs items |
96 |
* You may also override the defaults set in PrefsInit() |
97 |
*/ |
98 |
|
99 |
void AddPlatformPrefsDefaults(void) |
100 |
{ |
101 |
PrefsAddBool("keycodes", false); |
102 |
PrefsReplaceString("extfs", "/"); |
103 |
PrefsAddInt32("windowmodes", 3); |
104 |
PrefsAddInt32("screenmodes", 0x3f); |
105 |
#ifdef __linux__ |
106 |
if (access("/dev/.devfsd", F_OK) < 0) { |
107 |
PrefsReplaceString("dsp", "/dev/dsp"); |
108 |
PrefsReplaceString("mixer", "/dev/mixer"); |
109 |
} else { |
110 |
PrefsReplaceString("dsp", "/dev/sound/dsp"); |
111 |
PrefsReplaceString("mixer", "/dev/sound/mixer"); |
112 |
} |
113 |
#else |
114 |
PrefsReplaceString("dsp", "/dev/dsp"); |
115 |
PrefsReplaceString("mixer", "/dev/mixer"); |
116 |
#endif |
117 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
118 |
PrefsAddBool("ignoresegv", false); |
119 |
#endif |
120 |
} |