ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/MacOSX/prefs_macosx.cpp
Revision: 1.6
Committed: 2004-01-26T11:12:46Z (20 years, 8 months ago) by nigel
Branch: MAIN
Changes since 1.5: +29 -1 lines
Log Message:
Added code to remove my broken old floppy & serial prefs values

File Contents

# User Rev Content
1 nigel 1.1 /*
2 nigel 1.6 * $Id: prefs_macosx.cpp,v 1.5 2004/01/12 15:29:24 cebix Exp $
3 nigel 1.1 *
4     * prefs_macosx.cpp - Preferences handling, Unix specific.
5     * Based on prefs_unix.cpp
6     *
7 cebix 1.5 * Basilisk II (C) 1997-2004 Christian Bauer
8 nigel 1.1 *
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 nigel 1.3 #include <string>
30     using std::string;
31    
32 nigel 1.1 #include "prefs.h"
33    
34    
35     // Platform-specific preferences items
36     prefs_desc platform_prefs_items[] = {
37 nigel 1.3 #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
38     {"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"},
39     #endif
40 nigel 1.1 {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 nigel 1.3 string UserPrefsPath;
47     static string prefs_path;
48 nigel 1.1
49    
50     /*
51     * Load preferences from settings file
52     */
53    
54     void LoadPrefs(void)
55     {
56     // Construct prefs path
57 nigel 1.3 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 nigel 1.1
66     // Read preferences from settings file
67 nigel 1.3 FILE *f = fopen(prefs_path.c_str(), "r");
68 nigel 1.1 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 nigel 1.6 }
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");
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");
106 nigel 1.1 }
107     }
108    
109    
110     /*
111     * Save preferences to settings file
112     */
113    
114     void SavePrefs(void)
115     {
116     FILE *f;
117 nigel 1.3 if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
118 nigel 1.1 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 nigel 1.4 PrefsReplaceString("extfs", getenv("HOME"));
132 nigel 1.2 PrefsReplaceString("screen", "win/512/384/16");
133 nigel 1.3 #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
134     PrefsAddBool("ignoresegv", false);
135     #endif
136 nigel 1.1 }