ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/prefs_unix.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/prefs_unix.cpp (file contents):
Revision 1.1.1.1 by cebix, 1999-10-03T14:16:25Z vs.
Revision 1.19 by asvitkine, 2009-07-23T19:19:14Z

# Line 1 | Line 1
1   /*
2 < *  prefs_unix.cpp - Preferences handling, Unix specifix stuff
2 > *  prefs_unix.cpp - Preferences handling, Unix specific stuff
3   *
4 < *  Basilisk II (C) 1997-1999 Christian Bauer
4 > *  Basilisk II (C) 1997-2008 Christian Bauer
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
# Line 23 | Line 23
23   #include <stdio.h>
24   #include <stdlib.h>
25  
26 + #include <string>
27 + using std::string;
28 +
29   #include "prefs.h"
30  
31  
32   // Platform-specific preferences items
33   prefs_desc platform_prefs_items[] = {
34 <        {"keycodes", TYPE_BOOLEAN, false},              // Use keycodes rather than keysyms to decode keyboard (video_x.cpp)
35 <        {"keycodefile", TYPE_STRING, false},    // File name of keycode translation table (video_x.cpp)
36 <        {NULL, TYPE_END, false} // End of list
34 >        {"keycodes", TYPE_BOOLEAN, false,      "use keycodes rather than keysyms to decode keyboard"},
35 >        {"keycodefile", TYPE_STRING, false,    "path of keycode translation file"},
36 >        {"fbdevicefile", TYPE_STRING, false,   "path of frame buffer device specification file"},
37 >        {"mousewheelmode", TYPE_INT32, false,  "mouse wheel support mode (0=page up/down, 1=cursor up/down)"},
38 >        {"mousewheellines", TYPE_INT32, false, "number of lines to scroll in mouse wheel mode 1"},
39 >        {"dsp", TYPE_STRING, false,            "audio output (dsp) device name"},
40 >        {"mixer", TYPE_STRING, false,          "audio mixer device name"},
41 > #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
42 >        {"ignoresegv", TYPE_BOOLEAN, false,    "ignore illegal memory accesses"},
43 > #endif
44 >        {"idlewait", TYPE_BOOLEAN, false,      "sleep when idle"},
45 >        {NULL, TYPE_END, false, NULL} // End of list
46   };
47  
48  
49   // Prefs file name and path
50   const char PREFS_FILE_NAME[] = ".basilisk_ii_prefs";
51 < static char prefs_path[1024];
51 > string UserPrefsPath;
52 > static string prefs_path;
53  
54  
55   /*
56   *  Load preferences from settings file
57   */
58  
59 < void LoadPrefs(void)
59 > void LoadPrefs(const char *vmdir)
60   {
61 <        // Construct prefs path
62 <        prefs_path[0] = 0;
63 <        char *home = getenv("HOME");
64 <        if (home != NULL && strlen(home) < 1000) {
65 <                strncpy(prefs_path, home, 1000);
66 <                strcat(prefs_path, "/");
61 >        if (vmdir) {
62 >                prefs_path = string(vmdir) + '/' + string("prefs");
63 >                FILE *prefs = fopen(prefs_path.c_str(), "r");
64 >                if (!prefs) {
65 >                        printf("No file at %s found.\n", prefs_path.c_str());
66 >                        exit(1);
67 >                }
68 >                LoadPrefsFromStream(prefs);
69 >                fclose(prefs);
70 >                return;
71          }
72 <        strcat(prefs_path, PREFS_FILE_NAME);
72 >
73 >        // Construct prefs path
74 >        if (UserPrefsPath.empty()) {
75 >                char *home = getenv("HOME");
76 >                if (home)
77 >                        prefs_path = string(home) + '/';
78 >                prefs_path += PREFS_FILE_NAME;
79 >        } else
80 >                prefs_path = UserPrefsPath;
81  
82          // Read preferences from settings file
83 <        FILE *f = fopen(prefs_path, "r");
83 >        FILE *f = fopen(prefs_path.c_str(), "r");
84          if (f != NULL) {
85  
86                  // Prefs file found, load settings
# Line 77 | Line 102 | void LoadPrefs(void)
102   void SavePrefs(void)
103   {
104          FILE *f;
105 <        if ((f = fopen(prefs_path, "w")) != NULL) {
105 >        if ((f = fopen(prefs_path.c_str(), "w")) != NULL) {
106                  SavePrefsToStream(f);
107                  fclose(f);
108          }
# Line 92 | Line 117 | void SavePrefs(void)
117   void AddPlatformPrefsDefaults(void)
118   {
119          PrefsAddBool("keycodes", false);
120 +        PrefsReplaceString("extfs", "/");
121 +        PrefsReplaceInt32("mousewheelmode", 1);
122 +        PrefsReplaceInt32("mousewheellines", 3);
123 + #ifdef __linux__
124 +        if (access("/dev/sound/dsp", F_OK) == 0) {
125 +                PrefsReplaceString("dsp", "/dev/sound/dsp");
126 +        } else {
127 +                PrefsReplaceString("dsp", "/dev/dsp");
128 +        }
129 +        if (access("/dev/sound/mixer", F_OK) == 0) {
130 +                PrefsReplaceString("mixer", "/dev/sound/mixer");
131 +        } else {
132 +                PrefsReplaceString("mixer", "/dev/mixer");
133 +        }
134 + #else
135 +        PrefsReplaceString("dsp", "/dev/dsp");
136 +        PrefsReplaceString("mixer", "/dev/mixer");
137 + #endif
138 + #ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
139 +        PrefsAddBool("ignoresegv", false);
140 + #endif
141 +        PrefsAddBool("idlewait", true);
142   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines