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