1 |
cebix |
1.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 |
gbeauche |
1.3 |
{"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 |
gbeauche |
1.4 |
{"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"}, |
36 |
|
|
{"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"}, |
37 |
gbeauche |
1.3 |
{"dsp", TYPE_STRING, false, "audio output (dsp) device name"}, |
38 |
|
|
{"mixer", TYPE_STRING, false, "audio mixer device name"}, |
39 |
|
|
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
40 |
|
|
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"}, |
41 |
|
|
#endif |
42 |
cebix |
1.1 |
{NULL, TYPE_END, false, NULL} // End of list |
43 |
|
|
}; |
44 |
|
|
|
45 |
|
|
|
46 |
|
|
// Prefs file name and path |
47 |
|
|
const char PREFS_FILE_NAME[] = ".sheepshaver_prefs"; |
48 |
|
|
static char prefs_path[1024]; |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
/* |
52 |
|
|
* Load preferences from settings file |
53 |
|
|
*/ |
54 |
|
|
|
55 |
|
|
void LoadPrefs(void) |
56 |
|
|
{ |
57 |
|
|
// Construct prefs path |
58 |
|
|
prefs_path[0] = 0; |
59 |
|
|
char *home = getenv("HOME"); |
60 |
|
|
if (home != NULL && strlen(home) < 1000) { |
61 |
|
|
strncpy(prefs_path, home, 1000); |
62 |
|
|
strcat(prefs_path, "/"); |
63 |
|
|
} |
64 |
|
|
strcat(prefs_path, PREFS_FILE_NAME); |
65 |
|
|
|
66 |
|
|
// Read preferences from settings file |
67 |
|
|
FILE *f = fopen(prefs_path, "r"); |
68 |
|
|
if (f != NULL) { |
69 |
|
|
|
70 |
|
|
// Prefs file found, load settings |
71 |
|
|
LoadPrefsFromStream(f); |
72 |
|
|
fclose(f); |
73 |
|
|
|
74 |
|
|
} else { |
75 |
|
|
|
76 |
|
|
// No prefs file, save defaults |
77 |
|
|
SavePrefs(); |
78 |
|
|
} |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
/* |
83 |
|
|
* Save preferences to settings file |
84 |
|
|
*/ |
85 |
|
|
|
86 |
|
|
void SavePrefs(void) |
87 |
|
|
{ |
88 |
|
|
FILE *f; |
89 |
|
|
if ((f = fopen(prefs_path, "w")) != NULL) { |
90 |
|
|
SavePrefsToStream(f); |
91 |
|
|
fclose(f); |
92 |
|
|
} |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
|
96 |
|
|
/* |
97 |
|
|
* Add defaults of platform-specific prefs items |
98 |
|
|
* You may also override the defaults set in PrefsInit() |
99 |
|
|
*/ |
100 |
|
|
|
101 |
|
|
void AddPlatformPrefsDefaults(void) |
102 |
|
|
{ |
103 |
gbeauche |
1.2 |
PrefsAddBool("keycodes", false); |
104 |
cebix |
1.1 |
PrefsReplaceString("extfs", "/"); |
105 |
gbeauche |
1.4 |
PrefsReplaceInt32("mousewheelmode", 1); |
106 |
|
|
PrefsReplaceInt32("mousewheellines", 3); |
107 |
cebix |
1.1 |
PrefsAddInt32("windowmodes", 3); |
108 |
|
|
PrefsAddInt32("screenmodes", 0x3f); |
109 |
gbeauche |
1.3 |
#ifdef __linux__ |
110 |
|
|
if (access("/dev/.devfsd", F_OK) < 0) { |
111 |
|
|
PrefsReplaceString("dsp", "/dev/dsp"); |
112 |
|
|
PrefsReplaceString("mixer", "/dev/mixer"); |
113 |
|
|
} else { |
114 |
|
|
PrefsReplaceString("dsp", "/dev/sound/dsp"); |
115 |
|
|
PrefsReplaceString("mixer", "/dev/sound/mixer"); |
116 |
|
|
} |
117 |
|
|
#else |
118 |
|
|
PrefsReplaceString("dsp", "/dev/dsp"); |
119 |
|
|
PrefsReplaceString("mixer", "/dev/mixer"); |
120 |
|
|
#endif |
121 |
|
|
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
122 |
|
|
PrefsAddBool("ignoresegv", false); |
123 |
|
|
#endif |
124 |
cebix |
1.1 |
} |