diff options
Diffstat (limited to 'src/main.cc')
-rw-r--r-- | src/main.cc | 330 |
1 files changed, 138 insertions, 192 deletions
diff --git a/src/main.cc b/src/main.cc index 19ed631..e63700d 100644 --- a/src/main.cc +++ b/src/main.cc | |||
@@ -1,3 +1,6 @@ | |||
1 | // main.cc for Fluxbox Window manager | ||
2 | // Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org) | ||
3 | // | ||
1 | // main.cc for Blackbox - an X11 Window manager | 4 | // main.cc for Blackbox - an X11 Window manager |
2 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) | 5 | // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) |
3 | // | 6 | // |
@@ -19,46 +22,68 @@ | |||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
20 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
21 | 24 | ||
22 | // stupid macros needed to access some functions in version 2 of the GNU C | 25 | // $Id: main.cc,v 1.8 2002/10/13 21:48:28 fluxgen Exp $ |
23 | // library | ||
24 | #ifndef _GNU_SOURCE | ||
25 | #define _GNU_SOURCE | ||
26 | #endif // _GNU_SOURCE | ||
27 | 26 | ||
28 | #include "../version.h" | ||
29 | 27 | ||
30 | #ifdef HAVE_CONFIG_H | ||
31 | # include "../config.h" | ||
32 | #endif // HAVE_CONFIG_H | ||
33 | 28 | ||
34 | #include "i18n.hh" | 29 | #include "i18n.hh" |
35 | #include "fluxbox.hh" | 30 | #include "fluxbox.hh" |
36 | 31 | ||
37 | #ifdef HAVE_STDIO_H | 32 | #include "../version.h" |
38 | # include <stdio.h> | 33 | |
39 | #endif // HAVE_STDIO_H | 34 | #ifdef HAVE_CONFIG_H |
35 | #include "config.h" | ||
36 | #endif // HAVE_CONFIG_H | ||
37 | |||
38 | //use GNU extensions | ||
39 | #ifndef _GNU_SOURCE | ||
40 | #define _GNU_SOURCE | ||
41 | #endif // _GNU_SOURCE | ||
40 | 42 | ||
41 | #ifdef STDC_HEADERS | 43 | #include <cstdio> |
42 | # include <stdlib.h> | 44 | #include <cstdlib> |
43 | # include <string.h> | 45 | #include <cstring> |
44 | #endif // STDC_HEADERS | ||
45 | 46 | ||
46 | #ifdef HAVE_UNISTD_H | 47 | #ifdef HAVE_UNISTD_H |
47 | #include <sys/types.h> | 48 | #include <sys/types.h> |
48 | #endif // HAVE_UNISTD_H | 49 | #endif // HAVE_UNISTD_H |
49 | 50 | ||
50 | #ifdef HAVE_SYS_PARAM_H | 51 | #ifdef HAVE_SYS_PARAM_H |
51 | # include <sys/param.h> | 52 | #include <sys/param.h> |
52 | #endif // HAVE_SYS_PARAM_H | 53 | #endif // HAVE_SYS_PARAM_H |
53 | 54 | ||
54 | #ifndef MAXPATHLEN | ||
55 | #define MAXPATHLEN 255 | ||
56 | #endif // MAXPATHLEN | ||
57 | |||
58 | #include <iostream> | 55 | #include <iostream> |
56 | #include <stdexcept> | ||
57 | |||
59 | using namespace std; | 58 | using namespace std; |
60 | 59 | ||
60 | #ifdef DEBUG_UDS | ||
61 | |||
62 | #include <uds/init.hh> | ||
63 | #include <uds/uds.hh> | ||
64 | |||
65 | // configure UDS | ||
66 | uds::uds_flags_t uds::flags = uds::leak_check; | ||
67 | |||
68 | #endif //!DEBUG_UDS | ||
69 | |||
70 | const char *getNLSYesNoMsg(bool val) { | ||
71 | if (val) { | ||
72 | return I18n::instance()->getMessage( | ||
73 | FBNLS::CommonSet, FBNLS::CommonYes, | ||
74 | "yes"); | ||
75 | } | ||
76 | |||
77 | return I18n::instance()->getMessage( | ||
78 | FBNLS::CommonSet, FBNLS::CommonNo, | ||
79 | "no"); | ||
80 | } | ||
81 | |||
61 | int main(int argc, char **argv) { | 82 | int main(int argc, char **argv) { |
83 | #ifdef DEBUG_UDS | ||
84 | uds::Init uds_init; | ||
85 | #endif //!DEBUG_UDS | ||
86 | |||
62 | char *session_display = (char *) 0; | 87 | char *session_display = (char *) 0; |
63 | char *rc_file = (char *) 0; | 88 | char *rc_file = (char *) 0; |
64 | 89 | ||
@@ -72,201 +97,122 @@ int main(int argc, char **argv) { | |||
72 | 97 | ||
73 | if ((++i) >= argc) { | 98 | if ((++i) >= argc) { |
74 | fprintf(stderr, | 99 | fprintf(stderr, |
75 | i18n->getMessage( | 100 | i18n->getMessage( |
76 | #ifdef NLS | 101 | FBNLS::mainSet, FBNLS::mainRCRequiresArg, |
77 | mainSet, mainRCRequiresArg, | 102 | "error: '-rc' requires and argument\n")); |
78 | #else // !NLS | 103 | exit(1); |
79 | 0, 0, | 104 | } |
80 | #endif // NLS | ||
81 | "error: '-rc' requires and argument\n")); | ||
82 | |||
83 | ::exit(1); | ||
84 | } | ||
85 | 105 | ||
86 | rc_file = argv[i]; | 106 | rc_file = argv[i]; |
87 | } else if (! strcmp(argv[i], "-display")) { | 107 | } else if (! strcmp(argv[i], "-display")) { |
88 | // check for -display option... to run on a display other than the one | 108 | // check for -display option... to run on a display other than the one |
89 | // set by the environment variable DISPLAY | 109 | // set by the environment variable DISPLAY |
90 | 110 | ||
91 | if ((++i) >= argc) { | 111 | if ((++i) >= argc) { |
92 | fprintf(stderr, | 112 | fprintf(stderr, |
93 | i18n->getMessage( | 113 | i18n->getMessage( |
94 | #ifdef NLS | 114 | FBNLS::mainSet, FBNLS::mainDISPLAYRequiresArg, |
95 | mainSet, mainDISPLAYRequiresArg, | 115 | "error: '-display' requires an argument\n")); |
96 | #else // !NLS | 116 | exit(1); |
97 | 0, 0, | 117 | } |
98 | #endif // NLS | ||
99 | "error: '-display' requires an argument\n")); | ||
100 | |||
101 | ::exit(1); | ||
102 | } | ||
103 | 118 | ||
104 | session_display = argv[i]; | 119 | session_display = argv[i]; |
105 | char dtmp[MAXPATHLEN]; | 120 | char dtmp[255]; |
106 | sprintf(dtmp, "DISPLAY=%s", session_display); | 121 | sprintf(dtmp, "DISPLAY=%s", session_display); |
107 | 122 | ||
108 | if (putenv(dtmp)) { | 123 | if (putenv(dtmp)) { |
109 | fprintf(stderr, | 124 | fprintf(stderr, |
110 | i18n-> | 125 | i18n-> |
111 | getMessage( | 126 | getMessage( |
112 | #ifdef NLS | 127 | FBNLS::mainSet, FBNLS::mainWarnDisplaySet, |
113 | mainSet, mainWarnDisplaySet, | 128 | "warning: couldn't set environment variable 'DISPLAY'\n")); |
114 | #else // !NLS | ||
115 | 0, 0, | ||
116 | #endif // NLS | ||
117 | "warning: couldn't set environment variable 'DISPLAY'\n")); | ||
118 | perror("putenv()"); | 129 | perror("putenv()"); |
119 | } | 130 | } |
120 | } else if (! strcmp(argv[i], "-version")) { | 131 | } else if (strcmp(argv[i], "-version") == 0) { |
121 | // print current version string | 132 | // print current version string |
122 | printf("Fluxbox %s : (c) 2001 Henrik Kinnunen \n\n", | 133 | printf("Fluxbox %s : (c) 2001-2002 Henrik Kinnunen \n\n", |
123 | __fluxbox_version); | 134 | __fluxbox_version); |
124 | 135 | exit(0); | |
125 | ::exit(0); | 136 | } else if (strcmp(argv[i], "-help") == 0) { |
126 | } else if (! strcmp(argv[i], "-help")) { | 137 | // print program usage and command line options |
127 | // print program usage and command line options | 138 | printf(i18n-> |
128 | printf(i18n-> | 139 | getMessage( |
129 | getMessage( | 140 | FBNLS::mainSet, FBNLS::mainUsage, |
130 | #ifdef NLS | 141 | "Fluxbox %s : (c) 2001-2002 Henrik Kinnunen\n\n" |
131 | mainSet, mainUsage, | 142 | " -display <string>\t\tuse display connection.\n" |
132 | #else // !NLS | 143 | " -rc <string>\t\t\tuse alternate resource file.\n" |
133 | 0, 0, | 144 | " -version\t\t\tdisplay version and exit.\n" |
134 | #endif // NLS | 145 | " -help\t\t\t\tdisplay this help text and exit.\n\n"), |
135 | "Fluxbox %s : (c) 2001 Henrik Kinnunen\n\n" | 146 | __fluxbox_version); |
136 | " -display <string>\t\tuse display connection.\n" | 147 | |
137 | " -rc <string>\t\t\tuse alternate resource file.\n" | 148 | // some people have requested that we print out command line options |
138 | " -version\t\t\tdisplay version and exit.\n" | 149 | // as well |
139 | " -help\t\t\t\tdisplay this help text and exit.\n\n"), | 150 | printf(i18n-> |
140 | __fluxbox_version); | 151 | getMessage( |
141 | 152 | FBNLS::mainSet, FBNLS::mainCompileOptions, | |
142 | // some people have requested that we print out command line options | ||
143 | // as well | ||
144 | printf(i18n-> | ||
145 | getMessage( | ||
146 | #ifdef NLS | ||
147 | mainSet, mainCompileOptions, | ||
148 | #else // !NLS | ||
149 | 0, 0, | ||
150 | #endif // NLS | ||
151 | "Compile time options:\n" | 153 | "Compile time options:\n" |
152 | " Debugging:\t\t\t%s\n" | 154 | " Debugging:\t\t\t%s\n" |
153 | " Interlacing:\t\t\t%s\n" | 155 | " Interlacing:\t\t\t%s\n" |
154 | " Shape:\t\t\t%s\n" | 156 | " Shape:\t\t\t%s\n" |
155 | " Slit:\t\t\t\t%s\n" | 157 | " Slit:\t\t\t\t%s\n" |
156 | " 8bpp Ordered Dithering:\t%s\n\n"), | 158 | " 8bpp Ordered Dithering:\t%s\n\n"), |
157 | #ifdef DEBUG | 159 | #ifdef DEBUG |
158 | i18n->getMessage( | 160 | getNLSYesNoMsg(true), |
159 | #ifdef NLS | 161 | #else // !DEBUG |
160 | CommonSet, CommonYes, | 162 | getNLSYesNoMsg(false), |
161 | #else // !NLS | 163 | #endif // DEBUG |
162 | 0, 0, | 164 | |
163 | #endif // NLS | 165 | #ifdef INTERLACE |
164 | "yes"), | 166 | getNLSYesNoMsg(true), |
165 | #else // !DEBUG | 167 | #else // !INTERLACE |
166 | i18n->getMessage( | 168 | getNLSYesNoMsg(false), |
167 | #ifdef NLS | 169 | #endif // INTERLACE |
168 | CommonSet, CommonNo, | 170 | |
169 | #else // !NLS | 171 | #ifdef SHAPE |
170 | 0, 0, | 172 | getNLSYesNoMsg(true), |
171 | #endif // NLS | 173 | #else // !SHAPE |
172 | "no"), | 174 | getNLSYesNoMsg(false), |
173 | #endif // DEBUG | 175 | #endif // SHAPE |
174 | 176 | ||
175 | #ifdef INTERLACE | 177 | #ifdef SLIT |
176 | i18n->getMessage( | 178 | getNLSYesNoMsg(true), |
177 | #ifdef NLS | 179 | #else // !SLIT |
178 | CommonSet, CommonYes, | 180 | getNLSYesNoMsg(false), |
179 | #else // !NLS | 181 | #endif // SLIT |
180 | 0, 0, | 182 | |
181 | #endif // NLS | 183 | #ifdef ORDEREDPSEUDO |
182 | "yes"), | 184 | getNLSYesNoMsg(true) |
183 | #else // !INTERLACE | 185 | #else // !ORDEREDPSEUDO |
184 | i18n->getMessage( | 186 | getNLSYesNoMsg(false) |
185 | #ifdef NLS | 187 | #endif // ORDEREDPSEUDO |
186 | CommonSet, CommonNo, | 188 | |
187 | #else // !NLS | 189 | ); |
188 | 0, 0, | 190 | |
189 | #endif // NLS | 191 | ::exit(0); |
190 | "no"), | 192 | } |
191 | #endif // INTERLACE | 193 | } |
192 | 194 | ||
193 | #ifdef SHAPE | 195 | #ifdef __EMX__ |
194 | i18n->getMessage( | 196 | _chdir2(getenv("X11ROOT")); |
195 | #ifdef NLS | ||
196 | CommonSet, CommonYes, | ||
197 | #else // !NLS | ||
198 | 0, 0, | ||
199 | #endif // NLS | ||
200 | "yes"), | ||
201 | #else // !SHAPE | ||
202 | i18n->getMessage( | ||
203 | #ifdef NLS | ||
204 | CommonSet, CommonNo, | ||
205 | #else // !NLS | ||
206 | 0, 0, | ||
207 | #endif // NLS | ||
208 | "no"), | ||
209 | #endif // SHAPE | ||
210 | |||
211 | #ifdef SLIT | ||
212 | i18n->getMessage( | ||
213 | #ifdef NLS | ||
214 | CommonSet, CommonYes, | ||
215 | #else // !NLS | ||
216 | 0, 0, | ||
217 | #endif // NLS | ||
218 | "yes"), | ||
219 | #else // !SLIT | ||
220 | i18n->getMessage( | ||
221 | #ifdef NLS | ||
222 | CommonSet, CommonNo, | ||
223 | #else // !NLS | ||
224 | 0, 0, | ||
225 | #endif // NLS | ||
226 | "no"), | ||
227 | #endif // SLIT | ||
228 | |||
229 | #ifdef ORDEREDPSEUDO | ||
230 | i18n->getMessage( | ||
231 | #ifdef NLS | ||
232 | CommonSet, CommonYes, | ||
233 | #else // !NLS | ||
234 | 0, 0, | ||
235 | #endif // NLS | ||
236 | "yes") | ||
237 | #else // !ORDEREDPSEUDO | ||
238 | i18n->getMessage( | ||
239 | #ifdef NLS | ||
240 | CommonSet, CommonNo, | ||
241 | #else // !NLS | ||
242 | 0, 0, | ||
243 | #endif // NLS | ||
244 | "no") | ||
245 | #endif // ORDEREDPSEUDO | ||
246 | |||
247 | ); | ||
248 | |||
249 | ::exit(0); | ||
250 | } | ||
251 | } | ||
252 | |||
253 | #ifdef __EMX__ | ||
254 | _chdir2(getenv("X11ROOT")); | ||
255 | #endif // __EMX__ | 197 | #endif // __EMX__ |
256 | Fluxbox *fluxbox=0; | 198 | Fluxbox *fluxbox=0; |
257 | int exitcode=EXIT_SUCCESS; | 199 | int exitcode=EXIT_SUCCESS; |
258 | try { | 200 | try { |
259 | 201 | ||
260 | fluxbox = new Fluxbox(argc, argv, session_display, rc_file); | 202 | fluxbox = new Fluxbox(argc, argv, session_display, rc_file); |
261 | fluxbox->eventLoop(); | 203 | fluxbox->eventLoop(); |
262 | 204 | ||
263 | } catch (int _exitcode) { | 205 | } catch (std::out_of_range oor) { |
264 | exitcode=_exitcode; | 206 | cerr<<"Fluxbox: Out of range: "<<oor.what()<<endl; |
207 | } catch (std::logic_error le) { | ||
208 | cerr<<"Fluxbox: Logic error: "<<le.what()<<endl; | ||
209 | } catch (std::runtime_error re) { | ||
210 | cerr<<"Fluxbox: Runtime error: "<<re.what()<<endl; | ||
265 | } catch (...) { | 211 | } catch (...) { |
266 | cerr<<"Fluxbox: Unknown error."<<endl; | 212 | cerr<<"Fluxbox: Unknown error."<<endl; |
267 | } | 213 | } |
268 | 214 | ||
269 | if (fluxbox) | 215 | if (fluxbox) |
270 | delete fluxbox; | 216 | delete fluxbox; |
271 | exit(exitcode); | 217 | exit(exitcode); |
272 | } | 218 | } |