ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/prefs_unix.cpp
Revision: 1.12
Committed: 2009-07-23T19:12:51Z (14 years, 10 months ago) by asvitkine
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +13 -1 lines
Log Message:
support for .sheepvm bundles on macosx, containing "prefs" and "nvram" files

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * prefs_unix.cpp - Preferences handling, Unix specific things
3     *
4 gbeauche 1.11 * SheepShaver (C) 1997-2008 Christian Bauer and Marc Hellwig
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 <string.h>
24     #include <stdlib.h>
25     #include <stdio.h>
26    
27     #include "prefs.h"
28    
29    
30     // Platform-specific preferences items
31     prefs_desc platform_prefs_items[] = {
32 gbeauche 1.3 {"ether", TYPE_STRING, false, "device name of Mac ethernet adapter"},
33 gbeauche 1.6 {"etherconfig", TYPE_STRING, false, "path of network config script"},
34 gbeauche 1.3 {"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"},
35     {"keycodefile", TYPE_STRING, false, "path of keycode translation file"},
36 gbeauche 1.4 {"mousewheelmode", TYPE_INT32, false, "mouse wheel support mode (0=page up/down, 1=cursor up/down)"},
37     {"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"},
38 gbeauche 1.3 {"dsp", TYPE_STRING, false, "audio output (dsp) device name"},
39     {"mixer", TYPE_STRING, false, "audio mixer device name"},
40     #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
41     {"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"},
42     #endif
43 gbeauche 1.7 {"idlewait", TYPE_BOOLEAN, false, "sleep when idle"},
44 cebix 1.1 {NULL, TYPE_END, false, NULL} // End of list
45     };
46    
47    
48     // Prefs file name and path
49     const char PREFS_FILE_NAME[] = ".sheepshaver_prefs";
50     static char prefs_path[1024];
51    
52    
53     /*
54     * Load preferences from settings file
55     */
56    
57 asvitkine 1.12 void LoadPrefs(const char *vmdir)
58 cebix 1.1 {
59 asvitkine 1.12 if (vmdir) {
60     snprintf(prefs_path, sizeof(prefs_path), "%s/prefs", vmdir);
61     FILE *prefs = fopen(prefs_path, "r");
62     if (!prefs) {
63     printf("No file at %s found.\n", prefs_path);
64     exit(1);
65     }
66     LoadPrefsFromStream(prefs);
67     fclose(prefs);
68     return;
69     }
70    
71 cebix 1.1 // Construct prefs path
72     prefs_path[0] = 0;
73     char *home = getenv("HOME");
74     if (home != NULL && strlen(home) < 1000) {
75     strncpy(prefs_path, home, 1000);
76     strcat(prefs_path, "/");
77     }
78     strcat(prefs_path, PREFS_FILE_NAME);
79    
80     // Read preferences from settings file
81     FILE *f = fopen(prefs_path, "r");
82     if (f != NULL) {
83    
84     // Prefs file found, load settings
85     LoadPrefsFromStream(f);
86     fclose(f);
87    
88     } else {
89    
90     // No prefs file, save defaults
91     SavePrefs();
92     }
93     }
94    
95    
96     /*
97     * Save preferences to settings file
98     */
99    
100     void SavePrefs(void)
101     {
102     FILE *f;
103     if ((f = fopen(prefs_path, "w")) != NULL) {
104     SavePrefsToStream(f);
105     fclose(f);
106     }
107     }
108    
109    
110     /*
111     * Add defaults of platform-specific prefs items
112     * You may also override the defaults set in PrefsInit()
113     */
114    
115     void AddPlatformPrefsDefaults(void)
116     {
117 gbeauche 1.2 PrefsAddBool("keycodes", false);
118 cebix 1.1 PrefsReplaceString("extfs", "/");
119 gbeauche 1.4 PrefsReplaceInt32("mousewheelmode", 1);
120     PrefsReplaceInt32("mousewheellines", 3);
121 gbeauche 1.3 #ifdef __linux__
122 cebix 1.10 if (access("/dev/sound/dsp", F_OK) == 0) {
123     PrefsReplaceString("dsp", "/dev/sound/dsp");
124     } else {
125 gbeauche 1.3 PrefsReplaceString("dsp", "/dev/dsp");
126 cebix 1.10 }
127     if (access("/dev/sound/mixer", F_OK) == 0) {
128     PrefsReplaceString("mixer", "/dev/sound/mixer");
129     } else {
130 gbeauche 1.3 PrefsReplaceString("mixer", "/dev/mixer");
131     }
132     #else
133     PrefsReplaceString("dsp", "/dev/dsp");
134     PrefsReplaceString("mixer", "/dev/mixer");
135     #endif
136     #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
137     PrefsAddBool("ignoresegv", false);
138     #endif
139 gbeauche 1.7 PrefsAddBool("idlewait", true);
140 cebix 1.1 }