1 |
cebix |
1.1 |
/* |
2 |
gbeauche |
1.14 |
* prefs_unix.cpp - Preferences handling, Unix specific stuff |
3 |
cebix |
1.1 |
* |
4 |
gbeauche |
1.18 |
* Basilisk II (C) 1997-2008 Christian Bauer |
5 |
cebix |
1.1 |
* |
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 |
cebix |
1.11 |
#include <string> |
27 |
|
|
using std::string; |
28 |
|
|
|
29 |
cebix |
1.1 |
#include "prefs.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
// Platform-specific preferences items |
33 |
|
|
prefs_desc platform_prefs_items[] = { |
34 |
cebix |
1.8 |
{"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 |
cebix |
1.12 |
{"dsp", TYPE_STRING, false, "audio output (dsp) device name"}, |
40 |
|
|
{"mixer", TYPE_STRING, false, "audio mixer device name"}, |
41 |
gbeauche |
1.10 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
42 |
|
|
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"}, |
43 |
|
|
#endif |
44 |
gbeauche |
1.17 |
{"idlewait", TYPE_BOOLEAN, false, "sleep when idle"}, |
45 |
cebix |
1.8 |
{NULL, TYPE_END, false, NULL} // End of list |
46 |
cebix |
1.1 |
}; |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
// Prefs file name and path |
50 |
|
|
const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs"; |
51 |
cebix |
1.11 |
string UserPrefsPath; |
52 |
|
|
static string prefs_path; |
53 |
cebix |
1.1 |
|
54 |
|
|
|
55 |
|
|
/* |
56 |
|
|
* Load preferences from settings file |
57 |
|
|
*/ |
58 |
|
|
|
59 |
|
|
void LoadPrefs(void) |
60 |
|
|
{ |
61 |
|
|
// Construct prefs path |
62 |
cebix |
1.11 |
if (UserPrefsPath.empty()) { |
63 |
|
|
char *home = getenv("HOME"); |
64 |
|
|
if (home) |
65 |
|
|
prefs_path = string(home) + '/'; |
66 |
|
|
prefs_path += PREFS_FILE_NAME; |
67 |
|
|
} else |
68 |
|
|
prefs_path = UserPrefsPath; |
69 |
cebix |
1.1 |
|
70 |
|
|
// Read preferences from settings file |
71 |
cebix |
1.11 |
FILE *f = fopen(prefs_path.c_str(), "r"); |
72 |
cebix |
1.1 |
if (f != NULL) { |
73 |
|
|
|
74 |
|
|
// Prefs file found, load settings |
75 |
|
|
LoadPrefsFromStream(f); |
76 |
|
|
fclose(f); |
77 |
|
|
|
78 |
|
|
} else { |
79 |
|
|
|
80 |
|
|
// No prefs file, save defaults |
81 |
|
|
SavePrefs(); |
82 |
|
|
} |
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
|
86 |
|
|
/* |
87 |
|
|
* Save preferences to settings file |
88 |
|
|
*/ |
89 |
|
|
|
90 |
|
|
void SavePrefs(void) |
91 |
|
|
{ |
92 |
|
|
FILE *f; |
93 |
cebix |
1.11 |
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) { |
94 |
cebix |
1.1 |
SavePrefsToStream(f); |
95 |
|
|
fclose(f); |
96 |
|
|
} |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
/* |
101 |
|
|
* Add defaults of platform-specific prefs items |
102 |
|
|
* You may also override the defaults set in PrefsInit() |
103 |
|
|
*/ |
104 |
|
|
|
105 |
|
|
void AddPlatformPrefsDefaults(void) |
106 |
|
|
{ |
107 |
|
|
PrefsAddBool("keycodes", false); |
108 |
cebix |
1.2 |
PrefsReplaceString("extfs", "/"); |
109 |
cebix |
1.6 |
PrefsReplaceInt32("mousewheelmode", 1); |
110 |
|
|
PrefsReplaceInt32("mousewheellines", 3); |
111 |
cebix |
1.12 |
#ifdef __linux__ |
112 |
cebix |
1.16 |
if (access("/dev/sound/dsp", F_OK) == 0) { |
113 |
|
|
PrefsReplaceString("dsp", "/dev/sound/dsp"); |
114 |
|
|
} else { |
115 |
cebix |
1.12 |
PrefsReplaceString("dsp", "/dev/dsp"); |
116 |
cebix |
1.16 |
} |
117 |
|
|
if (access("/dev/sound/mixer", F_OK) == 0) { |
118 |
|
|
PrefsReplaceString("mixer", "/dev/sound/mixer"); |
119 |
|
|
} else { |
120 |
cebix |
1.12 |
PrefsReplaceString("mixer", "/dev/mixer"); |
121 |
|
|
} |
122 |
|
|
#else |
123 |
|
|
PrefsReplaceString("dsp", "/dev/dsp"); |
124 |
|
|
PrefsReplaceString("mixer", "/dev/mixer"); |
125 |
|
|
#endif |
126 |
gbeauche |
1.10 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
127 |
|
|
PrefsAddBool("ignoresegv", false); |
128 |
|
|
#endif |
129 |
gbeauche |
1.17 |
PrefsAddBool("idlewait", true); |
130 |
cebix |
1.1 |
} |