1 |
/* |
2 |
* prefs_unix.cpp - Preferences handling, Unix specific stuff |
3 |
* |
4 |
* Basilisk II (C) 1997-2008 Christian Bauer |
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 <stdio.h> |
24 |
#include <stdlib.h> |
25 |
|
26 |
#include <string> |
27 |
using std::string; |
28 |
|
29 |
#include "prefs.h" |
30 |
|
31 |
|
32 |
// Platform-specific preferences items |
33 |
prefs_desc platform_prefs_items[] = { |
34 |
{"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"}, |
35 |
{"keycodefile", TYPE_STRING, false, "path of keycode translation file"}, |
36 |
{"fbdevicefile", TYPE_STRING, false, "path of frame buffer device specification file"}, |
37 |
{"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"}, |
38 |
{"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"}, |
39 |
{"dsp", TYPE_STRING, false, "audio output (dsp) device name"}, |
40 |
{"mixer", TYPE_STRING, false, "audio mixer device name"}, |
41 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
42 |
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"}, |
43 |
#endif |
44 |
{"idlewait", TYPE_BOOLEAN, false, "sleep when idle"}, |
45 |
{NULL, TYPE_END, false, NULL} // End of list |
46 |
}; |
47 |
|
48 |
|
49 |
// Prefs file name and path |
50 |
const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs"; |
51 |
string UserPrefsPath; |
52 |
static string prefs_path; |
53 |
|
54 |
|
55 |
/* |
56 |
* Load preferences from settings file |
57 |
*/ |
58 |
|
59 |
void LoadPrefs(const char *vmdir) |
60 |
{ |
61 |
if (vmdir) { |
62 |
prefs_path = string(vmdir) + '/' + string("prefs"); |
63 |
FILE *prefs = fopen(prefs_path.c_str(), "r"); |
64 |
if (!prefs) { |
65 |
printf("No file at %s found.\n", prefs_path.c_str()); |
66 |
exit(1); |
67 |
} |
68 |
LoadPrefsFromStream(prefs); |
69 |
fclose(prefs); |
70 |
return; |
71 |
} |
72 |
|
73 |
// Construct prefs path |
74 |
if (UserPrefsPath.empty()) { |
75 |
char *home = getenv("HOME"); |
76 |
if (home) |
77 |
prefs_path = string(home) + '/'; |
78 |
prefs_path += PREFS_FILE_NAME; |
79 |
} else |
80 |
prefs_path = UserPrefsPath; |
81 |
|
82 |
// Read preferences from settings file |
83 |
FILE *f = fopen(prefs_path.c_str(), "r"); |
84 |
if (f != NULL) { |
85 |
|
86 |
// Prefs file found, load settings |
87 |
LoadPrefsFromStream(f); |
88 |
fclose(f); |
89 |
|
90 |
} else { |
91 |
|
92 |
// No prefs file, save defaults |
93 |
SavePrefs(); |
94 |
} |
95 |
} |
96 |
|
97 |
|
98 |
/* |
99 |
* Save preferences to settings file |
100 |
*/ |
101 |
|
102 |
void SavePrefs(void) |
103 |
{ |
104 |
FILE *f; |
105 |
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) { |
106 |
SavePrefsToStream(f); |
107 |
fclose(f); |
108 |
} |
109 |
} |
110 |
|
111 |
|
112 |
/* |
113 |
* Add defaults of platform-specific prefs items |
114 |
* You may also override the defaults set in PrefsInit() |
115 |
*/ |
116 |
|
117 |
void AddPlatformPrefsDefaults(void) |
118 |
{ |
119 |
PrefsAddBool("keycodes", false); |
120 |
PrefsReplaceString("extfs", "/"); |
121 |
PrefsReplaceInt32("mousewheelmode", 1); |
122 |
PrefsReplaceInt32("mousewheellines", 3); |
123 |
#ifdef __linux__ |
124 |
if (access("/dev/sound/dsp", F_OK) == 0) { |
125 |
PrefsReplaceString("dsp", "/dev/sound/dsp"); |
126 |
} else { |
127 |
PrefsReplaceString("dsp", "/dev/dsp"); |
128 |
} |
129 |
if (access("/dev/sound/mixer", F_OK) == 0) { |
130 |
PrefsReplaceString("mixer", "/dev/sound/mixer"); |
131 |
} else { |
132 |
PrefsReplaceString("mixer", "/dev/mixer"); |
133 |
} |
134 |
#else |
135 |
PrefsReplaceString("dsp", "/dev/dsp"); |
136 |
PrefsReplaceString("mixer", "/dev/mixer"); |
137 |
#endif |
138 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
139 |
PrefsAddBool("ignoresegv", false); |
140 |
#endif |
141 |
PrefsAddBool("idlewait", true); |
142 |
} |