1 |
/* |
2 |
* prefs_unix.cpp - Preferences handling, Unix specifix stuff |
3 |
* |
4 |
* Basilisk II (C) 1997-2004 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 |
{NULL, TYPE_END, false, NULL} // End of list |
45 |
}; |
46 |
|
47 |
|
48 |
// Prefs file name and path |
49 |
const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs"; |
50 |
string UserPrefsPath; |
51 |
static string prefs_path; |
52 |
|
53 |
|
54 |
/* |
55 |
* Load preferences from settings file |
56 |
*/ |
57 |
|
58 |
void LoadPrefs(void) |
59 |
{ |
60 |
// Construct prefs path |
61 |
if (UserPrefsPath.empty()) { |
62 |
char *home = getenv("HOME"); |
63 |
if (home) |
64 |
prefs_path = string(home) + '/'; |
65 |
prefs_path += PREFS_FILE_NAME; |
66 |
} else |
67 |
prefs_path = UserPrefsPath; |
68 |
|
69 |
// Read preferences from settings file |
70 |
FILE *f = fopen(prefs_path.c_str(), "r"); |
71 |
if (f != NULL) { |
72 |
|
73 |
// Prefs file found, load settings |
74 |
LoadPrefsFromStream(f); |
75 |
fclose(f); |
76 |
|
77 |
} else { |
78 |
|
79 |
// No prefs file, save defaults |
80 |
SavePrefs(); |
81 |
} |
82 |
} |
83 |
|
84 |
|
85 |
/* |
86 |
* Save preferences to settings file |
87 |
*/ |
88 |
|
89 |
void SavePrefs(void) |
90 |
{ |
91 |
FILE *f; |
92 |
if ((f = fopen(prefs_path.c_str(), "w")) != NULL) { |
93 |
SavePrefsToStream(f); |
94 |
fclose(f); |
95 |
} |
96 |
} |
97 |
|
98 |
|
99 |
/* |
100 |
* Add defaults of platform-specific prefs items |
101 |
* You may also override the defaults set in PrefsInit() |
102 |
*/ |
103 |
|
104 |
void AddPlatformPrefsDefaults(void) |
105 |
{ |
106 |
PrefsAddBool("keycodes", false); |
107 |
PrefsReplaceString("extfs", "/"); |
108 |
PrefsReplaceInt32("mousewheelmode", 1); |
109 |
PrefsReplaceInt32("mousewheellines", 3); |
110 |
#ifdef __linux__ |
111 |
if (access("/dev/.devfsd", F_OK) < 0) { |
112 |
PrefsReplaceString("dsp", "/dev/dsp"); |
113 |
PrefsReplaceString("mixer", "/dev/mixer"); |
114 |
} else { |
115 |
PrefsReplaceString("dsp", "/dev/sound/dsp"); |
116 |
PrefsReplaceString("mixer", "/dev/sound/mixer"); |
117 |
} |
118 |
#else |
119 |
PrefsReplaceString("dsp", "/dev/dsp"); |
120 |
PrefsReplaceString("mixer", "/dev/mixer"); |
121 |
#endif |
122 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
123 |
PrefsAddBool("ignoresegv", false); |
124 |
#endif |
125 |
} |