ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/prefs_unix.cpp
Revision: 1.6
Committed: 2001-01-04T19:50:23Z (23 years, 10 months ago) by cebix
Branch: MAIN
Changes since 1.5: +4 -4 lines
Log Message:
- removed the INT16 prefs item type; use INT32 instead
- AmigaOS/Unix: it's now possible to specify preferences items on the
  command line
- Unix: command line options now take "--"-prefix, e.g. "--rominfo"

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * prefs_unix.cpp - Preferences handling, Unix specifix stuff
3     *
4 cebix 1.5 * Basilisk II (C) 1997-2000 Christian Bauer
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 <stdio.h>
24     #include <stdlib.h>
25    
26     #include "prefs.h"
27    
28    
29     // Platform-specific preferences items
30     prefs_desc platform_prefs_items[] = {
31     {"keycodes", TYPE_BOOLEAN, false}, // Use keycodes rather than keysyms to decode keyboard (video_x.cpp)
32     {"keycodefile", TYPE_STRING, false}, // File name of keycode translation table (video_x.cpp)
33 cebix 1.4 {"fbdevicefile", TYPE_STRING, false}, // File name of frame buffer device specifications (video_x.cpp)
34 cebix 1.6 {"mousewheelmode", TYPE_INT32, false}, // Mouse wheel support mode (0=Page up/down, 1=Cursor up/down) (video_x.cpp)
35     {"mousewheellines", TYPE_INT32, false}, // Number of lines to scroll in mouse whell mode 1 (video_x.cpp)
36 cebix 1.1 {NULL, TYPE_END, false} // End of list
37     };
38    
39    
40     // Prefs file name and path
41     const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs";
42     static char prefs_path[1024];
43    
44    
45     /*
46     * Load preferences from settings file
47     */
48    
49     void LoadPrefs(void)
50     {
51     // Construct prefs path
52     prefs_path[0] = 0;
53     char *home = getenv("HOME");
54     if (home != NULL && strlen(home) < 1000) {
55     strncpy(prefs_path, home, 1000);
56     strcat(prefs_path, "/");
57     }
58     strcat(prefs_path, PREFS_FILE_NAME);
59    
60     // Read preferences from settings file
61     FILE *f = fopen(prefs_path, "r");
62     if (f != NULL) {
63    
64     // Prefs file found, load settings
65     LoadPrefsFromStream(f);
66     fclose(f);
67    
68     } else {
69    
70     // No prefs file, save defaults
71     SavePrefs();
72     }
73     }
74    
75    
76     /*
77     * Save preferences to settings file
78     */
79    
80     void SavePrefs(void)
81     {
82     FILE *f;
83     if ((f = fopen(prefs_path, "w")) != NULL) {
84     SavePrefsToStream(f);
85     fclose(f);
86     }
87     }
88    
89    
90     /*
91     * Add defaults of platform-specific prefs items
92     * You may also override the defaults set in PrefsInit()
93     */
94    
95     void AddPlatformPrefsDefaults(void)
96     {
97     PrefsAddBool("keycodes", false);
98 cebix 1.2 PrefsReplaceString("extfs", "/");
99 cebix 1.6 PrefsReplaceInt32("mousewheelmode", 1);
100     PrefsReplaceInt32("mousewheellines", 3);
101 cebix 1.1 }