ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/prefs_unix.cpp
Revision: 1.1.1.1 (vendor branch)
Committed: 2002-02-04T16:58:13Z (22 years, 4 months ago) by cebix
Branch: cebix
CVS Tags: start
Changes since 1.1: +0 -0 lines
Log Message:
Imported sources

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * prefs_unix.cpp - Preferences handling, Unix specific things
3     *
4     * SheepShaver (C) 1997-2002 Christian Bauer and Marc Hellwig
5     *
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     {"ether", TYPE_STRING, false, "device name of Mac ethernet adapter"},
33     {NULL, TYPE_END, false, NULL} // End of list
34     };
35    
36    
37     // Prefs file name and path
38     const char PREFS_FILE_NAME[] = ".sheepshaver_prefs";
39     static char prefs_path[1024];
40    
41    
42     /*
43     * Load preferences from settings file
44     */
45    
46     void LoadPrefs(void)
47     {
48     // Construct prefs path
49     prefs_path[0] = 0;
50     char *home = getenv("HOME");
51     if (home != NULL && strlen(home) < 1000) {
52     strncpy(prefs_path, home, 1000);
53     strcat(prefs_path, "/");
54     }
55     strcat(prefs_path, PREFS_FILE_NAME);
56    
57     // Read preferences from settings file
58     FILE *f = fopen(prefs_path, "r");
59     if (f != NULL) {
60    
61     // Prefs file found, load settings
62     LoadPrefsFromStream(f);
63     fclose(f);
64    
65     } else {
66    
67     // No prefs file, save defaults
68     SavePrefs();
69     }
70     }
71    
72    
73     /*
74     * Save preferences to settings file
75     */
76    
77     void SavePrefs(void)
78     {
79     FILE *f;
80     if ((f = fopen(prefs_path, "w")) != NULL) {
81     SavePrefsToStream(f);
82     fclose(f);
83     }
84     }
85    
86    
87     /*
88     * Add defaults of platform-specific prefs items
89     * You may also override the defaults set in PrefsInit()
90     */
91    
92     void AddPlatformPrefsDefaults(void)
93     {
94     PrefsReplaceString("extfs", "/");
95     PrefsAddInt32("windowmodes", 3);
96     PrefsAddInt32("screenmodes", 0x3f);
97     }