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 |
|
|
#include "prefs.h" |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
// Platform-specific preferences items |
30 |
|
|
prefs_desc platform_prefs_items[] = { |
31 |
cebix |
1.8 |
{"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"}, |
32 |
|
|
{"keycodefile", TYPE_STRING, false, "path of keycode translation file"}, |
33 |
|
|
{"fbdevicefile", TYPE_STRING, false, "path of frame buffer device specification file"}, |
34 |
|
|
{"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"}, |
35 |
|
|
{"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"}, |
36 |
gbeauche |
1.10 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
37 |
|
|
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"}, |
38 |
|
|
#endif |
39 |
cebix |
1.8 |
{NULL, TYPE_END, false, NULL} // End of list |
40 |
cebix |
1.1 |
}; |
41 |
|
|
|
42 |
|
|
|
43 |
|
|
// Prefs file name and path |
44 |
|
|
const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs"; |
45 |
|
|
static char prefs_path[1024]; |
46 |
|
|
|
47 |
|
|
|
48 |
|
|
/* |
49 |
|
|
* Load preferences from settings file |
50 |
|
|
*/ |
51 |
|
|
|
52 |
|
|
void LoadPrefs(void) |
53 |
|
|
{ |
54 |
|
|
// Construct prefs path |
55 |
|
|
prefs_path[0] = 0; |
56 |
|
|
char *home = getenv("HOME"); |
57 |
|
|
if (home != NULL && strlen(home) < 1000) { |
58 |
|
|
strncpy(prefs_path, home, 1000); |
59 |
|
|
strcat(prefs_path, "/"); |
60 |
|
|
} |
61 |
|
|
strcat(prefs_path, PREFS_FILE_NAME); |
62 |
|
|
|
63 |
|
|
// Read preferences from settings file |
64 |
|
|
FILE *f = fopen(prefs_path, "r"); |
65 |
|
|
if (f != NULL) { |
66 |
|
|
|
67 |
|
|
// Prefs file found, load settings |
68 |
|
|
LoadPrefsFromStream(f); |
69 |
|
|
fclose(f); |
70 |
|
|
|
71 |
|
|
} else { |
72 |
|
|
|
73 |
|
|
// No prefs file, save defaults |
74 |
|
|
SavePrefs(); |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
/* |
80 |
|
|
* Save preferences to settings file |
81 |
|
|
*/ |
82 |
|
|
|
83 |
|
|
void SavePrefs(void) |
84 |
|
|
{ |
85 |
|
|
FILE *f; |
86 |
|
|
if ((f = fopen(prefs_path, "w")) != NULL) { |
87 |
|
|
SavePrefsToStream(f); |
88 |
|
|
fclose(f); |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
|
93 |
|
|
/* |
94 |
|
|
* Add defaults of platform-specific prefs items |
95 |
|
|
* You may also override the defaults set in PrefsInit() |
96 |
|
|
*/ |
97 |
|
|
|
98 |
|
|
void AddPlatformPrefsDefaults(void) |
99 |
|
|
{ |
100 |
|
|
PrefsAddBool("keycodes", false); |
101 |
cebix |
1.2 |
PrefsReplaceString("extfs", "/"); |
102 |
cebix |
1.6 |
PrefsReplaceInt32("mousewheelmode", 1); |
103 |
|
|
PrefsReplaceInt32("mousewheellines", 3); |
104 |
gbeauche |
1.10 |
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION |
105 |
|
|
PrefsAddBool("ignoresegv", false); |
106 |
|
|
#endif |
107 |
cebix |
1.1 |
} |