ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/Unix/prefs_unix.cpp
Revision: 1.2
Committed: 2003-11-21T17:01:33Z (20 years, 7 months ago) by gbeauche
Branch: MAIN
Changes since 1.1: +3 -0 lines
Log Message:
Merge in "keycodes" support from Basilisk II. e.g. make French keyboard
layout work correctly for me.

File Contents

# Content
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 {"keycodes", TYPE_BOOLEAN, false, "use keycodes rather than keysyms to decode keyboard"},
34 {"keycodefile", TYPE_STRING, false, "path of keycode translation file"},
35 {NULL, TYPE_END, false, NULL} // End of list
36 };
37
38
39 // Prefs file name and path
40 const char PREFS_FILE_NAME[] = ".sheepshaver_prefs";
41 static char prefs_path[1024];
42
43
44 /*
45 * Load preferences from settings file
46 */
47
48 void LoadPrefs(void)
49 {
50 // Construct prefs path
51 prefs_path[0] = 0;
52 char *home = getenv("HOME");
53 if (home != NULL && strlen(home) < 1000) {
54 strncpy(prefs_path, home, 1000);
55 strcat(prefs_path, "/");
56 }
57 strcat(prefs_path, PREFS_FILE_NAME);
58
59 // Read preferences from settings file
60 FILE *f = fopen(prefs_path, "r");
61 if (f != NULL) {
62
63 // Prefs file found, load settings
64 LoadPrefsFromStream(f);
65 fclose(f);
66
67 } else {
68
69 // No prefs file, save defaults
70 SavePrefs();
71 }
72 }
73
74
75 /*
76 * Save preferences to settings file
77 */
78
79 void SavePrefs(void)
80 {
81 FILE *f;
82 if ((f = fopen(prefs_path, "w")) != NULL) {
83 SavePrefsToStream(f);
84 fclose(f);
85 }
86 }
87
88
89 /*
90 * Add defaults of platform-specific prefs items
91 * You may also override the defaults set in PrefsInit()
92 */
93
94 void AddPlatformPrefsDefaults(void)
95 {
96 PrefsAddBool("keycodes", false);
97 PrefsReplaceString("extfs", "/");
98 PrefsAddInt32("windowmodes", 3);
99 PrefsAddInt32("screenmodes", 0x3f);
100 }