ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/prefs_macosx.cpp
Revision: 1.7
Committed: 2004-01-27T11:31:01Z (20 years, 8 months ago) by nigel
Branch: MAIN
CVS Tags: nigel-build-15
Changes since 1.6: +3 -3 lines
Log Message:
Corrected removal of bad serial prefs data

File Contents

# Content
1 /*
2 * $Id: prefs_macosx.cpp,v 1.6 2004/01/26 11:12:46 nigel Exp $
3 *
4 * prefs_macosx.cpp - Preferences handling, Unix specific.
5 * Based on prefs_unix.cpp
6 *
7 * Basilisk II (C) 1997-2004 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 floppy and serial prefs
81
82 const char *str;
83 int tmp = 0;
84
85 while ( (str = PrefsFindString("floppy", tmp) ) != NULL )
86 if ( strncmp(str, "/dev/fd/", 8) == 0 )
87 {
88 printf("Deleting invalid prefs item 'floppy %s'\n", str);
89 PrefsRemoveItem("floppy", tmp);
90 }
91 else
92 ++tmp;
93
94 if ( (str = PrefsFindString("seriala") ) != NULL
95 && strcmp(str, "/dev/ttys0") == 0 )
96 {
97 puts("Deleting invalid prefs item 'seriala /dev/ttys0'");
98 PrefsRemoveItem("seriala", 1);
99 }
100
101 if ( (str = PrefsFindString("serialb") ) != NULL
102 && strcmp(str, "/dev/ttys1") == 0 )
103 {
104 puts("Deleting invalid prefs item 'serialb /dev/ttys1'");
105 PrefsRemoveItem("serialb", 1);
106 }
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 }