diff options
Diffstat (limited to 'src/main.cc')
-rw-r--r-- | src/main.cc | 375 |
1 files changed, 165 insertions, 210 deletions
diff --git a/src/main.cc b/src/main.cc index 19ed631..f40ceab 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,254 +22,206 @@ | |||
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.13 2003/01/09 18:28:48 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> | ||
39 | #endif // HAVE_STDIO_H | ||
40 | 33 | ||
41 | #ifdef STDC_HEADERS | 34 | #ifdef HAVE_CONFIG_H |
42 | # include <stdlib.h> | 35 | #include "config.h" |
43 | # include <string.h> | 36 | #endif // HAVE_CONFIG_H |
44 | #endif // STDC_HEADERS | ||
45 | 37 | ||
46 | #ifdef HAVE_UNISTD_H | 38 | //use GNU extensions |
39 | #ifndef _GNU_SOURCE | ||
40 | #define _GNU_SOURCE | ||
41 | #endif // _GNU_SOURCE | ||
42 | |||
43 | #include <cstdio> | ||
44 | #include <cstdlib> | ||
45 | #include <cstring> | ||
46 | |||
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 | #include <typeinfo> | ||
58 | |||
59 | using namespace std; | 59 | using namespace std; |
60 | 60 | ||
61 | #ifdef DEBUG_UDS | ||
62 | |||
63 | #include <uds/init.hh> | ||
64 | #include <uds/uds.hh> | ||
65 | |||
66 | // configure UDS | ||
67 | uds::uds_flags_t uds::flags = uds::leak_check | uds::std_backtraces | uds::log_allocs | uds::leak_check; | ||
68 | |||
69 | #endif //!DEBUG_UDS | ||
70 | |||
71 | const char *getNLSYesNoMsg(bool val) { | ||
72 | if (val) { | ||
73 | return I18n::instance()->getMessage( | ||
74 | FBNLS::CommonSet, FBNLS::CommonYes, | ||
75 | "yes"); | ||
76 | } | ||
77 | |||
78 | return I18n::instance()->getMessage( | ||
79 | FBNLS::CommonSet, FBNLS::CommonNo, | ||
80 | "no"); | ||
81 | } | ||
82 | |||
61 | int main(int argc, char **argv) { | 83 | int main(int argc, char **argv) { |
62 | char *session_display = (char *) 0; | 84 | #ifdef DEBUG_UDS |
63 | char *rc_file = (char *) 0; | 85 | uds::Init uds_init; |
86 | #endif //!DEBUG_UDS | ||
87 | |||
88 | char *session_display = (char *) 0; | ||
89 | char *rc_file = (char *) 0; | ||
64 | 90 | ||
65 | NLSInit("blackbox.cat"); | 91 | NLSInit("fluxbox.cat"); |
66 | I18n *i18n = I18n::instance(); | 92 | I18n *i18n = I18n::instance(); |
67 | 93 | ||
68 | int i; | 94 | int i; |
69 | for (i = 1; i < argc; ++i) { | 95 | for (i = 1; i < argc; ++i) { |
70 | if (! strcmp(argv[i], "-rc")) { | 96 | if (! strcmp(argv[i], "-rc")) { |
71 | // look for alternative rc file to use | 97 | // look for alternative rc file to use |
72 | 98 | ||
73 | if ((++i) >= argc) { | 99 | if ((++i) >= argc) { |
74 | fprintf(stderr, | 100 | fprintf(stderr, |
75 | i18n->getMessage( | 101 | i18n->getMessage( |
76 | #ifdef NLS | 102 | FBNLS::mainSet, FBNLS::mainRCRequiresArg, |
77 | mainSet, mainRCRequiresArg, | 103 | "error: '-rc' requires and argument\n")); |
78 | #else // !NLS | 104 | exit(1); |
79 | 0, 0, | 105 | } |
80 | #endif // NLS | 106 | |
81 | "error: '-rc' requires and argument\n")); | 107 | rc_file = argv[i]; |
82 | 108 | } else if (! strcmp(argv[i], "-display")) { | |
83 | ::exit(1); | 109 | // check for -display option... to run on a display other than the one |
84 | } | 110 | // set by the environment variable DISPLAY |
85 | 111 | ||
86 | rc_file = argv[i]; | 112 | if ((++i) >= argc) { |
87 | } else if (! strcmp(argv[i], "-display")) { | 113 | fprintf(stderr, |
88 | // check for -display option... to run on a display other than the one | 114 | i18n->getMessage( |
89 | // set by the environment variable DISPLAY | 115 | FBNLS::mainSet, FBNLS::mainDISPLAYRequiresArg, |
90 | 116 | "error: '-display' requires an argument\n")); | |
91 | if ((++i) >= argc) { | 117 | exit(1); |
92 | fprintf(stderr, | 118 | } |
93 | i18n->getMessage( | 119 | |
94 | #ifdef NLS | 120 | session_display = argv[i]; |
95 | mainSet, mainDISPLAYRequiresArg, | 121 | char dtmp[255]; |
96 | #else // !NLS | 122 | sprintf(dtmp, "DISPLAY=%s", session_display); |
97 | 0, 0, | 123 | |
98 | #endif // NLS | 124 | if (putenv(dtmp)) { |
99 | "error: '-display' requires an argument\n")); | 125 | fprintf(stderr, |
100 | 126 | i18n-> | |
101 | ::exit(1); | 127 | getMessage( |
102 | } | 128 | FBNLS::mainSet, FBNLS::mainWarnDisplaySet, |
103 | 129 | "warning: couldn't set environment variable 'DISPLAY'\n")); | |
104 | session_display = argv[i]; | 130 | perror("putenv()"); |
105 | char dtmp[MAXPATHLEN]; | 131 | } |
106 | sprintf(dtmp, "DISPLAY=%s", session_display); | 132 | } else if (strcmp(argv[i], "-version") == 0) { |
107 | 133 | // print current version string | |
108 | if (putenv(dtmp)) { | 134 | printf("Fluxbox %s : (c) 2001-2002 Henrik Kinnunen \n\n", |
109 | fprintf(stderr, | 135 | __fluxbox_version); |
110 | i18n-> | 136 | exit(0); |
111 | getMessage( | 137 | } else if (strcmp(argv[i], "-help") == 0) { |
112 | #ifdef NLS | 138 | // print program usage and command line options |
113 | mainSet, mainWarnDisplaySet, | 139 | printf(i18n-> |
114 | #else // !NLS | 140 | getMessage( |
115 | 0, 0, | 141 | FBNLS::mainSet, FBNLS::mainUsage, |
116 | #endif // NLS | 142 | "Fluxbox %s : (c) 2001-2002 Henrik Kinnunen\n\n" |
117 | "warning: couldn't set environment variable 'DISPLAY'\n")); | 143 | " -display <string>\t\tuse display connection.\n" |
118 | perror("putenv()"); | 144 | " -rc <string>\t\t\tuse alternate resource file.\n" |
119 | } | 145 | " -version\t\t\tdisplay version and exit.\n" |
120 | } else if (! strcmp(argv[i], "-version")) { | 146 | " -help\t\t\t\tdisplay this help text and exit.\n\n"), |
121 | // print current version string | 147 | __fluxbox_version); |
122 | printf("Fluxbox %s : (c) 2001 Henrik Kinnunen \n\n", | 148 | |
123 | __fluxbox_version); | 149 | |
124 | 150 | printf(i18n-> | |
125 | ::exit(0); | 151 | getMessage( |
126 | } else if (! strcmp(argv[i], "-help")) { | 152 | FBNLS::mainSet, FBNLS::mainCompileOptions, |
127 | // print program usage and command line options | 153 | "Compile time options:\n" |
128 | printf(i18n-> | 154 | " Debugging:\t\t\t%s\n" |
129 | getMessage( | 155 | " Interlacing:\t\t\t%s\n" |
130 | #ifdef NLS | 156 | " Shape:\t\t\t%s\n" |
131 | mainSet, mainUsage, | 157 | " Slit:\t\t\t\t%s\n" |
132 | #else // !NLS | 158 | " 8bpp Ordered Dithering:\t%s\n\n"), |
133 | 0, 0, | 159 | #ifdef DEBUG |
134 | #endif // NLS | 160 | getNLSYesNoMsg(true), |
135 | "Fluxbox %s : (c) 2001 Henrik Kinnunen\n\n" | ||
136 | " -display <string>\t\tuse display connection.\n" | ||
137 | " -rc <string>\t\t\tuse alternate resource file.\n" | ||
138 | " -version\t\t\tdisplay version and exit.\n" | ||
139 | " -help\t\t\t\tdisplay this help text and exit.\n\n"), | ||
140 | __fluxbox_version); | ||
141 | |||
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" | ||
152 | " Debugging:\t\t\t%s\n" | ||
153 | " Interlacing:\t\t\t%s\n" | ||
154 | " Shape:\t\t\t%s\n" | ||
155 | " Slit:\t\t\t\t%s\n" | ||
156 | " 8bpp Ordered Dithering:\t%s\n\n"), | ||
157 | #ifdef DEBUG | ||
158 | i18n->getMessage( | ||
159 | #ifdef NLS | ||
160 | CommonSet, CommonYes, | ||
161 | #else // !NLS | ||
162 | 0, 0, | ||
163 | #endif // NLS | ||
164 | "yes"), | ||
165 | #else // !DEBUG | 161 | #else // !DEBUG |
166 | i18n->getMessage( | 162 | getNLSYesNoMsg(false), |
167 | #ifdef NLS | ||
168 | CommonSet, CommonNo, | ||
169 | #else // !NLS | ||
170 | 0, 0, | ||
171 | #endif // NLS | ||
172 | "no"), | ||
173 | #endif // DEBUG | 163 | #endif // DEBUG |
174 | 164 | ||
175 | #ifdef INTERLACE | 165 | #ifdef INTERLACE |
176 | i18n->getMessage( | 166 | getNLSYesNoMsg(true), |
177 | #ifdef NLS | ||
178 | CommonSet, CommonYes, | ||
179 | #else // !NLS | ||
180 | 0, 0, | ||
181 | #endif // NLS | ||
182 | "yes"), | ||
183 | #else // !INTERLACE | 167 | #else // !INTERLACE |
184 | i18n->getMessage( | 168 | getNLSYesNoMsg(false), |
185 | #ifdef NLS | ||
186 | CommonSet, CommonNo, | ||
187 | #else // !NLS | ||
188 | 0, 0, | ||
189 | #endif // NLS | ||
190 | "no"), | ||
191 | #endif // INTERLACE | 169 | #endif // INTERLACE |
192 | 170 | ||
193 | #ifdef SHAPE | 171 | #ifdef SHAPE |
194 | i18n->getMessage( | 172 | getNLSYesNoMsg(true), |
195 | #ifdef NLS | ||
196 | CommonSet, CommonYes, | ||
197 | #else // !NLS | ||
198 | 0, 0, | ||
199 | #endif // NLS | ||
200 | "yes"), | ||
201 | #else // !SHAPE | 173 | #else // !SHAPE |
202 | i18n->getMessage( | 174 | getNLSYesNoMsg(false), |
203 | #ifdef NLS | ||
204 | CommonSet, CommonNo, | ||
205 | #else // !NLS | ||
206 | 0, 0, | ||
207 | #endif // NLS | ||
208 | "no"), | ||
209 | #endif // SHAPE | 175 | #endif // SHAPE |
210 | 176 | ||
211 | #ifdef SLIT | 177 | #ifdef SLIT |
212 | i18n->getMessage( | 178 | getNLSYesNoMsg(true), |
213 | #ifdef NLS | ||
214 | CommonSet, CommonYes, | ||
215 | #else // !NLS | ||
216 | 0, 0, | ||
217 | #endif // NLS | ||
218 | "yes"), | ||
219 | #else // !SLIT | 179 | #else // !SLIT |
220 | i18n->getMessage( | 180 | getNLSYesNoMsg(false), |
221 | #ifdef NLS | ||
222 | CommonSet, CommonNo, | ||
223 | #else // !NLS | ||
224 | 0, 0, | ||
225 | #endif // NLS | ||
226 | "no"), | ||
227 | #endif // SLIT | 181 | #endif // SLIT |
228 | 182 | ||
229 | #ifdef ORDEREDPSEUDO | 183 | #ifdef ORDEREDPSEUDO |
230 | i18n->getMessage( | 184 | getNLSYesNoMsg(true) |
231 | #ifdef NLS | ||
232 | CommonSet, CommonYes, | ||
233 | #else // !NLS | ||
234 | 0, 0, | ||
235 | #endif // NLS | ||
236 | "yes") | ||
237 | #else // !ORDEREDPSEUDO | 185 | #else // !ORDEREDPSEUDO |
238 | i18n->getMessage( | 186 | getNLSYesNoMsg(false) |
239 | #ifdef NLS | ||
240 | CommonSet, CommonNo, | ||
241 | #else // !NLS | ||
242 | 0, 0, | ||
243 | #endif // NLS | ||
244 | "no") | ||
245 | #endif // ORDEREDPSEUDO | 187 | #endif // ORDEREDPSEUDO |
246 | 188 | ||
247 | ); | 189 | ); |
248 | 190 | ||
249 | ::exit(0); | 191 | ::exit(0); |
192 | } | ||
250 | } | 193 | } |
251 | } | ||
252 | 194 | ||
253 | #ifdef __EMX__ | 195 | #ifdef __EMX__ |
254 | _chdir2(getenv("X11ROOT")); | 196 | _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_FAILURE; |
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 | exitcode = EXIT_SUCCESS; | |
263 | } catch (int _exitcode) { | 205 | } catch (std::out_of_range &oor) { |
264 | exitcode=_exitcode; | 206 | cerr<<"Fluxbox: Out of range: "<<oor.what()<<endl; |
265 | } catch (...) { | 207 | } catch (std::logic_error &le) { |
266 | cerr<<"Fluxbox: Unknown error."<<endl; | 208 | cerr<<"Fluxbox: Logic error: "<<le.what()<<endl; |
267 | } | 209 | } catch (std::runtime_error &re) { |
210 | cerr<<"Fluxbox: Runtime error: "<<re.what()<<endl; | ||
211 | } catch (std::bad_cast &bc) { | ||
212 | cerr<<"Fluxbox: Bad cast: "<<bc.what()<<endl; | ||
213 | } catch (std::bad_alloc &ba) { | ||
214 | cerr<<"Fluxbox: Bad Alloc: "<<ba.what()<<endl; | ||
215 | } catch (std::exception &e) { | ||
216 | cerr<<"Fluxbox: Standard exception: "<<e.what()<<endl; | ||
217 | } catch (std::string error_str) { | ||
218 | cerr<<"Error: "<<error_str<<endl; | ||
219 | } catch (...) { | ||
220 | cerr<<"Fluxbox: Unknown error."<<endl; | ||
221 | abort(); | ||
222 | } | ||
268 | 223 | ||
269 | if (fluxbox) | 224 | if (fluxbox) |
270 | delete fluxbox; | 225 | delete fluxbox; |
271 | exit(exitcode); | 226 | return exitcode; |
272 | } | 227 | } |