ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/prefs_macosx.cpp
Revision: 1.12
Committed: 2009-11-06T21:33:03Z (14 years, 7 months ago) by nigel
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +14 -2 lines
Log Message:
Allow linking after prefs API changes from 3 months ago.

File Contents

# Content
1 /*
2 * $Id: prefs_macosx.cpp,v 1.11 2008/01/01 09:40:32 gbeauche Exp $
3 *
4 * prefs_macosx.cpp - Preferences handling, Mac OS X specific.
5 * Based on prefs_unix.cpp
6 *
7 * Basilisk II (C) 1997-2008 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 {"idlewait", TYPE_BOOLEAN, false, "sleep when idle"},
41 {NULL, TYPE_END, false, NULL} // End of list
42 };
43
44
45 // Prefs file name and path
46 const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs";
47 string UserPrefsPath;
48 static string prefs_path;
49
50
51 /*
52 * Load preferences from settings file
53 */
54
55 void LoadPrefs(const char *vmdir)
56 {
57 if (vmdir) {
58 prefs_path = string(vmdir) + '/' + string("prefs");
59 FILE *prefs = fopen(prefs_path.c_str(), "r");
60 if (!prefs) {
61 printf("No file at %s found.\n", prefs_path.c_str());
62 exit(1);
63 }
64 LoadPrefsFromStream(prefs);
65 fclose(prefs);
66 return;
67 }
68
69 // Construct prefs path
70 if (UserPrefsPath.empty()) {
71 char *home = getenv("HOME");
72 if (home)
73 prefs_path = string(home) + '/';
74 prefs_path += PREFS_FILE_NAME;
75 UserPrefsPath = prefs_path;
76 } else
77 prefs_path = UserPrefsPath;
78
79 // Read preferences from settings file
80 FILE *f = fopen(prefs_path.c_str(), "r");
81 if (f != NULL) {
82
83 // Prefs file found, load settings
84 LoadPrefsFromStream(f);
85 fclose(f);
86
87 } else {
88
89 // No prefs file, save defaults
90 SavePrefs();
91 }
92
93 // Remove Nigel's bad old serial prefs
94
95 const char *str;
96 int tmp = 0;
97
98 if ( (str = PrefsFindString("seriala") ) != NULL
99 && strcmp(str, "/dev/ttys0") == 0 )
100 {
101 puts("Deleting invalid prefs item 'seriala /dev/ttys0'");
102 PrefsRemoveItem("seriala", 1);
103 }
104
105 if ( (str = PrefsFindString("serialb") ) != NULL
106 && strcmp(str, "/dev/ttys1") == 0 )
107 {
108 puts("Deleting invalid prefs item 'serialb /dev/ttys1'");
109 PrefsRemoveItem("serialb", 1);
110 }
111
112 // Floppy & cdrom prefs are always removed -
113 // we search for them each time the emulator is started
114
115 while ( (str = PrefsFindString("floppy", tmp) ) != NULL )
116 PrefsRemoveItem("floppy", tmp);
117
118 while ( (str = PrefsFindString("cdrom", tmp) ) != NULL )
119 PrefsRemoveItem("cdrom", tmp);
120 }
121
122
123 /*
124 * Save preferences to settings file
125 */
126
127 void SavePrefs(void)
128 {
129 FILE *f;
130 if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
131 SavePrefsToStream(f);
132 fclose(f);
133 }
134 }
135
136
137 /*
138 * Add defaults of platform-specific prefs items
139 * You may also override the defaults set in PrefsInit()
140 */
141
142 void AddPlatformPrefsDefaults(void)
143 {
144 PrefsReplaceString("extfs", getenv("HOME"));
145 PrefsReplaceString("screen", "win/512/384/16");
146 #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
147 PrefsAddBool("ignoresegv", false);
148 #endif
149 PrefsAddBool("idlewait", true);
150 }