ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/prefs_macosx.cpp
Revision: 1.9
Committed: 2005-01-30T21:42:13Z (19 years, 8 months ago) by gbeauche
Branch: MAIN
CVS Tags: nigel-build-19, nigel-build-17
Changes since 1.8: +2 -2 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * $Id: prefs_macosx.cpp,v 1.8 2004/05/02 11:09:25 nigel Exp $
3 *
4 * prefs_macosx.cpp - Preferences handling, Mac OS X specific.
5 * Based on prefs_unix.cpp
6 *
7 * Basilisk II (C) 1997-2005 Christian Bauer
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include "sysdeps.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #include <string>
30 using std::string;
31
32 #include "prefs.h"
33
34
35 // Platform-specific preferences items
36 prefs_desc platform_prefs_items[] = {
37 #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
38 {"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"},
39 #endif
40 {NULL, TYPE_END, false, NULL} // End of list
41 };
42
43
44 // Prefs file name and path
45 const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs";
46 string UserPrefsPath;
47 static string prefs_path;
48
49
50 /*
51 * Load preferences from settings file
52 */
53
54 void LoadPrefs(void)
55 {
56 // Construct prefs path
57 if (UserPrefsPath.empty()) {
58 char *home = getenv("HOME");
59 if (home)
60 prefs_path = string(home) + '/';
61 prefs_path += PREFS_FILE_NAME;
62 UserPrefsPath = prefs_path;
63 } else
64 prefs_path = UserPrefsPath;
65
66 // Read preferences from settings file
67 FILE *f = fopen(prefs_path.c_str(), "r");
68 if (f != NULL) {
69
70 // Prefs file found, load settings
71 LoadPrefsFromStream(f);
72 fclose(f);
73
74 } else {
75
76 // No prefs file, save defaults
77 SavePrefs();
78 }
79
80 // Remove Nigel's bad old serial prefs
81
82 const char *str;
83 int tmp = 0;
84
85 if ( (str = PrefsFindString("seriala") ) != NULL
86 && strcmp(str, "/dev/ttys0") == 0 )
87 {
88 puts("Deleting invalid prefs item 'seriala /dev/ttys0'");
89 PrefsRemoveItem("seriala", 1);
90 }
91
92 if ( (str = PrefsFindString("serialb") ) != NULL
93 && strcmp(str, "/dev/ttys1") == 0 )
94 {
95 puts("Deleting invalid prefs item 'serialb /dev/ttys1'");
96 PrefsRemoveItem("serialb", 1);
97 }
98
99 // Floppy & cdrom prefs are always removed -
100 // we search for them each time the emulator is started
101
102 while ( (str = PrefsFindString("floppy", tmp) ) != NULL )
103 PrefsRemoveItem("floppy", tmp);
104
105 while ( (str = PrefsFindString("cdrom", tmp) ) != NULL )
106 PrefsRemoveItem("cdrom", tmp);
107 }
108
109
110 /*
111 * Save preferences to settings file
112 */
113
114 void SavePrefs(void)
115 {
116 FILE *f;
117 if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
118 SavePrefsToStream(f);
119 fclose(f);
120 }
121 }
122
123
124 /*
125 * Add defaults of platform-specific prefs items
126 * You may also override the defaults set in PrefsInit()
127 */
128
129 void AddPlatformPrefsDefaults(void)
130 {
131 PrefsReplaceString("extfs", getenv("HOME"));
132 PrefsReplaceString("screen", "win/512/384/16");
133 #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
134 PrefsAddBool("ignoresegv", false);
135 #endif
136 }